Skip to content

Commit

Permalink
Merge branch 'release/0.2.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Feb 13, 2019
2 parents 4524edc + 60755ab commit a439220
Show file tree
Hide file tree
Showing 19 changed files with 1,130 additions and 283 deletions.
2 changes: 1 addition & 1 deletion nuspec/nuget/Cake.Tfs.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<repository type="git" url="https://github.com/cake-contrib/Cake.Tfs"/>
<copyright>Copyright © Pascal Berger</copyright>
<tags>Cake Script Team-Foundation-Server TFS Azure-DevOps</tags>
<releaseNotes>https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.2.5</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.2.6</releaseNotes>
</metadata>
<files>
<file src="net461\Cake.Tfs.dll" target="lib\net461" />
Expand Down
13 changes: 12 additions & 1 deletion src/Cake.Tfs.Tests/ExceptionAssertExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,21 @@ public static void IsTfsPullRequestNotFoundException(this Exception exception)
/// <summary>
/// Checks if an exception is of type <see cref="TfsException"/>
/// </summary>
/// <param name="exception">Exceptino to check.</param>
/// <param name="exception">Exception to check.</param>
public static void IsTfsException(this Exception exception)
{
Assert.IsType<TfsException>(exception);
}

/// <summary>
/// Checks if an exception is of type <see cref="TfsBranchNotFoundException"/>
/// </summary>
/// <param name="exception">Exception to check.</param>
/// <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);
}
}
}
27 changes: 27 additions & 0 deletions src/Cake.Tfs.Tests/PullRequest/BasePullRequestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Cake.Tfs.Tests.PullRequest
{
using Cake.Testing;
using Cake.Tfs.Tests.PullRequest.Fakes;

internal abstract class BasePullRequestFixture
{
public const string ValidTfsUrl = "http://MyServer/tfs/MyCollection/MyTeamProject/_git/MyRepoName";
public const string ValidAzureDevOpsUrl = "https://my-account.visualstudio.com/DefaultCollection/MyProject/_git/MyRepoName";
public const string InvalidTfsUrl = "http://example.com";

public BasePullRequestFixture()
{
this.InitializeFakes();
}

public FakeLog Log { get; set; }

public IGitClientFactory GitClientFactory { get; set; }

private void InitializeFakes()
{
this.Log = new FakeLog();
this.GitClientFactory = new FakeAllSetGitClientFactory();
}
}
}
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
25 changes: 25 additions & 0 deletions src/Cake.Tfs.Tests/PullRequest/CreatePullRequestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Cake.Tfs.Tests.PullRequest
{
using System;
using Cake.Tfs.Authentication;
using Cake.Tfs.PullRequest;

internal class CreatePullRequestFixture
: BasePullRequestFixture
{
public CreatePullRequestFixture(string repoUrl, string sourceRefName, string targetRefName, string title, string description)
: base()
{
this.Settings =
new TfsCreatePullRequestSettings(
new Uri(repoUrl),
sourceRefName,
targetRefName,
title,
description,
new TfsNtlmCredentials());
}

public TfsCreatePullRequestSettings Settings { get; set; }
}
}
44 changes: 44 additions & 0 deletions src/Cake.Tfs.Tests/PullRequest/Fakes/FakeAllSetGitClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,50 @@ protected override Mock<GitHttpClient> Setup(Mock<GitHttpClient> m)
.ReturnsAsync((Guid repoId, int prId, int iterId, int? t, int? s, int? ct, object o, CancellationToken c)
=> changes);

// Setup pull request creation
m.Setup(arg => arg.GetRefsAsync(It.IsAny<string>(), "MyRepoName", "NotExistingBranch", null, null, null, CancellationToken.None))
.ReturnsAsync(() => new List<GitRef>());

m.Setup(args => args.GetRepositoryAsync(It.IsAny<string>(), "MyRepoName", null, null, CancellationToken.None))
.ReturnsAsync(() => new GitRepository() { DefaultBranch = "master" });

m.Setup(arg => arg.GetRefsAsync(It.IsAny<string>(), "MyRepoName", "master", null, null, null, CancellationToken.None))
.ReturnsAsync(() => new List<GitRef>()
{
new GitRef("master")
});

m.Setup(
arg =>
arg.CreatePullRequestAsync(
It.IsAny<GitPullRequest>(),
It.IsAny<string>(),
It.IsAny<string>(),
null,
null,
CancellationToken.None))
.ReturnsAsync(
(
GitPullRequest gitPullRequestToCreate,
string project,
string repositoryId,
bool? supportsIterations,
object userState,
CancellationToken cancellationToken) =>
{
gitPullRequestToCreate.PullRequestId = 777;
gitPullRequestToCreate.Repository = new GitRepository
{
Id = Guid.NewGuid(),
Name = repositoryId
};
gitPullRequestToCreate.CodeReviewId = 123;
gitPullRequestToCreate.LastMergeSourceCommit = new GitCommitRef { CommitId = "4a92b977" };
gitPullRequestToCreate.LastMergeTargetCommit = new GitCommitRef { CommitId = "78a3c113" };

return gitPullRequestToCreate;
});

return m;
}
}
Expand Down
27 changes: 5 additions & 22 deletions src/Cake.Tfs.Tests/PullRequest/PullRequestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,24 @@
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 class PullRequestFixture
: BasePullRequestFixture
{
public const string ValidTfsUrl = "http://MyServer/tfs/MyCollection/MyTeamProject/_git/MyRepoName";
public const string ValidAzureDevOpsUrl = "https://my-account.visualstudio.com/DefaultCollection/MyProject/_git/MyRepoName";
public const string InvalidTfsUrl = "http://example.com";

public PullRequestFixture(string repoUrl, int prId)
: base()
{
this.Settings = new TfsPullRequestSettings(new Uri(repoUrl), prId, new TfsNtlmCredentials());

this.InitializeFakes();
}

public PullRequestFixture(string repoUrl, string sourceBranch)
public PullRequestFixture(string repoUrl, string sourceRefName)
: base()
{
this.Settings = new TfsPullRequestSettings(new Uri(repoUrl), sourceBranch, new TfsNtlmCredentials());

this.InitializeFakes();
this.Settings = new TfsPullRequestSettings(new Uri(repoUrl), sourceRefName, new TfsNtlmCredentials());
}

public FakeLog Log { get; set; }

public TfsPullRequestSettings Settings { get; set; }

public IGitClientFactory GitClientFactory { get; set; }

private void InitializeFakes()
{
this.Log = new FakeLog();
this.GitClientFactory = new FakeAllSetGitClientFactory();
}
}
}
Loading

0 comments on commit a439220

Please sign in to comment.