private async Task <ApiProductReviewResponseModel> CreateRecord(ApiClient client) { var model = new ApiProductReviewRequestModel(); model.SetProperties("B", "B", DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, DateTime.Parse("1/1/1988 12:00:00 AM"), "B"); CreateResponse <ApiProductReviewResponseModel> result = await client.ProductReviewCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiProductReviewRequestModel model) { this.CommentRules(); this.EmailAddressRules(); this.ModifiedDateRules(); this.ProductIDRules(); this.RatingRules(); this.ReviewDateRules(); this.ReviewerNameRules(); return(await this.ValidateAsync(model, id)); }
public virtual async Task <IActionResult> Create([FromBody] ApiProductReviewRequestModel model) { CreateResponse <ApiProductReviewResponseModel> result = await this.ProductReviewService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ProductReviews/{result.Record.ProductReviewID}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
private async Task <ApiProductReviewRequestModel> PatchModel(int id, JsonPatchDocument <ApiProductReviewRequestModel> patch) { var record = await this.ProductReviewService.Get(id); if (record == null) { return(null); } else { ApiProductReviewRequestModel request = this.ProductReviewModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiProductReviewResponseModel> > Create( ApiProductReviewRequestModel model) { CreateResponse <ApiProductReviewResponseModel> response = new CreateResponse <ApiProductReviewResponseModel>(await this.ProductReviewModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolProductReviewMapper.MapModelToBO(default(int), model); var record = await this.ProductReviewRepository.Create(this.DalProductReviewMapper.MapBOToEF(bo)); response.SetRecord(this.BolProductReviewMapper.MapBOToModel(this.DalProductReviewMapper.MapEFToBO(record))); } return(response); }
public void MapModelToBO() { var mapper = new BOLProductReviewMapper(); ApiProductReviewRequestModel model = new ApiProductReviewRequestModel(); model.SetProperties("A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); BOProductReview response = mapper.MapModelToBO(1, model); response.Comment.Should().Be("A"); response.EmailAddress.Should().Be("A"); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ProductID.Should().Be(1); response.Rating.Should().Be(1); response.ReviewDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ReviewerName.Should().Be("A"); }
public async void Create() { var mock = new ServiceMockFacade <IProductReviewRepository>(); var model = new ApiProductReviewRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ProductReview>())).Returns(Task.FromResult(new ProductReview())); var service = new ProductReviewService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ProductReviewModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLProductReviewMapperMock, mock.DALMapperMockFactory.DALProductReviewMapperMock); CreateResponse <ApiProductReviewResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ProductReviewModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiProductReviewRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ProductReview>())); }
public async void Delete() { var mock = new ServiceMockFacade <IProductReviewRepository>(); var model = new ApiProductReviewRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new ProductReviewService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ProductReviewModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLProductReviewMapperMock, mock.DALMapperMockFactory.DALProductReviewMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.ProductReviewModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual BOProductReview MapModelToBO( int productReviewID, ApiProductReviewRequestModel model ) { BOProductReview boProductReview = new BOProductReview(); boProductReview.SetProperties( productReviewID, model.Comment, model.EmailAddress, model.ModifiedDate, model.ProductID, model.Rating, model.ReviewDate, model.ReviewerName); return(boProductReview); }
public void CreatePatch() { var mapper = new ApiProductReviewModelMapper(); var model = new ApiProductReviewRequestModel(); model.SetProperties("A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); JsonPatchDocument <ApiProductReviewRequestModel> patch = mapper.CreatePatch(model); var response = new ApiProductReviewRequestModel(); patch.ApplyTo(response); response.Comment.Should().Be("A"); response.EmailAddress.Should().Be("A"); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ProductID.Should().Be(1); response.Rating.Should().Be(1); response.ReviewDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ReviewerName.Should().Be("A"); }
public virtual async Task <UpdateResponse <ApiProductReviewResponseModel> > Update( int productReviewID, ApiProductReviewRequestModel model) { var validationResult = await this.ProductReviewModelValidator.ValidateUpdateAsync(productReviewID, model); if (validationResult.IsValid) { var bo = this.BolProductReviewMapper.MapModelToBO(productReviewID, model); await this.ProductReviewRepository.Update(this.DalProductReviewMapper.MapBOToEF(bo)); var record = await this.ProductReviewRepository.Get(productReviewID); return(new UpdateResponse <ApiProductReviewResponseModel>(this.BolProductReviewMapper.MapBOToModel(this.DalProductReviewMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiProductReviewResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiProductReviewRequestModel model) { ApiProductReviewRequestModel request = await this.PatchModel(id, this.ProductReviewModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiProductReviewResponseModel> result = await this.ProductReviewService.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 <ApiProductReviewRequestModel> patch) { ApiProductReviewResponseModel record = await this.ProductReviewService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiProductReviewRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiProductReviewResponseModel> result = await this.ProductReviewService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }