示例#1
0
        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();
        }
示例#4
0
        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"));
        }
示例#5
0
        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();
        }
示例#7
0
        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>()));
        }
示例#8
0
        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>()));
        }
示例#9
0
        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>()));
        }
示例#10
0
        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));
                }
            }
        }
示例#11
0
        public async void TestGet()
        {
            ApiBusinessEntityResponseModel response = await this.Client.BusinessEntityGetAsync(1);

            response.Should().NotBeNull();
        }