Ejemplo n.º 1
0
        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>());
        }
Ejemplo n.º 2
0
        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");
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        public void Ctor_NullAuthenticator_ThrowsException()
        {
            IVstsReleaseClient releaseClient = Substitute.For <IVstsReleaseClient>();
            VstsConfig         vstsConfig    = new VstsConfig();

            Assert.Throws <ArgumentNullException>(() =>
                                                  this.sut = new VstsReleaseRepository(releaseClient, null, vstsConfig));
        }
Ejemplo n.º 5
0
        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"));
        }
Ejemplo n.º 6
0
        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"));
        }
Ejemplo n.º 7
0
        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"));
        }
Ejemplo n.º 8
0
        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"));
        }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
        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"));
        }
Ejemplo n.º 11
0
        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"));
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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));
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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>());
        }
Ejemplo n.º 17
0
        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));
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        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));
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
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>();
 }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
        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);
        }
Ejemplo n.º 26
0
        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();
        }
Ejemplo n.º 27
0
        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;
        }
Ejemplo n.º 28
0
        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");
        }
Ejemplo n.º 29
0
        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");
        }