Beispiel #1
0
        public virtual ApiWorkOrderResponseModel MapBOToModel(
            BOWorkOrder boWorkOrder)
        {
            var model = new ApiWorkOrderResponseModel();

            model.SetProperties(boWorkOrder.WorkOrderID, boWorkOrder.DueDate, boWorkOrder.EndDate, boWorkOrder.ModifiedDate, boWorkOrder.OrderQty, boWorkOrder.ProductID, boWorkOrder.ScrappedQty, boWorkOrder.ScrapReasonID, boWorkOrder.StartDate, boWorkOrder.StockedQty);

            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());
            ApiWorkOrderResponseModel response = await client.WorkOrderGetAsync(1);

            response.Should().NotBeNull();
        }
Beispiel #3
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiWorkOrderResponseModel response = await this.WorkOrderService.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());

            ApiWorkOrderResponseModel model = await client.WorkOrderGetAsync(1);

            ApiWorkOrderModelMapper mapper = new ApiWorkOrderModelMapper();

            UpdateResponse <ApiWorkOrderResponseModel> updateResponse = await client.WorkOrderUpdateAsync(model.WorkOrderID, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IWorkOrderRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <WorkOrder>(null));
            var service = new WorkOrderService(mock.LoggerMock.Object,
                                               mock.RepositoryMock.Object,
                                               mock.ModelValidatorMockFactory.WorkOrderModelValidatorMock.Object,
                                               mock.BOLMapperMockFactory.BOLWorkOrderMapperMock,
                                               mock.DALMapperMockFactory.DALWorkOrderMapperMock,
                                               mock.BOLMapperMockFactory.BOLWorkOrderRoutingMapperMock,
                                               mock.DALMapperMockFactory.DALWorkOrderRoutingMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiWorkOrderModelMapper();
            var model  = new ApiWorkOrderResponseModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1);
            ApiWorkOrderRequestModel response = mapper.MapResponseToRequest(model);

            response.DueDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.EndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.OrderQty.Should().Be(1);
            response.ProductID.Should().Be(1);
            response.ScrappedQty.Should().Be(1);
            response.ScrapReasonID.Should().Be(1);
            response.StartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.StockedQty.Should().Be(1);
        }
        public void MapBOToModel()
        {
            var         mapper = new BOLWorkOrderMapper();
            BOWorkOrder bo     = new BOWorkOrder();

            bo.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1);
            ApiWorkOrderResponseModel response = mapper.MapBOToModel(bo);

            response.DueDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.EndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.OrderQty.Should().Be(1);
            response.ProductID.Should().Be(1);
            response.ScrappedQty.Should().Be(1);
            response.ScrapReasonID.Should().Be(1);
            response.StartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.StockedQty.Should().Be(1);
            response.WorkOrderID.Should().Be(1);
        }
Beispiel #8
0
        public async void Create_Errors()
        {
            WorkOrderControllerMockFacade mock = new WorkOrderControllerMockFacade();

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

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiWorkOrderRequestModel>()));
        }
Beispiel #9
0
        public async void All_Exists()
        {
            WorkOrderControllerMockFacade mock = new WorkOrderControllerMockFacade();
            var record  = new ApiWorkOrderResponseModel();
            var records = new List <ApiWorkOrderResponseModel>();

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Beispiel #10
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiWorkOrderRequestModel> patch)
        {
            ApiWorkOrderResponseModel record = await this.WorkOrderService.Get(id);

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

                UpdateResponse <ApiWorkOrderResponseModel> result = await this.WorkOrderService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public async void TestGet()
        {
            ApiWorkOrderResponseModel response = await this.Client.WorkOrderGetAsync(1);

            response.Should().NotBeNull();
        }