public async Task <VstsReleaseDefinition> GetRelease(int releaseDefinitionId) { var client = _vssConnection.GetClient <ReleaseHttpClient>(); var release = await client.GetReleaseDefinitionAsync(_configuration.Value.ProjectName, releaseDefinitionId); var vstsRelease = new VstsReleaseDefinition { Id = release.Id, ReleaseName = release.Name }; return(vstsRelease); }
public async Task AddStandardNonRingTest() { using (var scope = Fixture.Container.BeginLifetimeScope()) { var cl = scope.Resolve <HttpClient>(); var vstsConfig = scope.Resolve <VstsConfiguration>(); var releaseClient = scope.Resolve <ReleaseHttpClient2>(); var releaseDefinition = new VstsReleaseDefinition { BuildDefinition = new VstsBuildDefinition { TenantCode = "L2TNT", VstsBuildDefinitionId = vstsConfig.WebApiBuildDefinitionTemplate.DefinitionId, SourceCode = new SourceCodeRepository { TenantCode = "L2TNT", ProjectType = ProjectTypeEnum.WebApi, SourceRepositoryName = "ForkIntTestSourceRepo", Fork = false } }, TenantCode = "L2TNT", SkipEnvironments = new[] { DeploymentEnvironment.Prod }, RingBased = false }; try { var resp = await cl.PostJsonToActor(Fixture.TestMiddlewareUri, "ReleaseDefinition", "Add", releaseDefinition); resp.State.Should().Be(EntityStateEnum.Created); resp.VstsReleaseDefinitionId.Should().NotBe(default(int)); var vstsRel = await releaseClient.GetReleaseDefinitionAsync(vstsConfig.VstsTargetProjectId, resp.VstsReleaseDefinitionId); vstsRel.Should().NotBeNull(); vstsRel.Environments.Should().NotContain(e => e.Name.StartsWith(DeploymentEnvironment.Prod.ToString(), StringComparison.OrdinalIgnoreCase)); //no PROD check } finally { await cl.PostJsonToActor(Fixture.TestMiddlewareUri, "ReleaseDefinition", "Remove", releaseDefinition); } } }
public async Task AddStandardRingTest() { using (var scope = Fixture.Container.BeginLifetimeScope()) { var cl = scope.Resolve <HttpClient>(); var vstsConfig = scope.Resolve <VstsConfiguration>(); var releaseClient = scope.Resolve <ReleaseHttpClient2>(); var releaseDefinition = new VstsReleaseDefinition { BuildDefinition = new VstsBuildDefinition { TenantCode = "L2TNT", VstsBuildDefinitionId = vstsConfig.WebApiBuildDefinitionTemplate.DefinitionId, SourceCode = new SourceCodeRepository { TenantCode = "L2TNT", ProjectType = ProjectTypeEnum.WebApi, SourceRepositoryName = "ForkIntTestSourceRepo", Fork = false } }, TenantCode = "L2TNT", TenantSize = TenantSize.Small, RingBased = true }; try { var resp = await cl.PostJsonToActor(Fixture.TestMiddlewareUri, "ReleaseDefinition", "Add", releaseDefinition); resp.State.Should().Be(EntityStateEnum.Created); resp.VstsReleaseDefinitionId.Should().NotBe(default(int)); var vstsRel = await releaseClient.GetReleaseDefinitionAsync(vstsConfig.VstsTargetProjectId, resp.VstsReleaseDefinitionId); vstsRel.Should().NotBeNull(); //check variable containing definition vstsRel.Variables["SmallTenants"].Value.Should().Be("L2TNT#11111"); } finally { await cl.PostJsonToActor(Fixture.TestMiddlewareUri, "ReleaseDefinition", "Remove", releaseDefinition); } } }
public async Task RemoveForkTest() { using (var scope = Fixture.Container.BeginLifetimeScope()) { var cl = scope.Resolve <HttpClient>(); var vstsConfig = scope.Resolve <VstsConfiguration>(); var releaseClient = scope.Resolve <ReleaseHttpClient2>(); var releaseDefinition = new VstsReleaseDefinition { BuildDefinition = new VstsBuildDefinition { TenantCode = "L2TNT", VstsBuildDefinitionId = vstsConfig.WebApiBuildDefinitionTemplate.DefinitionId, SourceCode = new SourceCodeRepository { TenantCode = "L2TNT", ProjectType = ProjectTypeEnum.WebApi, SourceRepositoryName = "ForkIntTestSourceRepo", Fork = true } }, TenantCode = "L2TNT" }; try { await cl.PostJsonToActor(Fixture.TestMiddlewareUri, "ReleaseDefinition", "Add", releaseDefinition); } finally { await cl.PostJsonToActor(Fixture.TestMiddlewareUri, "ReleaseDefinition", "Remove", releaseDefinition); (await releaseClient.GetReleaseDefinitionsAsync(vstsConfig.VstsTargetProjectId, releaseDefinition.ToString(), isExactNameMatch: true)).Should().BeNullOrEmpty(); } } }
public void SwitchForkToStandardComponent() { var forkRepoA = new SourceCodeRepository { State = EntityStateEnum.Created, SourceRepositoryName = "RepoA", TenantCode = "TenantA", Fork = true }; var relDefA = new VstsReleaseDefinition { TenantCode = "TenantA", State = EntityStateEnum.Created }; var buildDefA = new VstsBuildDefinition { SourceCode = forkRepoA, TenantCode = "TenantA", ReleaseDefinitions = new[] { relDefA }.ToList(), State = EntityStateEnum.Created }; relDefA.BuildDefinition = buildDefA; var currentTenant = new Tenant { Code = "TenantA", Name = "oldName", SourceRepos = new List <SourceCodeRepository>(new[] { forkRepoA }), BuildDefinitions = new List <VstsBuildDefinition>(new[] { buildDefA }), ReleaseDefinitions = new List <VstsReleaseDefinition>(new[] { relDefA }) }; var tenantRequest = new Tenant { SourceRepos = new List <SourceCodeRepository>(new[] { new SourceCodeRepository { SourceRepositoryName = "RepoA", Fork = false } }) }; currentTenant.Update(tenantRequest, GetEnvironments()); //check fork repo in to be deleted state and standard component in to be created currentTenant.SourceRepos.Should().HaveCount(2); currentTenant.SourceRepos.Should().ContainSingle(r => r.Fork && r.SourceRepositoryName == "RepoA" && r.State == EntityStateEnum.ToBeDeleted); currentTenant.SourceRepos.Should().ContainSingle(r => !r.Fork && r.SourceRepositoryName == "RepoA" && r.State == EntityStateEnum.NotCreated); //check the same for build definition var newRepo = currentTenant.SourceRepos.First(r => !r.Fork); currentTenant.BuildDefinitions.Should().HaveCount(2); currentTenant.BuildDefinitions.Should().ContainSingle(b => b.SourceCode.Equals(forkRepoA) && b.State == EntityStateEnum.ToBeDeleted); currentTenant.BuildDefinitions.Should().ContainSingle(b => b.SourceCode.Equals(newRepo) && b.State == EntityStateEnum.NotCreated); //check the same for release definition var newBuildDef = currentTenant.BuildDefinitions.First(r => r.SourceCode.Equals(newRepo)); currentTenant.ReleaseDefinitions.Should().HaveCount(3); currentTenant.ReleaseDefinitions.Should() .ContainSingle(r => r.BuildDefinition.Equals(buildDefA) && r.State == EntityStateEnum.ToBeDeleted); currentTenant.ReleaseDefinitions.Should() .ContainSingle(r => r.BuildDefinition.Equals(newBuildDef) && r.State == EntityStateEnum.NotCreated && !r.RingBased); currentTenant.ReleaseDefinitions.Should() .ContainSingle(r => r.BuildDefinition.Equals(newBuildDef) && r.State == EntityStateEnum.NotCreated && r.RingBased); }
public void Update_RemoveRepo() { var forkRepoA = new SourceCodeRepository { State = EntityStateEnum.Created, SourceRepositoryName = "RepoA", TenantCode = "TenantA" }; var forkRepoB = new SourceCodeRepository { State = EntityStateEnum.Created, SourceRepositoryName = "RepoB", TenantCode = "TenantA" }; var relDefA = new VstsReleaseDefinition { TenantCode = "TenantA", State = EntityStateEnum.Created }; var relDefB = new VstsReleaseDefinition { TenantCode = "TenantB", State = EntityStateEnum.Created }; var buildDefA = new VstsBuildDefinition { SourceCode = forkRepoA, TenantCode = "TenantA", ReleaseDefinitions = new[] { relDefA }.ToList(), State = EntityStateEnum.Created }; var buildDefB = new VstsBuildDefinition { SourceCode = forkRepoB, TenantCode = "TenantA", ReleaseDefinitions = new[] { relDefB }.ToList(), State = EntityStateEnum.Created }; relDefA.BuildDefinition = buildDefA; relDefB.BuildDefinition = buildDefB; var currentTenant = new Tenant { Code = "TenantA", Name = "oldName", SourceRepos = new List <SourceCodeRepository>(new[] { forkRepoA, forkRepoB }), BuildDefinitions = new List <VstsBuildDefinition>(new[] { buildDefA, buildDefB }), ReleaseDefinitions = new List <VstsReleaseDefinition>(new[] { relDefA, relDefB }) }; var tenantRequest = new Tenant { SourceRepos = new List <SourceCodeRepository>(new[] { new SourceCodeRepository { SourceRepositoryName = "RepoA" } }) }; currentTenant.Update(tenantRequest, GetEnvironments()); //forks checks currentTenant.SourceRepos.Should().NotContain(f => f.State == EntityStateEnum.NotCreated); currentTenant.SourceRepos.Should() .ContainSingle(f => f.SourceRepositoryName == "RepoB" && f.TenantCode == "TenantA" && f.State == EntityStateEnum.ToBeDeleted); //build definition checks currentTenant.BuildDefinitions.Should().NotContain(d => d.State == EntityStateEnum.NotCreated); currentTenant.BuildDefinitions.Should() .ContainSingle(d => d.SourceCode.SourceRepositoryName == "RepoB" && forkRepoA.TenantCode == "TenantA" && d.State == EntityStateEnum.ToBeDeleted); //release definition checks currentTenant.ReleaseDefinitions.Should().NotContain(d => d.State == EntityStateEnum.NotCreated); currentTenant.ReleaseDefinitions.Should() .ContainSingle(d => d.BuildDefinition.SourceCode.SourceRepositoryName == "RepoB" && forkRepoA.TenantCode == "TenantA" && d.State == EntityStateEnum.ToBeDeleted); }
public void Update_AddAdditionalRepo() { var fork = new SourceCodeRepository { SourceRepositoryName = "AlreadyThere", State = EntityStateEnum.Created, TenantCode = "TenantA", Fork = true }; var relDefA = new VstsReleaseDefinition { TenantCode = "TenantA", State = EntityStateEnum.Created }; var buildDefA = new VstsBuildDefinition { SourceCode = fork, TenantCode = "TenantA", ReleaseDefinitions = new[] { relDefA }.ToList(), State = EntityStateEnum.Created }; var currentTenant = new Tenant { Code = "TenantA", Name = "oldName", SourceRepos = new List <SourceCodeRepository>(new[] { fork }), BuildDefinitions = new List <VstsBuildDefinition>(new[] { buildDefA }), ReleaseDefinitions = new List <VstsReleaseDefinition>() { relDefA } }; var tenantRequest = new Tenant { SourceRepos = new List <SourceCodeRepository>(new[] { new SourceCodeRepository { SourceRepositoryName = "A", Fork = true }, fork }) }; currentTenant.Update(tenantRequest, GetEnvironments()); currentTenant.SourceRepos.Should().HaveCount(2); //forks checks currentTenant.SourceRepos.Should().ContainSingle(f => f.State == EntityStateEnum.NotCreated); currentTenant.SourceRepos.Should() .ContainSingle(f => f.SourceRepositoryName == "A" && f.TenantCode == "TenantA" && f.State == EntityStateEnum.NotCreated); currentTenant.SourceRepos.Should() .Contain(f => f.SourceRepositoryName == "AlreadyThere" && f.State == EntityStateEnum.Created && f.TenantCode == "TenantA"); //build definition checks currentTenant.BuildDefinitions.Should().ContainSingle(bd => bd.State == EntityStateEnum.NotCreated); currentTenant.BuildDefinitions.Should() .ContainSingle(d => d.State == EntityStateEnum.NotCreated && d.TenantCode == "TenantA" && d.SourceCode.SourceRepositoryName == "A"); currentTenant.BuildDefinitions.Should().NotContain(bd => bd.State == EntityStateEnum.ToBeDeleted); //release definition checks currentTenant.ReleaseDefinitions.Should().ContainSingle(bd => bd.State == EntityStateEnum.NotCreated); currentTenant.ReleaseDefinitions.Should() .ContainSingle(d => d.State == EntityStateEnum.NotCreated && d.TenantCode == "TenantA" && d.BuildDefinition.SourceCode.SourceRepositoryName == "A"); currentTenant.ReleaseDefinitions.Should().NotContain(bd => bd.State == EntityStateEnum.ToBeDeleted); }
public async Task MultipleTenantsToRingTest() { using (var scope = Fixture.Container.BeginLifetimeScope()) { var cl = scope.Resolve <HttpClient>(); var vstsConfig = scope.Resolve <VstsConfiguration>(); var releaseClient = scope.Resolve <ReleaseHttpClient2>(); var releaseDefinition1 = new VstsReleaseDefinition { BuildDefinition = new VstsBuildDefinition { TenantCode = "L2TNT", VstsBuildDefinitionId = vstsConfig.WebApiBuildDefinitionTemplate.DefinitionId, SourceCode = new SourceCodeRepository { TenantCode = "L2TNT", ProjectType = ProjectTypeEnum.WebApi, SourceRepositoryName = "ForkIntTestSourceRepo", Fork = false } }, TenantCode = "L2TNT", TenantSize = TenantSize.Small, RingBased = true }; var releaseDefinition2 = new VstsReleaseDefinition { BuildDefinition = new VstsBuildDefinition { TenantCode = "L2TNT2", VstsBuildDefinitionId = vstsConfig.WebApiBuildDefinitionTemplate.DefinitionId, SourceCode = new SourceCodeRepository { TenantCode = "L2TNT2", ProjectType = ProjectTypeEnum.WebApi, SourceRepositoryName = "ForkIntTestSourceRepo", Fork = false } }, TenantCode = "L2TNT2", TenantSize = TenantSize.Small, RingBased = true }; var pipelineId = 0; try { //first tenant var resp1 = await cl.PostJsonToActor(Fixture.TestMiddlewareUri, "ReleaseDefinition", "Add", releaseDefinition1); resp1.State.Should().Be(EntityStateEnum.Created); resp1.VstsReleaseDefinitionId.Should().NotBe(default(int)); //second tenant var resp2 = await cl.PostJsonToActor(Fixture.TestMiddlewareUri, "ReleaseDefinition", "Add", releaseDefinition2); resp2.State.Should().Be(EntityStateEnum.Created); resp2.VstsReleaseDefinitionId.Should().NotBe(default(int)); //checks resp1.VstsReleaseDefinitionId.Should().Be(resp2.VstsReleaseDefinitionId); //sharing the ring var vstsRel = await releaseClient.GetReleaseDefinitionAsync(vstsConfig.VstsTargetProjectId, resp1.VstsReleaseDefinitionId); vstsRel.Should().NotBeNull(); //check variable containing definition vstsRel.Variables["SmallTenants"].Value.Should().ContainAll("L2TNT2#11111", "L2TNT#11111"); pipelineId = resp1.VstsReleaseDefinitionId; } finally { await cl.PostJsonToActor(Fixture.TestMiddlewareUri, "ReleaseDefinition", "Remove", releaseDefinition1); //check tenant definition gone var vstsRel = await releaseClient.GetReleaseDefinitionAsync(vstsConfig.VstsTargetProjectId, pipelineId); vstsRel.Variables["SmallTenants"].Value.Should().Be("L2TNT2#11111"); await cl.PostJsonToActor(Fixture.TestMiddlewareUri, "ReleaseDefinition", "Remove", releaseDefinition2); //check pipeline gone var pipelines = await releaseClient.GetReleaseDefinitionsAsync2(vstsConfig.VstsTargetProjectId); pipelines.Should().NotContain(p => p.Id == pipelineId); } } }