public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiVariableSetRequestModel model) { this.IsFrozenRules(); this.JSONRules(); this.OwnerIdRules(); this.RelatedDocumentIdsRules(); this.VersionRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiVariableSetResponseModel> CreateRecord() { var model = new ApiVariableSetRequestModel(); model.SetProperties(true, "B", "B", "B", 2); CreateResponse <ApiVariableSetResponseModel> result = await this.Client.VariableSetCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiVariableSetRequestModel model) { CreateResponse <ApiVariableSetResponseModel> result = await this.VariableSetService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/VariableSets/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapModelToBO() { var mapper = new BOLVariableSetMapper(); ApiVariableSetRequestModel model = new ApiVariableSetRequestModel(); model.SetProperties(true, "A", "A", "A", 1); BOVariableSet response = mapper.MapModelToBO("A", model); response.IsFrozen.Should().Be(true); response.JSON.Should().Be("A"); response.OwnerId.Should().Be("A"); response.RelatedDocumentIds.Should().Be("A"); response.Version.Should().Be(1); }
public void MapResponseToRequest() { var mapper = new ApiVariableSetModelMapper(); var model = new ApiVariableSetResponseModel(); model.SetProperties("A", true, "A", "A", "A", 1); ApiVariableSetRequestModel response = mapper.MapResponseToRequest(model); response.IsFrozen.Should().Be(true); response.JSON.Should().Be("A"); response.OwnerId.Should().Be("A"); response.RelatedDocumentIds.Should().Be("A"); response.Version.Should().Be(1); }
private async Task <ApiVariableSetRequestModel> PatchModel(string id, JsonPatchDocument <ApiVariableSetRequestModel> patch) { var record = await this.VariableSetService.Get(id); if (record == null) { return(null); } else { ApiVariableSetRequestModel request = this.VariableSetModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiVariableSetResponseModel> > Create( ApiVariableSetRequestModel model) { CreateResponse <ApiVariableSetResponseModel> response = new CreateResponse <ApiVariableSetResponseModel>(await this.variableSetModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolVariableSetMapper.MapModelToBO(default(string), model); var record = await this.variableSetRepository.Create(this.dalVariableSetMapper.MapBOToEF(bo)); response.SetRecord(this.bolVariableSetMapper.MapBOToModel(this.dalVariableSetMapper.MapEFToBO(record))); } return(response); }
public virtual BOVariableSet MapModelToBO( string id, ApiVariableSetRequestModel model ) { BOVariableSet boVariableSet = new BOVariableSet(); boVariableSet.SetProperties( id, model.IsFrozen, model.JSON, model.OwnerId, model.RelatedDocumentIds, model.Version); return(boVariableSet); }
public void CreatePatch() { var mapper = new ApiVariableSetModelMapper(); var model = new ApiVariableSetRequestModel(); model.SetProperties(true, "A", "A", "A", 1); JsonPatchDocument <ApiVariableSetRequestModel> patch = mapper.CreatePatch(model); var response = new ApiVariableSetRequestModel(); patch.ApplyTo(response); response.IsFrozen.Should().Be(true); response.JSON.Should().Be("A"); response.OwnerId.Should().Be("A"); response.RelatedDocumentIds.Should().Be("A"); response.Version.Should().Be(1); }
public async void Create() { var mock = new ServiceMockFacade <IVariableSetRepository>(); var model = new ApiVariableSetRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <VariableSet>())).Returns(Task.FromResult(new VariableSet())); var service = new VariableSetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.VariableSetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLVariableSetMapperMock, mock.DALMapperMockFactory.DALVariableSetMapperMock); CreateResponse <ApiVariableSetResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.VariableSetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVariableSetRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <VariableSet>())); }
public async void Delete() { var mock = new ServiceMockFacade <IVariableSetRepository>(); var model = new ApiVariableSetRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask); var service = new VariableSetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.VariableSetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLVariableSetMapperMock, mock.DALMapperMockFactory.DALVariableSetMapperMock); ActionResponse response = await service.Delete(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>())); mock.ModelValidatorMockFactory.VariableSetModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>())); }
public virtual async Task <UpdateResponse <ApiVariableSetResponseModel> > Update( string id, ApiVariableSetRequestModel model) { var validationResult = await this.variableSetModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolVariableSetMapper.MapModelToBO(id, model); await this.variableSetRepository.Update(this.dalVariableSetMapper.MapBOToEF(bo)); var record = await this.variableSetRepository.Get(id); return(new UpdateResponse <ApiVariableSetResponseModel>(this.bolVariableSetMapper.MapBOToModel(this.dalVariableSetMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiVariableSetResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(string id, [FromBody] ApiVariableSetRequestModel model) { ApiVariableSetRequestModel request = await this.PatchModel(id, this.VariableSetModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiVariableSetResponseModel> result = await this.VariableSetService.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 <ApiVariableSetRequestModel> patch) { ApiVariableSetResponseModel record = await this.VariableSetService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiVariableSetRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiVariableSetResponseModel> result = await this.VariableSetService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }