public virtual ApiPostLinksResponseModel MapBOToModel( BOPostLinks boPostLinks) { var model = new ApiPostLinksResponseModel(); model.SetProperties(boPostLinks.Id, boPostLinks.CreationDate, boPostLinks.LinkTypeId, boPostLinks.PostId, boPostLinks.RelatedPostId); return(model); }
public async virtual Task <IActionResult> Get(int id) { ApiPostLinksResponseModel response = await this.PostLinksService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public void MapResponseToRequest() { var mapper = new ApiPostLinksModelMapper(); var model = new ApiPostLinksResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); ApiPostLinksRequestModel response = mapper.MapResponseToRequest(model); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.LinkTypeId.Should().Be(1); response.PostId.Should().Be(1); response.RelatedPostId.Should().Be(1); }
public void MapBOToModel() { var mapper = new BOLPostLinksMapper(); BOPostLinks bo = new BOPostLinks(); bo.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); ApiPostLinksResponseModel response = mapper.MapBOToModel(bo); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Id.Should().Be(1); response.LinkTypeId.Should().Be(1); response.PostId.Should().Be(1); response.RelatedPostId.Should().Be(1); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IPostLinksRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <PostLinks>(null)); var service = new PostLinksService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PostLinksModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPostLinksMapperMock, mock.DALMapperMockFactory.DALPostLinksMapperMock); ApiPostLinksResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create_Errors() { PostLinksControllerMockFacade mock = new PostLinksControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiPostLinksResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiPostLinksResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiPostLinksRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiPostLinksResponseModel> >(mockResponse.Object)); PostLinksController controller = new PostLinksController(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 ApiPostLinksRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiPostLinksRequestModel>())); }
public async void All_Exists() { PostLinksControllerMockFacade mock = new PostLinksControllerMockFacade(); var record = new ApiPostLinksResponseModel(); var records = new List <ApiPostLinksResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); PostLinksController controller = new PostLinksController(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 <ApiPostLinksResponseModel>; 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 <ApiPostLinksRequestModel> patch) { ApiPostLinksResponseModel record = await this.PostLinksService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiPostLinksRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiPostLinksResponseModel> result = await this.PostLinksService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiPostLinksResponseModel response = await this.Client.PostLinksGetAsync(1); response.Should().NotBeNull(); }