Skip to content

Commit

Permalink
Improve test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Feb 7, 2019
1 parent f0a6aac commit 60755ab
Show file tree
Hide file tree
Showing 10 changed files with 617 additions and 185 deletions.
4 changes: 3 additions & 1 deletion src/Cake.Tfs.Tests/ExceptionAssertExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ public static void IsTfsException(this Exception exception)
/// Checks if an exception is of type <see cref="TfsBranchNotFoundException"/>
/// </summary>
/// <param name="exception">Exception to check.</param>
public static void IsTfsBranchNotFoundException(this Exception exception)
/// <param name="message">Exception message which should be checked.</param>
public static void IsTfsBranchNotFoundException(this Exception exception, string message)
{
Assert.IsType<TfsBranchNotFoundException>(exception);
Assert.Equal(message, exception.Message);
}
}
}
3 changes: 0 additions & 3 deletions src/Cake.Tfs.Tests/PullRequest/BasePullRequestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
namespace Cake.Tfs.Tests.PullRequest
{
using System;
using Cake.Testing;
using Cake.Tfs.Authentication;
using Cake.Tfs.PullRequest;
using Cake.Tfs.Tests.PullRequest.Fakes;

internal abstract class BasePullRequestFixture
Expand Down
95 changes: 95 additions & 0 deletions src/Cake.Tfs.Tests/PullRequest/CommentThread/TfsCommentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
namespace Cake.Tfs.Tests.PullRequest.CommentThread
{
using Cake.Tfs.PullRequest.CommentThread;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Shouldly;
using Xunit;

public sealed class TfsCommentTests
{
public sealed class TheCtor
{
[Fact]
public void Should_Throw_If_Comment_Is_Null()
{
// Given, When
var result = Record.Exception(() => new TfsComment(null));

// Then
result.IsArgumentNullException("comment");
}

[Fact]
public void Should_Throw_If_Comment_Content_Is_Null()
{
// Given, When
var result = Record.Exception(() => new TfsComment(null, false));

// Then
result.IsArgumentNullException("content");
}

[Fact]
public void Should_Throw_If_Comment_Content_Is_Empty()
{
// Given, When
var result = Record.Exception(() => new TfsComment(string.Empty, false));

// Then
result.IsArgumentOutOfRangeException("content");
}

[Fact]
public void Should_Return_Empty_Comment()
{
// Given, When
var comment = new TfsComment();

// Then
comment.ShouldNotBeNull();
comment.Content.ShouldBe(default(string));
comment.IsDeleted.ShouldBe(default(bool));
comment.CommentType.ShouldBe(default(TfsCommentType));
}

[Fact]
public void Should_Return_Valid_Comment_With_Default_Comment_Type()
{
// Given, When
var comment = new TfsComment("Hello", false);

// Then
comment.ShouldNotBeNull();
comment.Content.ShouldBe("Hello");
comment.IsDeleted.ShouldBeFalse();
comment.CommentType.ShouldBe(default(TfsCommentType));
}

[Fact]
public void Should_Return_Valid_Comment_Via_With_Specific_Comment_Type()
{
// Given, When
var comment = new TfsComment("What's up?", true, CommentType.Text);

// Then
comment.ShouldNotBeNull();
comment.Content.ShouldBe("What's up?");
comment.IsDeleted.ShouldBeTrue();
comment.CommentType.ShouldBe(TfsCommentType.Text);
}

[Fact]
public void Should_Return_Valid_Comment_Via_Initializers()
{
// Given, When
var comment = new TfsComment { Content = "All good", IsDeleted = false, CommentType = TfsCommentType.CodeChange };

// Then
comment.ShouldNotBeNull();
comment.Content.ShouldBe("All good");
comment.IsDeleted.ShouldBeFalse();
comment.CommentType.ShouldBe(TfsCommentType.CodeChange);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Cake.Tfs.Tests.PullRequest
namespace Cake.Tfs.Tests.PullRequest.CommentThread
{
using System.Collections.Generic;
using System.Linq;
Expand All @@ -10,7 +10,7 @@

public sealed class TfsPullRequestCommentThreadTests
{
public sealed class Ctor
public sealed class TheCtor
{
[Fact]
public void Should_Throw_If_Input_Thread_IsNull()
Expand Down Expand Up @@ -76,7 +76,7 @@ public void Should_Return_Valid_Comment_Thread()
}
}

public sealed class FilePath
public sealed class TheFilePathProperty
{
[Fact]
public void Should_Return_Null_If_Not_Initialized()
Expand Down Expand Up @@ -107,16 +107,18 @@ public void Should_Set_And_Trimmed_Properly()
};

// When
var tfsThread = new TfsPullRequestCommentThread(thread);
tfsThread.FilePath = "/path/to/myclass.cs";
var tfsThread = new TfsPullRequestCommentThread(thread)
{
FilePath = "/path/to/myclass.cs"
};

// Then
tfsThread.FilePath.ShouldNotBeNull();
tfsThread.FilePath.FullPath.ShouldBe("path/to/myclass.cs");
}
}

public sealed class Comments
public sealed class TheCommentsProperty
{
[Fact]
public void Should_Throw_If_Not_Set()
Expand Down Expand Up @@ -163,7 +165,7 @@ public void Should_Set_Properly()
}
}

public sealed class Properties
public sealed class ThePropertiesProperty
{
[Fact]
public void Should_Return_Null_If_Not_Set()
Expand Down Expand Up @@ -228,7 +230,7 @@ public void Should_Set_Colletion_With_Single_Element()
}
}

public sealed class GetValue
public sealed class TheGetValueMethod
{
[Fact]
public void Should_Throw_If_Property_Name_Is_Null()
Expand Down Expand Up @@ -300,7 +302,7 @@ public void Should_Get_Valid_Properties()
}
}

public sealed class SetValue
public sealed class TheSetValueMethod
{
[Fact]
public void Should_Throw_If_Property_Name_Is_Null()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ protected override Mock<GitHttpClient> Setup(Mock<GitHttpClient> m)
object userState,
CancellationToken cancellationToken) =>
{
gitPullRequestToCreate.PullRequestId = 777;
gitPullRequestToCreate.PullRequestId = 777;
gitPullRequestToCreate.Repository = new GitRepository
{
Id = Guid.NewGuid(),
Expand Down
92 changes: 0 additions & 92 deletions src/Cake.Tfs.Tests/PullRequest/TfsCommentTests.cs

This file was deleted.

Loading

0 comments on commit 60755ab

Please sign in to comment.