Skip to content

Commit

Permalink
Merge branch 'release/0.2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Oct 21, 2018
2 parents e322107 + c368004 commit 6b13ff8
Show file tree
Hide file tree
Showing 14 changed files with 766 additions and 54 deletions.
4 changes: 2 additions & 2 deletions nuspec/nuget/Cake.Tfs.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
</description>
<licenseUrl>https://github.com/cake-contrib/Cake.Tfs/blob/develop/LICENSE</licenseUrl>
<projectUrl>http://cake-contrib.github.io/Cake.Tfs/</projectUrl>
<iconUrl>https://cdn.rawgit.com/cake-contrib/graphics/a5cf0f881c390650144b2243ae551d5b9f836196/png/cake-contrib-medium.png</iconUrl>
<iconUrl>https://cdn.jsdelivr.net/gh/cake-contrib/graphics@a5cf0f881c390650144b2243ae551d5b9f836196/png/cake-contrib-medium.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<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.2</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.Tfs/releases/tag/0.2.3</releaseNotes>
</metadata>
<files>
<file src="net461\Cake.Tfs.dll" target="lib\net461" />
Expand Down
1 change: 1 addition & 0 deletions src/Cake.Tfs.Tests/Cake.Tfs.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Cake.Core" Version="0.28.0" />
<PackageReference Include="Cake.Testing" Version="0.28.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="Shouldly" Version="3.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
<PackageReference Include="xunit" Version="2.4.0" />
Expand Down
19 changes: 19 additions & 0 deletions src/Cake.Tfs.Tests/ExceptionAssertExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Cake.Tfs
{
using System;
using Cake.Tfs.PullRequest;
using Xunit;

/// <summary>
Expand Down Expand Up @@ -49,5 +50,23 @@ public static void IsInvalidOperationException(this Exception exception)
{
Assert.IsType<InvalidOperationException>(exception);
}

/// <summary>
/// Checks if an exception is of type <see cref="UriFormatException"/>.
/// </summary>
/// <param name="exception">Exception to check.</param>
public static void IsUrlFormatException(this Exception exception)
{
Assert.IsType<UriFormatException>(exception);
}

/// <summary>
/// Checks if an exception is of type <see cref="TfsPullRequestNotFoundException"/>.
/// </summary>
/// <param name="exception">Exception to check.</param>
public static void IsTfsPullRequestNotFoundException(this Exception exception)
{
Assert.IsType<TfsPullRequestNotFoundException>(exception);
}
}
}
106 changes: 106 additions & 0 deletions src/Cake.Tfs.Tests/PullRequest/Fakes/FakeAllSetGitClientFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
namespace Cake.Tfs.Tests.PullRequest.Fakes
{
using System;
using System.Collections.Generic;
using System.Threading;
using Cake.Tfs.Authentication;
using Cake.Tfs.PullRequest;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Moq;

public class FakeAllSetGitClientFactory : FakeGitClientFactory
{
public override GitHttpClient CreateGitClient(Uri collectionUrl, ITfsCredentials credentials)
{
var mock = new Mock<GitHttpClient>(MockBehavior.Loose, collectionUrl, credentials.ToVssCredentials());

mock.Setup(arg => arg.GetPullRequestAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), null, null, null, null, null, null, default(CancellationToken)))
.ReturnsAsync((string project1, string repoId1, int prId, int i1, int i2, int i3, bool b1, bool b2, object o1, CancellationToken c1) => new GitPullRequest
{
PullRequestId = prId,
Repository = new GitRepository
{
Id = Guid.NewGuid(),
Name = repoId1
},
SourceRefName = "foo",
TargetRefName = "master",
CodeReviewId = 123,
LastMergeSourceCommit = new GitCommitRef { CommitId = "4a92b977" },
LastMergeTargetCommit = new GitCommitRef { CommitId = "78a3c113" }
});

mock.Setup(arg => arg.GetPullRequestsAsync(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<GitPullRequestSearchCriteria>(),
null,
null,
1,
null,
default(CancellationToken)))
.ReturnsAsync((string project2, string repoId2, GitPullRequestSearchCriteria sc, int j1, int j2, int top, object o2, CancellationToken c2)
=> new List<GitPullRequest>(new[]
{
new GitPullRequest
{
PullRequestId = 777,
Repository = new GitRepository
{
Id = Guid.NewGuid(),
Name = repoId2
},
SourceRefName = sc.SourceRefName,
TargetRefName = "master",
CodeReviewId = 123,
LastMergeSourceCommit = new GitCommitRef { CommitId = "4a92b977" },
LastMergeTargetCommit = new GitCommitRef { CommitId = "78a3c113" }
}
}));

mock = this.Setup(mock);

return mock.Object;
}

protected override Mock<GitHttpClient> Setup(Mock<GitHttpClient> m)
{
m.Setup(arg => arg.CreatePullRequestReviewerAsync(
It.Is<IdentityRefWithVote>(i => Enum.IsDefined(typeof(TfsPullRequestVote), i.Vote)),
It.IsAny<Guid>(),
It.IsAny<int>(),
It.IsAny<string>(),
It.IsAny<object>(),
default(CancellationToken)))
.ReturnsAsync((IdentityRefWithVote identity, Guid project, int prId, string reviewerId, object o, CancellationToken c)
=> new IdentityRefWithVote
{
Vote = identity.Vote,
});

m.Setup(arg => arg.CreatePullRequestReviewerAsync(
It.Is<IdentityRefWithVote>(i => !Enum.IsDefined(typeof(TfsPullRequestVote), i.Vote)),
It.IsAny<Guid>(),
It.IsAny<int>(),
It.IsAny<string>(),
It.IsAny<object>(),
default(CancellationToken)))
.Throws(new Exception("Something went wrong"));

m.Setup(arg => arg.CreatePullRequestStatusAsync(
It.IsAny<GitPullRequestStatus>(),
It.IsAny<Guid>(),
It.IsAny<int>(),
It.IsAny<object>(),
It.IsAny<CancellationToken>()))
.ReturnsAsync((GitPullRequestStatus status, Guid repoId, int prId, object o, CancellationToken c)
=> new GitPullRequestStatus
{
Context = status.Context,
State = status.State
});

return m;
}
}
}
24 changes: 24 additions & 0 deletions src/Cake.Tfs.Tests/PullRequest/Fakes/FakeGitClientFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Cake.Tfs.Tests.PullRequest.Fakes
{
using System;
using Cake.Tfs.Authentication;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.Identity;
using Moq;

public abstract class FakeGitClientFactory : IGitClientFactory
{
public abstract GitHttpClient CreateGitClient(Uri collectionUrl, ITfsCredentials credentials);

public GitHttpClient CreateGitClient(Uri collectionUrl, ITfsCredentials credentials, out Identity identity)
{
identity = new Identity { ProviderDisplayName = "FakeUser", Id = Guid.NewGuid(), IsActive = true };
return this.CreateGitClient(collectionUrl, credentials);
}

protected virtual Mock<GitHttpClient> Setup(Mock<GitHttpClient> m)
{
return m;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Cake.Tfs.Tests.PullRequest.Fakes
{
using System;
using System.Threading;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Moq;

public class FakeNullForMethodsGitClientFactory : FakeAllSetGitClientFactory
{
protected override Mock<GitHttpClient> Setup(Mock<GitHttpClient> m)
{
m.Setup(arg => arg.CreatePullRequestReviewerAsync(It.IsAny<IdentityRefWithVote>(), It.IsAny<Guid>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<object>(), default(CancellationToken)))
.ReturnsAsync(() => null);

m.Setup(arg => arg.CreatePullRequestStatusAsync(It.IsAny<GitPullRequestStatus>(), It.IsAny<Guid>(), It.IsAny<int>(), It.IsAny<object>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(() => null);

return m;
}
}
}
27 changes: 27 additions & 0 deletions src/Cake.Tfs.Tests/PullRequest/Fakes/FakeNullGitClientFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Cake.Tfs.Tests.PullRequest.Fakes
{
using System;
using System.Collections.Generic;
using System.Threading;
using Cake.Tfs.Authentication;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Moq;

public class FakeNullGitClientFactory : FakeGitClientFactory
{
public override GitHttpClient CreateGitClient(Uri collectionUrl, ITfsCredentials credentials)
{
var mock = new Mock<GitHttpClient>(MockBehavior.Loose, collectionUrl, credentials.ToVssCredentials());

mock.Setup(arg => arg.GetPullRequestAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), null, null, null, null, null, null, default(CancellationToken)))
.ReturnsAsync(() => null);

mock.Setup(arg => arg.GetPullRequestsAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GitPullRequestSearchCriteria>(), null, null, 1, null, default(CancellationToken)))
.ReturnsAsync(() => new List<GitPullRequest>());

mock = this.Setup(mock);

return mock.Object;
}
}
}
41 changes: 41 additions & 0 deletions src/Cake.Tfs.Tests/PullRequest/PullRequestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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
{
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)
{
this.Settings = new TfsPullRequestSettings(new Uri(repoUrl), prId, new TfsNtlmCredentials());

this.InitializeFakes();
}

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

this.InitializeFakes();
}

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 6b13ff8

Please sign in to comment.