public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiMachinePolicyRequestModel model) { this.IsDefaultRules(); this.JSONRules(); this.NameRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiMachinePolicyResponseModel> CreateRecord() { var model = new ApiMachinePolicyRequestModel(); model.SetProperties(true, "B", "B"); CreateResponse <ApiMachinePolicyResponseModel> result = await this.Client.MachinePolicyCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLMachinePolicyMapper(); ApiMachinePolicyRequestModel model = new ApiMachinePolicyRequestModel(); model.SetProperties(true, "A", "A"); BOMachinePolicy response = mapper.MapModelToBO("A", model); response.IsDefault.Should().Be(true); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); }
public void MapResponseToRequest() { var mapper = new ApiMachinePolicyModelMapper(); var model = new ApiMachinePolicyResponseModel(); model.SetProperties("A", true, "A", "A"); ApiMachinePolicyRequestModel response = mapper.MapResponseToRequest(model); response.IsDefault.Should().Be(true); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); }
public virtual async Task <IActionResult> Create([FromBody] ApiMachinePolicyRequestModel model) { CreateResponse <ApiMachinePolicyResponseModel> result = await this.MachinePolicyService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/MachinePolicies/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BOMachinePolicy MapModelToBO( string id, ApiMachinePolicyRequestModel model ) { BOMachinePolicy boMachinePolicy = new BOMachinePolicy(); boMachinePolicy.SetProperties( id, model.IsDefault, model.JSON, model.Name); return(boMachinePolicy); }
public virtual async Task <CreateResponse <ApiMachinePolicyResponseModel> > Create( ApiMachinePolicyRequestModel model) { CreateResponse <ApiMachinePolicyResponseModel> response = new CreateResponse <ApiMachinePolicyResponseModel>(await this.machinePolicyModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolMachinePolicyMapper.MapModelToBO(default(string), model); var record = await this.machinePolicyRepository.Create(this.dalMachinePolicyMapper.MapBOToEF(bo)); response.SetRecord(this.bolMachinePolicyMapper.MapBOToModel(this.dalMachinePolicyMapper.MapEFToBO(record))); } return(response); }
public void CreatePatch() { var mapper = new ApiMachinePolicyModelMapper(); var model = new ApiMachinePolicyRequestModel(); model.SetProperties(true, "A", "A"); JsonPatchDocument <ApiMachinePolicyRequestModel> patch = mapper.CreatePatch(model); var response = new ApiMachinePolicyRequestModel(); patch.ApplyTo(response); response.IsDefault.Should().Be(true); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); }
private async Task <ApiMachinePolicyRequestModel> PatchModel(string id, JsonPatchDocument <ApiMachinePolicyRequestModel> patch) { var record = await this.MachinePolicyService.Get(id); if (record == null) { return(null); } else { ApiMachinePolicyRequestModel request = this.MachinePolicyModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Create() { var mock = new ServiceMockFacade <IMachinePolicyRepository>(); var model = new ApiMachinePolicyRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <MachinePolicy>())).Returns(Task.FromResult(new MachinePolicy())); var service = new MachinePolicyService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.MachinePolicyModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLMachinePolicyMapperMock, mock.DALMapperMockFactory.DALMachinePolicyMapperMock); CreateResponse <ApiMachinePolicyResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.MachinePolicyModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiMachinePolicyRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <MachinePolicy>())); }
public async void Delete() { var mock = new ServiceMockFacade <IMachinePolicyRepository>(); var model = new ApiMachinePolicyRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask); var service = new MachinePolicyService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.MachinePolicyModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLMachinePolicyMapperMock, mock.DALMapperMockFactory.DALMachinePolicyMapperMock); ActionResponse response = await service.Delete(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>())); mock.ModelValidatorMockFactory.MachinePolicyModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>())); }
public virtual async Task <UpdateResponse <ApiMachinePolicyResponseModel> > Update( string id, ApiMachinePolicyRequestModel model) { var validationResult = await this.machinePolicyModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolMachinePolicyMapper.MapModelToBO(id, model); await this.machinePolicyRepository.Update(this.dalMachinePolicyMapper.MapBOToEF(bo)); var record = await this.machinePolicyRepository.Get(id); return(new UpdateResponse <ApiMachinePolicyResponseModel>(this.bolMachinePolicyMapper.MapBOToModel(this.dalMachinePolicyMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiMachinePolicyResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(string id, [FromBody] ApiMachinePolicyRequestModel model) { ApiMachinePolicyRequestModel request = await this.PatchModel(id, this.MachinePolicyModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiMachinePolicyResponseModel> result = await this.MachinePolicyService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiMachinePolicyRequestModel> patch) { ApiMachinePolicyResponseModel record = await this.MachinePolicyService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiMachinePolicyRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiMachinePolicyResponseModel> result = await this.MachinePolicyService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }