public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiProductProductPhotoRequestModel model) { this.ModifiedDateRules(); this.PrimaryRules(); this.ProductPhotoIDRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiProductProductPhotoResponseModel> CreateRecord(ApiClient client) { var model = new ApiProductProductPhotoRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), true, 2); CreateResponse <ApiProductProductPhotoResponseModel> result = await client.ProductProductPhotoCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLProductProductPhotoMapper(); ApiProductProductPhotoRequestModel model = new ApiProductProductPhotoRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), true, 1); BOProductProductPhoto response = mapper.MapModelToBO(1, model); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Primary.Should().Be(true); response.ProductPhotoID.Should().Be(1); }
public void MapResponseToRequest() { var mapper = new ApiProductProductPhotoModelMapper(); var model = new ApiProductProductPhotoResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), true, 1); ApiProductProductPhotoRequestModel response = mapper.MapResponseToRequest(model); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Primary.Should().Be(true); response.ProductPhotoID.Should().Be(1); }
public virtual async Task <IActionResult> Create([FromBody] ApiProductProductPhotoRequestModel model) { CreateResponse <ApiProductProductPhotoResponseModel> result = await this.ProductProductPhotoService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ProductProductPhotoes/{result.Record.ProductID}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BOProductProductPhoto MapModelToBO( int productID, ApiProductProductPhotoRequestModel model ) { BOProductProductPhoto boProductProductPhoto = new BOProductProductPhoto(); boProductProductPhoto.SetProperties( productID, model.ModifiedDate, model.Primary, model.ProductPhotoID); return(boProductProductPhoto); }
private async Task <ApiProductProductPhotoRequestModel> PatchModel(int id, JsonPatchDocument <ApiProductProductPhotoRequestModel> patch) { var record = await this.ProductProductPhotoService.Get(id); if (record == null) { return(null); } else { ApiProductProductPhotoRequestModel request = this.ProductProductPhotoModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiProductProductPhotoResponseModel> > Create( ApiProductProductPhotoRequestModel model) { CreateResponse <ApiProductProductPhotoResponseModel> response = new CreateResponse <ApiProductProductPhotoResponseModel>(await this.ProductProductPhotoModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolProductProductPhotoMapper.MapModelToBO(default(int), model); var record = await this.ProductProductPhotoRepository.Create(this.DalProductProductPhotoMapper.MapBOToEF(bo)); response.SetRecord(this.BolProductProductPhotoMapper.MapBOToModel(this.DalProductProductPhotoMapper.MapEFToBO(record))); } return(response); }
public void CreatePatch() { var mapper = new ApiProductProductPhotoModelMapper(); var model = new ApiProductProductPhotoRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), true, 1); JsonPatchDocument <ApiProductProductPhotoRequestModel> patch = mapper.CreatePatch(model); var response = new ApiProductProductPhotoRequestModel(); patch.ApplyTo(response); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Primary.Should().Be(true); response.ProductPhotoID.Should().Be(1); }
public async void Create() { var mock = new ServiceMockFacade <IProductProductPhotoRepository>(); var model = new ApiProductProductPhotoRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ProductProductPhoto>())).Returns(Task.FromResult(new ProductProductPhoto())); var service = new ProductProductPhotoService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ProductProductPhotoModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLProductProductPhotoMapperMock, mock.DALMapperMockFactory.DALProductProductPhotoMapperMock); CreateResponse <ApiProductProductPhotoResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ProductProductPhotoModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiProductProductPhotoRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ProductProductPhoto>())); }
public async void Delete() { var mock = new ServiceMockFacade <IProductProductPhotoRepository>(); var model = new ApiProductProductPhotoRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new ProductProductPhotoService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ProductProductPhotoModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLProductProductPhotoMapperMock, mock.DALMapperMockFactory.DALProductProductPhotoMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.ProductProductPhotoModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiProductProductPhotoResponseModel> > Update( int productID, ApiProductProductPhotoRequestModel model) { var validationResult = await this.ProductProductPhotoModelValidator.ValidateUpdateAsync(productID, model); if (validationResult.IsValid) { var bo = this.BolProductProductPhotoMapper.MapModelToBO(productID, model); await this.ProductProductPhotoRepository.Update(this.DalProductProductPhotoMapper.MapBOToEF(bo)); var record = await this.ProductProductPhotoRepository.Get(productID); return(new UpdateResponse <ApiProductProductPhotoResponseModel>(this.BolProductProductPhotoMapper.MapBOToModel(this.DalProductProductPhotoMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiProductProductPhotoResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiProductProductPhotoRequestModel model) { ApiProductProductPhotoRequestModel request = await this.PatchModel(id, this.ProductProductPhotoModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiProductProductPhotoResponseModel> result = await this.ProductProductPhotoService.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 <ApiProductProductPhotoRequestModel> patch) { ApiProductProductPhotoResponseModel record = await this.ProductProductPhotoService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiProductProductPhotoRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiProductProductPhotoResponseModel> result = await this.ProductProductPhotoService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }