public virtual ApiClaspResponseModel MapBOToModel( BOClasp boClasp) { var model = new ApiClaspResponseModel(); model.SetProperties(boClasp.Id, boClasp.NextChainId, boClasp.PreviousChainId); return(model); }
public void MapResponseToRequest() { var mapper = new ApiClaspModelMapper(); var model = new ApiClaspResponseModel(); model.SetProperties(1, 1, 1); ApiClaspRequestModel response = mapper.MapResponseToRequest(model); response.NextChainId.Should().Be(1); response.PreviousChainId.Should().Be(1); }
public void MapBOToModel() { var mapper = new BOLClaspMapper(); BOClasp bo = new BOClasp(); bo.SetProperties(1, 1, 1); ApiClaspResponseModel response = mapper.MapBOToModel(bo); response.Id.Should().Be(1); response.NextChainId.Should().Be(1); response.PreviousChainId.Should().Be(1); }
public async virtual Task <IActionResult> Get(int id) { ApiClaspResponseModel response = await this.ClaspService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_null_record() { var mock = new ServiceMockFacade <IClaspRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Clasp>(null)); var service = new ClaspService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ClaspModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLClaspMapperMock, mock.DALMapperMockFactory.DALClaspMapperMock); ApiClaspResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create_Errors() { ClaspControllerMockFacade mock = new ClaspControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiClaspResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiClaspResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiClaspRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiClaspResponseModel> >(mockResponse.Object)); ClaspController controller = new ClaspController(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 ApiClaspRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiClaspRequestModel>())); }
public async void All_Exists() { ClaspControllerMockFacade mock = new ClaspControllerMockFacade(); var record = new ApiClaspResponseModel(); var records = new List <ApiClaspResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); ClaspController controller = new ClaspController(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 <ApiClaspResponseModel>; 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 <ApiClaspRequestModel> patch) { ApiClaspResponseModel record = await this.ClaspService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiClaspRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiClaspResponseModel> result = await this.ClaspService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiClaspResponseModel response = await this.Client.ClaspGetAsync(1); response.Should().NotBeNull(); }