public virtual ApiBusinessEntityResponseModel MapBOToModel( BOBusinessEntity boBusinessEntity) { var model = new ApiBusinessEntityResponseModel(); model.SetProperties(boBusinessEntity.BusinessEntityID, boBusinessEntity.ModifiedDate, boBusinessEntity.Rowguid); return(model); }
public void MapResponseToRequest() { var mapper = new ApiBusinessEntityModelMapper(); var model = new ApiBusinessEntityResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); ApiBusinessEntityRequestModel response = mapper.MapResponseToRequest(model); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
public async void TestGet() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiBusinessEntityResponseModel response = await client.BusinessEntityGetAsync(1); response.Should().NotBeNull(); }
public void MapBOToModel() { var mapper = new BOLBusinessEntityMapper(); BOBusinessEntity bo = new BOBusinessEntity(); bo.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); ApiBusinessEntityResponseModel response = mapper.MapBOToModel(bo); response.BusinessEntityID.Should().Be(1); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
public async virtual Task <IActionResult> Get(int id) { ApiBusinessEntityResponseModel response = await this.BusinessEntityService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiBusinessEntityResponseModel model = await client.BusinessEntityGetAsync(1); ApiBusinessEntityModelMapper mapper = new ApiBusinessEntityModelMapper(); UpdateResponse <ApiBusinessEntityResponseModel> updateResponse = await client.BusinessEntityUpdateAsync(model.BusinessEntityID, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { BusinessEntityControllerMockFacade mock = new BusinessEntityControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiBusinessEntityResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiBusinessEntityResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiBusinessEntityRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiBusinessEntityResponseModel> >(mockResponse.Object)); BusinessEntityController controller = new BusinessEntityController(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 ApiBusinessEntityRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiBusinessEntityRequestModel>())); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IBusinessEntityRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <BusinessEntity>(null)); var service = new BusinessEntityService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BusinessEntityModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBusinessEntityMapperMock, mock.DALMapperMockFactory.DALBusinessEntityMapperMock, mock.BOLMapperMockFactory.BOLBusinessEntityAddressMapperMock, mock.DALMapperMockFactory.DALBusinessEntityAddressMapperMock, mock.BOLMapperMockFactory.BOLBusinessEntityContactMapperMock, mock.DALMapperMockFactory.DALBusinessEntityContactMapperMock, mock.BOLMapperMockFactory.BOLPersonMapperMock, mock.DALMapperMockFactory.DALPersonMapperMock); ApiBusinessEntityResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void All_Exists() { BusinessEntityControllerMockFacade mock = new BusinessEntityControllerMockFacade(); var record = new ApiBusinessEntityResponseModel(); var records = new List <ApiBusinessEntityResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); BusinessEntityController controller = new BusinessEntityController(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 <ApiBusinessEntityResponseModel>; 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 <ApiBusinessEntityRequestModel> patch) { ApiBusinessEntityResponseModel record = await this.BusinessEntityService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiBusinessEntityRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiBusinessEntityResponseModel> result = await this.BusinessEntityService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiBusinessEntityResponseModel response = await this.Client.BusinessEntityGetAsync(1); response.Should().NotBeNull(); }