private void UploadLibraryVariableSet(LibraryVariableSet libraryVariableSet) { var resource = LoadResource(_repository.LibraryVariableSets, libraryVariableSet.Identifier).UpdateWith(libraryVariableSet); resource = Upsert(_repository.LibraryVariableSets, resource); Update( _repository.VariableSets, _repository.VariableSets.Get(resource.VariableSetId).UpdateWith(libraryVariableSet, _repository, null, null), resource.Name); }
public static YamlLibraryVariableSet FromModel(LibraryVariableSet model) { return(new YamlLibraryVariableSet { Name = model.Identifier.Name, RenamedFrom = model.Identifier.RenamedFrom, Description = model.Description, ContentType = model.ContentType, Variables = model.Variables.Select(YamlVariable.FromModel).OrderBy(m => m.Name).ToArray().NullIfEmpty() }); }
private async Task <bool> BeUniqueByName(ApiLibraryVariableSetRequestModel model, CancellationToken cancellationToken) { LibraryVariableSet record = await this.libraryVariableSetRepository.ByName(model.Name); if (record == null || (this.existingRecordId != default(string) && record.Id == this.existingRecordId)) { return(true); } else { return(false); } }
public virtual BOLibraryVariableSet MapEFToBO( LibraryVariableSet ef) { var bo = new BOLibraryVariableSet(); bo.SetProperties( ef.Id, ef.ContentType, ef.JSON, ef.Name, ef.VariableSetId); return(bo); }
public virtual LibraryVariableSet MapBOToEF( BOLibraryVariableSet bo) { LibraryVariableSet efLibraryVariableSet = new LibraryVariableSet(); efLibraryVariableSet.SetProperties( bo.ContentType, bo.Id, bo.JSON, bo.Name, bo.VariableSetId); return(efLibraryVariableSet); }
public async Task <ApiLibraryVariableSetResponseModel> ByName(string name) { LibraryVariableSet record = await this.libraryVariableSetRepository.ByName(name); if (record == null) { return(null); } else { return(this.bolLibraryVariableSetMapper.MapBOToModel(this.dalLibraryVariableSetMapper.MapEFToBO(record))); } }
public void MapEFToBOList() { var mapper = new DALLibraryVariableSetMapper(); LibraryVariableSet entity = new LibraryVariableSet(); entity.SetProperties("A", "A", "A", "A", "A"); List <BOLibraryVariableSet> response = mapper.MapEFToBO(new List <LibraryVariableSet>() { entity }); response.Count.Should().Be(1); }
public void MapEFToBO() { var mapper = new DALLibraryVariableSetMapper(); LibraryVariableSet entity = new LibraryVariableSet(); entity.SetProperties("A", "A", "A", "A", "A"); BOLibraryVariableSet response = mapper.MapEFToBO(entity); response.ContentType.Should().Be("A"); response.Id.Should().Be("A"); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.VariableSetId.Should().Be("A"); }
public void MapBOToEF() { var mapper = new DALLibraryVariableSetMapper(); var bo = new BOLibraryVariableSet(); bo.SetProperties("A", "A", "A", "A", "A"); LibraryVariableSet response = mapper.MapBOToEF(bo); response.ContentType.Should().Be("A"); response.Id.Should().Be("A"); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.VariableSetId.Should().Be("A"); }
private async Task UploadLibraryVariableSet(LibraryVariableSet libraryVariableSet) { var resource = await LoadResource(_repository.LibraryVariableSets, libraryVariableSet.Identifier); resource.UpdateWith(libraryVariableSet); resource = await Upsert(_repository.LibraryVariableSets, resource); var variableSet = await _repository.VariableSets.Get(resource.VariableSetId); await variableSet.UpdateWith(libraryVariableSet, _repository, null, null); await Update( _repository.VariableSets, variableSet, resource.Name); }
public async void Get() { var mock = new ServiceMockFacade <ILibraryVariableSetRepository>(); var record = new LibraryVariableSet(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult(record)); var service = new LibraryVariableSetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.LibraryVariableSetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLLibraryVariableSetMapperMock, mock.DALMapperMockFactory.DALLibraryVariableSetMapperMock); ApiLibraryVariableSetResponseModel response = await service.Get(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>())); }
public static LibraryVariableSetResource UpdateWith(this LibraryVariableSetResource resource, LibraryVariableSet model) { resource.Name = model.Identifier.Name; resource.ContentType = (VariableSetContentType)model.ContentType; resource.Description = model.Description; return(resource); }
public void It_should_upload_and_download_tenant() { var tagset = new TagSet(new ElementIdentifier("ts1"), new List <string> { "t1", "t2" }); var environment1 = new Environment(new ElementIdentifier("env1"), CreateItem <string>()); var projectGroup = new ProjectGroup(CreateItemWithRename <ElementIdentifier>(false), string.Empty); var libraryVariableSet = new LibraryVariableSet(CreateItemWithRename <ElementIdentifier>(false), CreateItem <string>(), LibraryVariableSet.VariableSetContentType.Variables, Enumerable.Empty <Variable>()); var lifecycle = new Lifecycle( CreateItemWithRename <ElementIdentifier>(false), string.Empty, new RetentionPolicy(0, RetentionPolicy.RetentionUnit.Items), new RetentionPolicy(0, RetentionPolicy.RetentionUnit.Items), Enumerable.Empty <Phase>()); var deploymentProcess = new DeploymentProcess(new List <DeploymentStep> { new DeploymentStep(CreateItem <string>(), CreateItem <DeploymentStep.StepCondition>(), CreateItem <bool>(), CreateItem <DeploymentStep.StepStartTrigger>(), CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new[] { new DeploymentAction(CreateItem <string>(), CreateItem <string>(), CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new[] { new ElementReference("env1") }), }) }); var scope = new Dictionary <VariableScopeType, IEnumerable <ElementReference> > { { VariableScopeType.Environment, new[] { new ElementReference("env1") } }, { VariableScopeType.Action, deploymentProcess.DeploymentSteps.SelectMany(s => s.Actions.Select(a => a.Name)) .Select(action => new ElementReference(action)) .ToArray() } }; var variables = new[] { new Variable(CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <string>(), scope, CreateItem <VariablePrompt>()) }; var project1 = new Project(CreateItemWithRename <ElementIdentifier>(false), CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <bool>(), deploymentProcess, variables, new[] { new ElementReference(libraryVariableSet.Identifier.Name) }, new ElementReference(lifecycle.Identifier.Name), new ElementReference(projectGroup.Identifier.Name), CreateItem <VersioningStrategy>(), Enumerable.Empty <ProjectTrigger>(), TenantedDeploymentMode.TenantedOrUntenanted); var tenant = new Tenant(new ElementIdentifier("t1"), new[] { new ElementReference(tagset.Identifier.Name) }, new Dictionary <string, IEnumerable <string> > { { project1.Identifier.Name, new[] { environment1.Identifier.Name } } }); var expected = new SystemModelBuilder() .AddProject(project1) .AddTenant(tenant) .AddProjectGroup(projectGroup) .AddLifecycle(lifecycle) .AddLibraryVariableSet(libraryVariableSet) .AddEnvironment(environment1) .Build(); _uploader.UploadModel(expected).GetAwaiter(); var actual = _downloader.DownloadModel().GetAwaiter().GetResult(); actual.AssertDeepEqualsTo(expected); }
public void It_should_upload_and_download_projects() { var environment1 = new Environment(new ElementIdentifier("env1"), CreateItem <string>()); var environment2 = new Environment(new ElementIdentifier("env2"), CreateItem <string>()); var projectGroup = new ProjectGroup(CreateItemWithRename <ElementIdentifier>(false), string.Empty); var libraryVariableSet = new LibraryVariableSet(CreateItemWithRename <ElementIdentifier>(false), CreateItem <string>(), LibraryVariableSet.VariableSetContentType.Variables, Enumerable.Empty <Variable>()); var lifecycle = new Lifecycle( CreateItemWithRename <ElementIdentifier>(false), string.Empty, new RetentionPolicy(0, RetentionPolicy.RetentionUnit.Items), new RetentionPolicy(0, RetentionPolicy.RetentionUnit.Items), Enumerable.Empty <Phase>()); var deploymentProcess = new DeploymentProcess(new List <DeploymentStep> { new DeploymentStep(CreateItem <string>(), CreateItem <DeploymentStep.StepCondition>(), CreateItem <bool>(), CreateItem <DeploymentStep.StepStartTrigger>(), CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new[] { new DeploymentAction(CreateItem <string>(), CreateItem <string>(), CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new[] { new ElementReference("env1") }), new DeploymentAction(CreateItem <string>(), CreateItem <string>(), CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new[] { new ElementReference("env2") }) }), new DeploymentStep(CreateItem <string>(), CreateItem <DeploymentStep.StepCondition>(), CreateItem <bool>(), CreateItem <DeploymentStep.StepStartTrigger>(), CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new[] { new DeploymentAction(CreateItem <string>(), CreateItem <string>(), CreateItem <IReadOnlyDictionary <string, PropertyValue> >(), new[] { new ElementReference("env1") }) }) }); var scope = new Dictionary <VariableScopeType, IEnumerable <ElementReference> > { { VariableScopeType.Environment, new[] { new ElementReference("env1"), new ElementReference("env2") } }, { VariableScopeType.Machine, new[] { new ElementReference("m1"), new ElementReference("m2") } }, { VariableScopeType.Role, new[] { new ElementReference("r1"), new ElementReference("r2") } }, { VariableScopeType.Channel, new[] { new ElementReference("ch1"), new ElementReference("ch2") } }, { VariableScopeType.Action, deploymentProcess.DeploymentSteps.SelectMany(s => s.Actions.Select(a => a.Name)) .Select(action => new ElementReference(action)) .ToArray() } }; var variables = new[] { new Variable(CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <string>(), scope, CreateItem <VariablePrompt>()), new Variable(CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <string>(), scope, CreateItem <VariablePrompt>()) }; var project1 = new Project(CreateItemWithRename <ElementIdentifier>(false), CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <bool>(), deploymentProcess, variables, new[] { new ElementReference(libraryVariableSet.Identifier.Name) }, new ElementReference(lifecycle.Identifier.Name), new ElementReference(projectGroup.Identifier.Name), CreateItem <VersioningStrategy>(), Enumerable.Empty <ProjectTrigger>(), TenantedDeploymentMode.TenantedOrUntenanted); var project2 = new Project(CreateItemWithRename <ElementIdentifier>(false), CreateItem <string>(), CreateItem <bool>(), CreateItem <bool>(), CreateItem <bool>(), deploymentProcess, variables, new[] { new ElementReference(libraryVariableSet.Identifier.Name) }, new ElementReference(lifecycle.Identifier.Name), new ElementReference(projectGroup.Identifier.Name), null, new[] { CreateProjectTrigger("m1", "env1"), CreateProjectTrigger("m2", "env2") }, TenantedDeploymentMode.TenantedOrUntenanted); var expected = new SystemModelBuilder() .AddProject(project1) .AddProject(project2) .AddProjectGroup(projectGroup) .AddLifecycle(lifecycle) .AddLibraryVariableSet(libraryVariableSet) .AddEnvironment(environment1) .AddEnvironment(environment2) .Build(); _repository.Machines.Create(new MachineResource { Name = "m1" }); _repository.Machines.Create(new MachineResource { Name = "m2" }); //_repository.FakeMachineRoles.Add("r1"); //_repository.FakeMachineRoles.Add("r2"); _repository.Channels.Create(new ChannelResource { Name = "ch1" }); _repository.Channels.Create(new ChannelResource { Name = "ch2" }); _uploader.UploadModel(expected).GetAwaiter(); var actual = _downloader.DownloadModel().GetAwaiter().GetResult(); actual.AssertDeepEqualsTo(expected); }