public virtual ApiProductInventoryResponseModel MapBOToModel(
            BOProductInventory boProductInventory)
        {
            var model = new ApiProductInventoryResponseModel();

            model.SetProperties(boProductInventory.ProductID, boProductInventory.Bin, boProductInventory.LocationID, boProductInventory.ModifiedDate, boProductInventory.Quantity, boProductInventory.Rowguid, boProductInventory.Shelf);

            return(model);
        }
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiProductInventoryResponseModel response = await client.ProductInventoryGetAsync(1);

            response.Should().NotBeNull();
        }
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiProductInventoryResponseModel response = await this.ProductInventoryService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiProductInventoryModelMapper();
            var model  = new ApiProductInventoryResponseModel();

            model.SetProperties(1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A");
            ApiProductInventoryRequestModel response = mapper.MapResponseToRequest(model);

            response.Bin.Should().Be(1);
            response.LocationID.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Quantity.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.Shelf.Should().Be("A");
        }
        public void MapBOToModel()
        {
            var mapper            = new BOLProductInventoryMapper();
            BOProductInventory bo = new BOProductInventory();

            bo.SetProperties(1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A");
            ApiProductInventoryResponseModel response = mapper.MapBOToModel(bo);

            response.Bin.Should().Be(1);
            response.LocationID.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ProductID.Should().Be(1);
            response.Quantity.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.Shelf.Should().Be("A");
        }
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IProductInventoryRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ProductInventory>(null));
            var service = new ProductInventoryService(mock.LoggerMock.Object,
                                                      mock.RepositoryMock.Object,
                                                      mock.ModelValidatorMockFactory.ProductInventoryModelValidatorMock.Object,
                                                      mock.BOLMapperMockFactory.BOLProductInventoryMapperMock,
                                                      mock.DALMapperMockFactory.DALProductInventoryMapperMock);

            ApiProductInventoryResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            ApiProductInventoryResponseModel model = await client.ProductInventoryGetAsync(1);

            ApiProductInventoryModelMapper mapper = new ApiProductInventoryModelMapper();

            UpdateResponse <ApiProductInventoryResponseModel> updateResponse = await client.ProductInventoryUpdateAsync(model.ProductID, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
        public async void Create_Errors()
        {
            ProductInventoryControllerMockFacade mock = new ProductInventoryControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiProductInventoryResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiProductInventoryResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiProductInventoryRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiProductInventoryResponseModel> >(mockResponse.Object));
            ProductInventoryController controller = new ProductInventoryController(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 ApiProductInventoryRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiProductInventoryRequestModel>()));
        }
        public async void All_Exists()
        {
            ProductInventoryControllerMockFacade mock = new ProductInventoryControllerMockFacade();
            var record  = new ApiProductInventoryResponseModel();
            var records = new List <ApiProductInventoryResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            ProductInventoryController controller = new ProductInventoryController(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 <ApiProductInventoryResponseModel>;

            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 <ApiProductInventoryRequestModel> patch)
        {
            ApiProductInventoryResponseModel record = await this.ProductInventoryService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiProductInventoryRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiProductInventoryResponseModel> result = await this.ProductInventoryService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Example #11
0
        public async void TestGet()
        {
            ApiProductInventoryResponseModel response = await this.Client.ProductInventoryGetAsync(1);

            response.Should().NotBeNull();
        }