public void UpdateApproval_GetsApprovals_UpdatesApproval() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); releaseClient.GetApprovals(Arg.Any <int>(), Arg.Any <string>()) .Returns(new List <ReleaseApproval> { new ReleaseApproval { Id = 123 } }); authenticator.Authenticate().Returns(new AuthenticationResult() { Success = true }); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); this.sut.UpdateApproval("123"); releaseClient.ReceivedWithAnyArgs(1).UpdateApproval(Arg.Any <int>(), Arg.Any <string>()); }
public void GetBuilds_Branch_Succeeds() { VstsConfig vstsConfig = GetVstsConfig(); IHttpClient httpClient = new HttpClient(); ITokenRepository repository = new JsonFileTokenRepository(new FileSystem()); IAuthenticator authenticator = new VstsOAuthAuthenticator(httpClient, repository, vstsConfig); File.Copy($"..//..//..//testdata//{TokenFilename}", fullTokenFilename, true); AuthenticationResult authResult = authenticator.Authenticate(); File.Copy(fullTokenFilename, $"..//..//..//testdata//{TokenFilename}", true); this.sut = new VstsSyncReleaseClient(vstsConfig); IEnumerable <Build> result = this.sut.GetBuilds( 1, authResult.AccessToken, branch: "refs/heads/master"); Assert.NotNull(result); Assert.True(result.Count() > 0); SaveResultData(result, "../../../testdata/GetBuilds_Branch.json"); }
public void Ctor_NullConfig_ThrowsException() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); Assert.Throws <ArgumentNullException>(() => this.sut = new VstsReleaseRepository(releaseClient, authenticator, null)); }
public void Ctor_NullAuthenticator_ThrowsException() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); VstsConfig vstsConfig = new VstsConfig(); Assert.Throws <ArgumentNullException>(() => this.sut = new VstsReleaseRepository(releaseClient, null, vstsConfig)); }
public void UpdateReleaseEnvironment_EnvironmentIdNaN_ThrowsException() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); Assert.Throws <ArgumentException>(() => this.sut.UpdateReleaseEnvironment("123", "someEnvironment")); }
public void GetLatest_ThrowsException() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); Assert.Throws <NotImplementedException>(() => this.sut.GetLatest("someService")); }
public void GetReleaseId_NullService_ThrowsException() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); Assert.Throws <ArgumentException>(() => this.sut.GetReleaseId(null, version: "someVersion")); }
public void GetEnvironmentId_ReleaseIdNaN_ThrowsException() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); Assert.Throws <ArgumentException>(() => this.sut.GetReleaseEnvironmentId("someRelease", "999")); }
public void UpdateApproval_NullReleaseId_ThrowsException() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); Assert.Throws <ArgumentException>(() => this.sut.UpdateApproval(null)); }
public void UpdateApproval_AuthenticationFails_ThrowsException() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult()); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); Assert.Throws <AuthenticationException>(() => this.sut.UpdateApproval("123")); }
public void GetReleaseId_AuthenticationFails_ThrowsException() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult()); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); Assert.Throws <AuthenticationException>(() => this.sut.GetReleaseId("someRelease", "some Version")); }
public void GetReleaseEnvironmentStatus_AuthenticationSucceeds_GetsRelease() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult { Success = true }); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); this.sut.GetReleaseEnvironmentStatus("123", "999"); releaseClient.ReceivedWithAnyArgs().GetRelease(default(int), default(string)); }
public void GetEnvironmentId_NoRelease_ReturnsNull() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult { Success = true }); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); string result = this.sut.GetReleaseEnvironmentId("999", "someEnvironment"); Assert.Null(result); }
public void GetReleaseId_AuthenticationSucceeds_GetsReleaseDefinitions() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult { Success = true }); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); this.sut.GetReleaseId("someService", version: "someVersion"); releaseClient.ReceivedWithAnyArgs().GetReleaseDefinitions(default(string), default(string)); }
public void GetReleaseId_NoReleaseDefintions_ReturnsNull() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult { Success = true }); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); string result = this.sut.GetReleaseId("someService", version: "someVersion"); Assert.Null(result); }
public void GetReleaseId_WithPrereqEnv_GetsReleaseWithPrereq() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult { Success = true }); releaseClient.GetReleaseDefinitions(Arg.Any <string>(), Arg.Any <string>()).Returns(GetTestReleaseDefinitions()); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); this.sut.GetReleaseId("someService", version: null, prereqEnvironment: "someEnvironment"); releaseClient.Received().GetReleases(Arg.Any <int>(), Arg.Any <string>(), null, Arg.Any <int>()); }
public void GetReleaseId_WithBranch_GetsBuilds() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult { Success = true }); releaseClient.GetReleaseDefinitions(Arg.Any <string>(), Arg.Any <string>()).Returns(GetTestReleaseDefinitions()); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); this.sut.GetReleaseId("someService", branch: "someBranch"); releaseClient.ReceivedWithAnyArgs().GetBuilds(default(int), default(string), default(string), default(string)); }
public void GetReleaseEnvironmentStatus_DoesntGetRelease_ReturnsUnknown() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult { Success = true }); releaseClient.GetRelease(Arg.Any <int>(), Arg.Any <string>()).Returns((Release)null); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); SolutionDeploy.Core.DeploymentStatus result = this.sut.GetReleaseEnvironmentStatus("123", "999"); Assert.Equal(SolutionDeploy.Core.DeploymentStatus.Unknown, result); }
public void GetReleaseEnvironmentStatus_ReleaseInProgress_ChecksForApprovals() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult { Success = true }); releaseClient.GetRelease(Arg.Any <int>(), Arg.Any <string>()).Returns(GetTestRelease(EnvironmentStatus.InProgress)); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); SolutionDeploy.Core.DeploymentStatus result = this.sut.GetReleaseEnvironmentStatus("123", "123"); releaseClient.ReceivedWithAnyArgs().GetApprovals(default(int), default(string)); }
public void GetEnvironmentId_GetsEnvironment_ReturnsEnvironmentId() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult { Success = true }); releaseClient.GetRelease(Arg.Any <int>(), Arg.Any <string>()) .Returns(GetTestRelease(EnvironmentStatus.Succeeded)); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); string result = this.sut.GetReleaseEnvironmentId("999", "Environment1"); Assert.NotNull(result); }
public void GetReleaseEnvironmentStatus_ReleaseHasNoApprovals_ReturnsInProgress() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult { Success = true }); releaseClient.GetRelease(Arg.Any <int>(), Arg.Any <string>()).Returns(GetTestRelease(EnvironmentStatus.InProgress)); releaseClient.GetApprovals(Arg.Any <int>(), Arg.Any <string>()).Returns(new List <ReleaseApproval>()); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); SolutionDeploy.Core.DeploymentStatus result = this.sut.GetReleaseEnvironmentStatus("123", "123"); Assert.Equal(SolutionDeploy.Core.DeploymentStatus.InProgress, result); }
private static void AddServices(IServiceCollection serviceCollection, Options options) { serviceCollection .AddSingleton <IFileSystem, FileSystem>() .AddSingleton <IHttpClient, HttpClient>() .AddSingleton <IProductManifestRepository, JsonFileProductManifestRepository>() .AddSingleton <ITokenRepository, JsonFileTokenRepository>() .AddSingleton <IVstsReleaseClient, VstsSyncReleaseClient>( (ctx) => { return(new VstsSyncReleaseClient(Configuration.VstsConfig, options)); }) .AddSingleton <IReleaseRepository, VstsReleaseRepository>( (ctx) => { IVstsReleaseClient releaseClient = ctx.GetService <IVstsReleaseClient>(); IAuthenticator authenticator = ctx.GetService <IAuthenticator>(); return(new VstsReleaseRepository( releaseClient, authenticator, Configuration.VstsConfig)); }) .AddSingleton <IAuthenticator, VstsOAuthAuthenticator>( (ctx) => { IHttpClient httpClient = ctx.GetService <IHttpClient>(); ITokenRepository tokenRepository = ctx.GetService <ITokenRepository>(); return(new VstsOAuthAuthenticator( httpClient, tokenRepository, Configuration.VstsConfig)); }) .AddSingleton <IServiceDeploymentExecutor, VstsDeploymentExecutor>( (ctx) => { IReleaseRepository repository = ctx.GetService <IReleaseRepository>(); return (new VstsDeploymentExecutor(repository, Configuration.VstsConfig, options)); }) .AddSingleton <IServiceDeploymentHandler, SequentialDeploymentHandler>( (ctx) => { IServiceDeploymentExecutor executor = ctx.GetService <IServiceDeploymentExecutor>(); return(new SequentialDeploymentHandler(executor, 10, options)); }) .AddSingleton <IDeploymentService, DeploymentService>(); }
public void GetReleaseId_GetsReleases_ReturnsReleaseId() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult { Success = true }); releaseClient.GetReleaseDefinitions(Arg.Any <string>(), Arg.Any <string>()).Returns(GetTestReleaseDefinitions()); releaseClient.GetBuilds(Arg.Any <int>(), Arg.Any <string>(), Arg.Any <string>()).Returns(GetTestBuilds()); releaseClient.GetReleases(Arg.Any <int>(), Arg.Any <string>(), Arg.Any <int>()).Returns(GetTestReleases()); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); string result = this.sut.GetReleaseId("someService", version: "someVersion"); Assert.NotNull(result); }
internal void GetReleaseEnvironmentStatus_GetsEnvironment_ReturnsStatus( EnvironmentStatus envStatus, SolutionDeploy.Core.DeploymentStatus deployStatus) { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig(); authenticator.Authenticate().Returns(new AuthenticationResult { Success = true }); releaseClient.GetRelease(Arg.Any <int>(), Arg.Any <string>()) .Returns(this.GetTestRelease(envStatus)); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); SolutionDeploy.Core.DeploymentStatus result = this.sut.GetReleaseEnvironmentStatus("123", "123"); Assert.Equal(deployStatus, result); }
public void UpdateReleaseEnvironment_Succeeds() { VstsConfig vstsConfig = GetVstsConfig(); IHttpClient httpClient = new HttpClient(); ITokenRepository repository = new JsonFileTokenRepository(new FileSystem()); IAuthenticator authenticator = new VstsOAuthAuthenticator(httpClient, repository, vstsConfig); File.Copy($"..//..//..//testdata//{TokenFilename}", fullTokenFilename, true); AuthenticationResult authResult = authenticator.Authenticate(); File.Copy(fullTokenFilename, $"..//..//..//testdata//{TokenFilename}", true); this.sut = new VstsSyncReleaseClient(vstsConfig); ReleaseEnvironment result = this.sut.UpdateReleaseEnvironment(11, 11, authResult.AccessToken); Assert.NotNull(result); Assert.Equal(EnvironmentStatus.Queued, result.Status); }
public void GetReleaseId_Authenticates() { IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>(); IAuthenticator authenticator = Substitute.For <IAuthenticator>(); VstsConfig vstsConfig = new VstsConfig { BaseUrl = @"" }; authenticator.Authenticate().Returns(new AuthenticationResult { Success = true, AccessToken = "foo" }); this.sut = new VstsReleaseRepository(releaseClient, authenticator, vstsConfig); this.sut.GetReleaseId("someRelease", version: "someVersion"); authenticator.Received().Authenticate(); }
public VstsReleaseRepository( IVstsReleaseClient releaseClient, IAuthenticator authenticator, VstsConfig vstsConfig) { if (releaseClient == null) { throw new ArgumentNullException(nameof(releaseClient)); } if (authenticator == null) { throw new ArgumentNullException(nameof(authenticator)); } if (vstsConfig == null) { throw new ArgumentNullException(nameof(vstsConfig)); } this.releaseClient = releaseClient; this.authenticator = authenticator; this.vstsConfig = vstsConfig; }
public void GetReleaseDefinition_Succeeds() { VstsConfig vstsConfig = GetVstsConfig(); IHttpClient httpClient = new HttpClient(); ITokenRepository repository = new JsonFileTokenRepository(new FileSystem()); IAuthenticator authenticator = new VstsOAuthAuthenticator(httpClient, repository, vstsConfig); File.Copy($"..//..//..//testdata//{TokenFilename}", fullTokenFilename, true); AuthenticationResult authResult = authenticator.Authenticate(); File.Copy(fullTokenFilename, $"..//..//..//testdata//{TokenFilename}", true); this.sut = new VstsSyncReleaseClient(vstsConfig); ReleaseDefinition result = this.sut.GetReleaseDefinition(1, authResult.AccessToken); Assert.NotNull(result); SaveResultData(result, "../../../testdata/GetReleaseDefinition.json"); }
public void UpdateApproval_Succeeds() { VstsConfig vstsConfig = GetVstsConfig(); IHttpClient httpClient = new HttpClient(); ITokenRepository repository = new JsonFileTokenRepository(new FileSystem()); IAuthenticator authenticator = new VstsOAuthAuthenticator(httpClient, repository, vstsConfig); File.Copy($"..//..//..//testdata//{TokenFilename}", fullTokenFilename, true); AuthenticationResult authResult = authenticator.Authenticate(); File.Copy(fullTokenFilename, $"..//..//..//testdata//{TokenFilename}", true); this.sut = new VstsSyncReleaseClient(vstsConfig); ReleaseApproval result = this.sut.UpdateApproval(123, authResult.AccessToken); Assert.NotNull(result); Assert.Equal(ApprovalStatus.Approved, result.Status); SaveResultData(result, "../../../testdata/UpdateApproval.json"); }