public async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); var createModel = new ApiCommentRequestModel(); createModel.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, "B", 2); CreateResponse <ApiCommentResponseModel> createResult = await client.CommentCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiCommentResponseModel getResponse = await client.CommentGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.CommentDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiCommentResponseModel verifyResponse = await client.CommentGetAsync(2); verifyResponse.Should().BeNull(); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiCommentRequestModel model) { this.CreationDateRules(); this.PostIdRules(); this.ScoreRules(); this.TextRules(); this.UserIdRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiCommentResponseModel> CreateRecord(ApiClient client) { var model = new ApiCommentRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, "B", 2); CreateResponse <ApiCommentResponseModel> result = await client.CommentCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiCommentRequestModel model) { CreateResponse <ApiCommentResponseModel> result = await this.CommentService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Comments/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapModelToBO() { var mapper = new BOLCommentMapper(); ApiCommentRequestModel model = new ApiCommentRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", 1); BOComment response = mapper.MapModelToBO(1, model); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.PostId.Should().Be(1); response.Score.Should().Be(1); response.Text.Should().Be("A"); response.UserId.Should().Be(1); }
public void MapResponseToRequest() { var mapper = new ApiCommentModelMapper(); var model = new ApiCommentResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", 1); ApiCommentRequestModel response = mapper.MapResponseToRequest(model); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.PostId.Should().Be(1); response.Score.Should().Be(1); response.Text.Should().Be("A"); response.UserId.Should().Be(1); }
private async Task <ApiCommentRequestModel> PatchModel(int id, JsonPatchDocument <ApiCommentRequestModel> patch) { var record = await this.CommentService.Get(id); if (record == null) { return(null); } else { ApiCommentRequestModel request = this.CommentModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiCommentResponseModel> > Create( ApiCommentRequestModel model) { CreateResponse <ApiCommentResponseModel> response = new CreateResponse <ApiCommentResponseModel>(await this.CommentModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolCommentMapper.MapModelToBO(default(int), model); var record = await this.CommentRepository.Create(this.DalCommentMapper.MapBOToEF(bo)); response.SetRecord(this.BolCommentMapper.MapBOToModel(this.DalCommentMapper.MapEFToBO(record))); } return(response); }
public virtual BOComment MapModelToBO( int id, ApiCommentRequestModel model ) { BOComment boComment = new BOComment(); boComment.SetProperties( id, model.CreationDate, model.PostId, model.Score, model.Text, model.UserId); return(boComment); }
public void CreatePatch() { var mapper = new ApiCommentModelMapper(); var model = new ApiCommentRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", 1); JsonPatchDocument <ApiCommentRequestModel> patch = mapper.CreatePatch(model); var response = new ApiCommentRequestModel(); patch.ApplyTo(response); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.PostId.Should().Be(1); response.Score.Should().Be(1); response.Text.Should().Be("A"); response.UserId.Should().Be(1); }
public async void Create() { var mock = new ServiceMockFacade <ICommentRepository>(); var model = new ApiCommentRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Comment>())).Returns(Task.FromResult(new Comment())); var service = new CommentService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CommentModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCommentMapperMock, mock.DALMapperMockFactory.DALCommentMapperMock); CreateResponse <ApiCommentResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.CommentModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiCommentRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Comment>())); }
public async void Delete() { var mock = new ServiceMockFacade <ICommentRepository>(); var model = new ApiCommentRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new CommentService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CommentModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCommentMapperMock, mock.DALMapperMockFactory.DALCommentMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.CommentModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiCommentResponseModel> > Update( int id, ApiCommentRequestModel model) { var validationResult = await this.CommentModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolCommentMapper.MapModelToBO(id, model); await this.CommentRepository.Update(this.DalCommentMapper.MapBOToEF(bo)); var record = await this.CommentRepository.Get(id); return(new UpdateResponse <ApiCommentResponseModel>(this.BolCommentMapper.MapBOToModel(this.DalCommentMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiCommentResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiCommentRequestModel model) { ApiCommentRequestModel request = await this.PatchModel(id, this.CommentModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiCommentResponseModel> result = await this.CommentService.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 <ApiCommentRequestModel> patch) { ApiCommentResponseModel record = await this.CommentService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiCommentRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiCommentResponseModel> result = await this.CommentService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiCommentResponseModel> > CommentUpdateAsync(int id, ApiCommentRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Comments/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiCommentResponseModel> >(httpResponse.Content.ContentToString())); }