-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
766 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/Cake.Tfs.Tests/PullRequest/Fakes/FakeAllSetGitClientFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
src/Cake.Tfs.Tests/PullRequest/Fakes/FakeGitClientFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Cake.Tfs.Tests/PullRequest/Fakes/FakeNullForMethodsGitClientFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
src/Cake.Tfs.Tests/PullRequest/Fakes/FakeNullGitClientFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.