public virtual ApiCommentsResponseModel MapBOToModel( BOComments boComments) { var model = new ApiCommentsResponseModel(); model.SetProperties(boComments.Id, boComments.CreationDate, boComments.PostId, boComments.Score, boComments.Text, boComments.UserId); return(model); }
public async virtual Task <IActionResult> Get(int id) { ApiCommentsResponseModel response = await this.CommentsService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public void MapResponseToRequest() { var mapper = new ApiCommentsModelMapper(); var model = new ApiCommentsResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", 1); ApiCommentsRequestModel 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); }
public void MapBOToModel() { var mapper = new BOLCommentsMapper(); BOComments bo = new BOComments(); bo.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", 1); ApiCommentsResponseModel response = mapper.MapBOToModel(bo); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Id.Should().Be(1); response.PostId.Should().Be(1); response.Score.Should().Be(1); response.Text.Should().Be("A"); response.UserId.Should().Be(1); }
public async void Get_null_record() { var mock = new ServiceMockFacade <ICommentsRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Comments>(null)); var service = new CommentsService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CommentsModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCommentsMapperMock, mock.DALMapperMockFactory.DALCommentsMapperMock); ApiCommentsResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create_Errors() { CommentsControllerMockFacade mock = new CommentsControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiCommentsResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiCommentsResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCommentsRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCommentsResponseModel> >(mockResponse.Object)); CommentsController controller = new CommentsController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiCommentsRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCommentsRequestModel>())); }
public async void All_Exists() { CommentsControllerMockFacade mock = new CommentsControllerMockFacade(); var record = new ApiCommentsResponseModel(); var records = new List <ApiCommentsResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); CommentsController controller = new CommentsController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiCommentsResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiCommentsRequestModel> patch) { ApiCommentsResponseModel record = await this.CommentsService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiCommentsRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiCommentsResponseModel> result = await this.CommentsService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiCommentsResponseModel response = await this.Client.CommentsGetAsync(1); response.Should().NotBeNull(); }