コード例 #1
0
        public void Ctor_NullReleaseRepository_ThrowsException()
        {
            VstsConfig vstsConfig = new VstsConfig();

            Assert.Throws <ArgumentNullException>(() => this.sut =
                                                      new VstsDeploymentExecutor(null, vstsConfig));
        }
コード例 #2
0
        public void Ctor_NegativeInterval_ThrowsException()
        {
            IServiceDeploymentExecutor deploymentExecutor = Substitute.For <IServiceDeploymentExecutor>();

            Assert.Throws <ArgumentException>(() => this.sut =
                                                  new SequentialDeploymentHandler(deploymentExecutor, -1));
        }
コード例 #3
0
        public void Ctor_NullVstsConfig_ThrowsException()
        {
            IReleaseRepository releaseRepository = Substitute.For <IReleaseRepository>();

            Assert.Throws <ArgumentNullException>(() =>
                                                  this.sut = new VstsDeploymentExecutor(releaseRepository, null));
        }
コード例 #4
0
        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>());
        }
コード例 #5
0
        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"));
        }
コード例 #6
0
        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"));
        }
コード例 #7
0
        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"));
        }
コード例 #8
0
        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>());
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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;
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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));
        }
コード例 #15
0
        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>());
        }
コード例 #16
0
        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);
        }
コード例 #17
0
 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>();
 }
コード例 #18
0
        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>());
        }