public void Ctor_NullReleaseRepository_ThrowsException() { VstsConfig vstsConfig = new VstsConfig(); Assert.Throws <ArgumentNullException>(() => this.sut = new VstsDeploymentExecutor(null, vstsConfig)); }
public void Ctor_NegativeInterval_ThrowsException() { IServiceDeploymentExecutor deploymentExecutor = Substitute.For <IServiceDeploymentExecutor>(); Assert.Throws <ArgumentException>(() => this.sut = new SequentialDeploymentHandler(deploymentExecutor, -1)); }
public void Ctor_NullVstsConfig_ThrowsException() { IReleaseRepository releaseRepository = Substitute.For <IReleaseRepository>(); Assert.Throws <ArgumentNullException>(() => this.sut = new VstsDeploymentExecutor(releaseRepository, null)); }
public void Deploy_DoesntGetVersion_DoesntDeploy() { IServiceDeploymentExecutor deploymentExecutor = Substitute.For <IServiceDeploymentExecutor>(); this.sut = new SequentialDeploymentHandler(deploymentExecutor, 0); this.sut.Deploy(GetTestManifest(2), environment: "someEnvironment", productVersion: "wrongVersion"); deploymentExecutor.DidNotReceiveWithAnyArgs().Deploy(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()); }
public void Deploy_NullEnvironment_ThrowsException() { IReleaseRepository releaseRepository = Substitute.For <IReleaseRepository>(); VstsConfig vstsConfig = new VstsConfig(); this.sut = new VstsDeploymentExecutor(releaseRepository, vstsConfig); Assert.Throws <ArgumentException>(() => this.sut.Deploy("someService", environment: null, version: "someVersion")); }
public void Deploy_NullEnvironment_ThrowsException() { IServiceDeploymentExecutor deploymentExecutor = Substitute.For <IServiceDeploymentExecutor>(); this.sut = new SequentialDeploymentHandler(deploymentExecutor, 0); Assert.Throws <ArgumentException>(() => this.sut.Deploy(GetTestManifest(1), environment: null, productVersion: "someVersion")); }
public void GetDeploymentStatus_NullServiceName_ThrowsException() { IReleaseRepository releaseRepository = Substitute.For <IReleaseRepository>(); VstsConfig vstsConfig = new VstsConfig(); this.sut = new VstsDeploymentExecutor(releaseRepository, vstsConfig); Assert.Throws <ArgumentException>(() => this.sut .GetDeploymentStatus(null, "someEnvironment", "someVersion")); }
public void Deploy_DoesntSucceed_Aborts() { IServiceDeploymentExecutor deploymentExecutor = Substitute.For <IServiceDeploymentExecutor>(); deploymentExecutor.Deploy(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Returns(true); deploymentExecutor.GetDeploymentStatus( Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Returns(DeploymentStatus.Failed); this.sut = new SequentialDeploymentHandler(deploymentExecutor, 0); this.sut.Deploy(GetTestManifest(2), environment: "someEnvironment", productVersion: "someVersion"); deploymentExecutor.Received(1).Deploy(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()); }
public void Deploy_DoesntGetReleaseId_DoesntGetEnvironmentId() { IReleaseRepository releaseRepository = Substitute.For <IReleaseRepository>(); VstsConfig vstsConfig = new VstsConfig(); releaseRepository.GetReleaseId(Arg.Any <string>(), Arg.Any <string>()).Returns((string)null); this.sut = new VstsDeploymentExecutor(releaseRepository, vstsConfig); sut.Deploy("someService", environment: "someEnvironment", version: "someVersion"); releaseRepository.DidNotReceiveWithAnyArgs().GetReleaseEnvironmentId( default(string), default(string)); }
public SequentialDeploymentHandler( IServiceDeploymentExecutor deploymentExecutor, int deploymentStatusCheckInterval, Options options = null) { if (deploymentStatusCheckInterval < 0) { throw new ArgumentException("parameter cannot be less than 0", nameof(deploymentStatusCheckInterval)); } this.deploymentExecutor = deploymentExecutor ?? throw new ArgumentNullException(nameof(deploymentExecutor)); this.deploymentStatusCheckInterval = deploymentStatusCheckInterval * 1000; this.options = options; }
public void GetDeploymentStatus_GetsReleaseId_GetsEnvironmentId() { IReleaseRepository releaseRepository = Substitute.For <IReleaseRepository>(); VstsConfig vstsConfig = new VstsConfig(); releaseRepository.GetReleaseId(Arg.Any <string>(), Arg.Any <string>()) .Returns("123"); this.sut = new VstsDeploymentExecutor(releaseRepository, vstsConfig); this.sut.GetDeploymentStatus("someService", "someEnvironment", "someVersion"); releaseRepository.ReceivedWithAnyArgs().GetReleaseEnvironmentId(default(string), default(string)); }
public void GetDeploymentStatus_DoesntGetReleaseId_ReturnsUnknown() { IReleaseRepository releaseRepository = Substitute.For <IReleaseRepository>(); VstsConfig vstsConfig = new VstsConfig(); releaseRepository.GetReleaseId(Arg.Any <string>(), Arg.Any <string>()) .Returns((string)null); this.sut = new VstsDeploymentExecutor(releaseRepository, vstsConfig); DeploymentStatus result = this.sut.GetDeploymentStatus("someService", "someEnvironment", "someVersion"); Assert.Equal(DeploymentStatus.Unknown, result); }
public void Deploy_UpdatesEnvironment_ReturnsTrue() { IReleaseRepository releaseRepository = Substitute.For <IReleaseRepository>(); VstsConfig vstsConfig = new VstsConfig(); releaseRepository.GetReleaseId(Arg.Any <string>(), Arg.Any <string>()).Returns("123"); releaseRepository.GetReleaseEnvironmentId(Arg.Any <string>(), Arg.Any <string>()).Returns("123"); this.sut = new VstsDeploymentExecutor(releaseRepository, vstsConfig); bool retval = sut.Deploy("someService", environment: "someEnvironment", version: "someVersion"); Assert.True(retval); }
public void Deploy_WhatIf_DoesntUpdateEnvironment() { IReleaseRepository releaseRepository = Substitute.For <IReleaseRepository>(); VstsConfig vstsConfig = new VstsConfig(); releaseRepository.GetReleaseId(Arg.Any <string>(), Arg.Any <string>()).Returns("123"); releaseRepository.GetReleaseEnvironmentId(Arg.Any <string>(), Arg.Any <string>()).Returns("123"); this.sut = new VstsDeploymentExecutor(releaseRepository, vstsConfig, new Options { WhatIf = true }); sut.Deploy("someService", environment: "someEnvironment", version: "someVersion"); releaseRepository.DidNotReceiveWithAnyArgs().UpdateReleaseEnvironment(default(string), default(string)); }
public void Deploy_DeploymentQueued_Waits() { IServiceDeploymentExecutor deploymentExecutor = Substitute.For <IServiceDeploymentExecutor>(); deploymentExecutor.Deploy(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Returns(true); Stack <DeploymentStatus> statusResults = new Stack <DeploymentStatus>(); statusResults.Push(DeploymentStatus.Succeeded); statusResults.Push(DeploymentStatus.Queued); deploymentExecutor.GetDeploymentStatus( Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Returns(x => statusResults.Pop()); this.sut = new SequentialDeploymentHandler(deploymentExecutor, 0); this.sut.Deploy(GetTestManifest(1), environment: "someEnvironment", productVersion: "someVersion"); deploymentExecutor.Received(2).GetDeploymentStatus(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()); }
public void GetDeploymentStatus_GetsEnvironmentStatus_ReturnsStatus() { IReleaseRepository releaseRepository = Substitute.For <IReleaseRepository>(); VstsConfig vstsConfig = new VstsConfig(); releaseRepository.GetReleaseId(Arg.Any <string>(), Arg.Any <string>()) .Returns("123"); releaseRepository.GetReleaseEnvironmentId(Arg.Any <string>(), Arg.Any <string>()) .Returns("123"); releaseRepository.GetReleaseEnvironmentStatus(Arg.Any <string>(), Arg.Any <string>()) .Returns(DeploymentStatus.Succeeded); this.sut = new VstsDeploymentExecutor(releaseRepository, vstsConfig); DeploymentStatus result = this.sut.GetDeploymentStatus( "someService", "someEnvironment", "someVersion"); Assert.Equal(DeploymentStatus.Succeeded, 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 Deploy_Whatif_DoesntWait() { IServiceDeploymentExecutor deploymentExecutor = Substitute.For <IServiceDeploymentExecutor>(); deploymentExecutor.Deploy(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Returns(true); Stack <DeploymentStatus> statusResults = new Stack <DeploymentStatus>(); statusResults.Push(DeploymentStatus.Succeeded); statusResults.Push(DeploymentStatus.InProgress); deploymentExecutor.GetDeploymentStatus( Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Returns(x => statusResults.Pop()); this.sut = new SequentialDeploymentHandler(deploymentExecutor, 0, new Options { WhatIf = true }); this.sut.Deploy(GetTestManifest(1), environment: "someEnvironment", productVersion: "someVersion"); deploymentExecutor.DidNotReceiveWithAnyArgs().GetDeploymentStatus(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()); }