private async Task UploadMachinePolicy(MachinePolicy machinePolicy)
        {
            var resource = await LoadResource(_repository.MachinePolicies, machinePolicy.Identifier);

            resource.UpdateWith(machinePolicy);
            await Upsert(_repository.MachinePolicies, resource);
        }
        public virtual BOMachinePolicy MapEFToBO(
            MachinePolicy ef)
        {
            var bo = new BOMachinePolicy();

            bo.SetProperties(
                ef.Id,
                ef.IsDefault,
                ef.JSON,
                ef.Name);
            return(bo);
        }
        public virtual MachinePolicy MapBOToEF(
            BOMachinePolicy bo)
        {
            MachinePolicy efMachinePolicy = new MachinePolicy();

            efMachinePolicy.SetProperties(
                bo.Id,
                bo.IsDefault,
                bo.JSON,
                bo.Name);
            return(efMachinePolicy);
        }
示例#4
0
        public async Task <ApiMachinePolicyResponseModel> ByName(string name)
        {
            MachinePolicy record = await this.machinePolicyRepository.ByName(name);

            if (record == null)
            {
                return(null);
            }
            else
            {
                return(this.bolMachinePolicyMapper.MapBOToModel(this.dalMachinePolicyMapper.MapEFToBO(record)));
            }
        }
示例#5
0
        private async Task <bool> BeUniqueByName(ApiMachinePolicyRequestModel model, CancellationToken cancellationToken)
        {
            MachinePolicy record = await this.machinePolicyRepository.ByName(model.Name);

            if (record == null || (this.existingRecordId != default(string) && record.Id == this.existingRecordId))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#6
0
 public static YamlMachinePolicy FromModel(MachinePolicy model)
 {
     return(new YamlMachinePolicy
            (
                model.Identifier.Name,
                model.Identifier.RenamedFrom,
                model.Description,
                YamlMachineHealthCheckPolicy.FromModel(model.HealthCheckPolicy),
                YamlMachineConnectivityPolicy.FromModel(model.ConnectivityPolicy),
                YamlMachineUpdatePolicy.FromModel(model.UpdatePolicy),
                YamlMachineCleanupPolicy.FromModel(model.CleanupPolicy)
            ));
 }
        public void MapEFToBOList()
        {
            var           mapper = new DALMachinePolicyMapper();
            MachinePolicy entity = new MachinePolicy();

            entity.SetProperties("A", true, "A", "A");

            List <BOMachinePolicy> response = mapper.MapEFToBO(new List <MachinePolicy>()
            {
                entity
            });

            response.Count.Should().Be(1);
        }
        public void MapEFToBO()
        {
            var           mapper = new DALMachinePolicyMapper();
            MachinePolicy entity = new MachinePolicy();

            entity.SetProperties("A", true, "A", "A");

            BOMachinePolicy response = mapper.MapEFToBO(entity);

            response.Id.Should().Be("A");
            response.IsDefault.Should().Be(true);
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
        public void MapBOToEF()
        {
            var mapper = new DALMachinePolicyMapper();
            var bo     = new BOMachinePolicy();

            bo.SetProperties("A", true, "A", "A");

            MachinePolicy response = mapper.MapBOToEF(bo);

            response.Id.Should().Be("A");
            response.IsDefault.Should().Be(true);
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
        }
示例#10
0
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IMachinePolicyRepository>();
            var record = new MachinePolicy();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult(record));
            var service = new MachinePolicyService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.MachinePolicyModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLMachinePolicyMapperMock,
                                                   mock.DALMapperMockFactory.DALMachinePolicyMapperMock);

            ApiMachinePolicyResponseModel response = await service.Get(default(string));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>()));
        }
示例#11
0
        private void UploadMachinePolicy(MachinePolicy machinePolicy)
        {
            var resource = LoadResource(_repository.MachinePolicies, machinePolicy.Identifier).UpdateWith(machinePolicy);

            Upsert(_repository.MachinePolicies, resource);
        }
 public static MachinePolicyResource UpdateWith(this MachinePolicyResource resource, MachinePolicy model)
 {
     resource.Name        = model.Identifier.Name;
     resource.Description = model.Description;
     resource.MachineHealthCheckPolicy.UpdateWith(model.HealthCheckPolicy);
     resource.MachineConnectivityPolicy.UpdateWith(model.ConnectivityPolicy);
     resource.MachineUpdatePolicy.UpdateWith(model.UpdatePolicy);
     resource.MachineCleanupPolicy.UpdateWith(model.CleanupPolicy);
     return(resource);
 }