public void MapModelToBO() { var mapper = new BOLProductCategoryMapper(); ApiProductCategoryRequestModel model = new ApiProductCategoryRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); BOProductCategory response = mapper.MapModelToBO(1, model); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
public virtual async Task <IActionResult> Create([FromBody] ApiProductCategoryRequestModel model) { CreateResponse <ApiProductCategoryResponseModel> result = await this.ProductCategoryService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ProductCategories/{result.Record.ProductCategoryID}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BOProductCategory MapModelToBO( int productCategoryID, ApiProductCategoryRequestModel model ) { BOProductCategory boProductCategory = new BOProductCategory(); boProductCategory.SetProperties( productCategoryID, model.ModifiedDate, model.Name, model.Rowguid); return(boProductCategory); }
public virtual async Task <CreateResponse <ApiProductCategoryResponseModel> > Create( ApiProductCategoryRequestModel model) { CreateResponse <ApiProductCategoryResponseModel> response = new CreateResponse <ApiProductCategoryResponseModel>(await this.ProductCategoryModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolProductCategoryMapper.MapModelToBO(default(int), model); var record = await this.ProductCategoryRepository.Create(this.DalProductCategoryMapper.MapBOToEF(bo)); response.SetRecord(this.BolProductCategoryMapper.MapBOToModel(this.DalProductCategoryMapper.MapEFToBO(record))); } return(response); }
public void CreatePatch() { var mapper = new ApiProductCategoryModelMapper(); var model = new ApiProductCategoryRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); JsonPatchDocument <ApiProductCategoryRequestModel> patch = mapper.CreatePatch(model); var response = new ApiProductCategoryRequestModel(); patch.ApplyTo(response); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
private async Task <ApiProductCategoryRequestModel> PatchModel(int id, JsonPatchDocument <ApiProductCategoryRequestModel> patch) { var record = await this.ProductCategoryService.Get(id); if (record == null) { return(null); } else { ApiProductCategoryRequestModel request = this.ProductCategoryModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <UpdateResponse <ApiProductCategoryResponseModel> > Update( int productCategoryID, ApiProductCategoryRequestModel model) { var validationResult = await this.ProductCategoryModelValidator.ValidateUpdateAsync(productCategoryID, model); if (validationResult.IsValid) { var bo = this.BolProductCategoryMapper.MapModelToBO(productCategoryID, model); await this.ProductCategoryRepository.Update(this.DalProductCategoryMapper.MapBOToEF(bo)); var record = await this.ProductCategoryRepository.Get(productCategoryID); return(new UpdateResponse <ApiProductCategoryResponseModel>(this.BolProductCategoryMapper.MapBOToModel(this.DalProductCategoryMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiProductCategoryResponseModel>(validationResult)); } }
public async void Create() { var mock = new ServiceMockFacade <IProductCategoryRepository>(); var model = new ApiProductCategoryRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ProductCategory>())).Returns(Task.FromResult(new ProductCategory())); var service = new ProductCategoryService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ProductCategoryModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLProductCategoryMapperMock, mock.DALMapperMockFactory.DALProductCategoryMapperMock, mock.BOLMapperMockFactory.BOLProductSubcategoryMapperMock, mock.DALMapperMockFactory.DALProductSubcategoryMapperMock); CreateResponse <ApiProductCategoryResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ProductCategoryModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiProductCategoryRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ProductCategory>())); }
public async void Delete() { var mock = new ServiceMockFacade <IProductCategoryRepository>(); var model = new ApiProductCategoryRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new ProductCategoryService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ProductCategoryModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLProductCategoryMapperMock, mock.DALMapperMockFactory.DALProductCategoryMapperMock, mock.BOLMapperMockFactory.BOLProductSubcategoryMapperMock, mock.DALMapperMockFactory.DALProductSubcategoryMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.ProductCategoryModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiProductCategoryRequestModel model) { ApiProductCategoryRequestModel request = await this.PatchModel(id, this.ProductCategoryModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiProductCategoryResponseModel> result = await this.ProductCategoryService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiProductCategoryRequestModel> patch) { ApiProductCategoryResponseModel record = await this.ProductCategoryService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiProductCategoryRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiProductCategoryResponseModel> result = await this.ProductCategoryService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }