Example #1
0
        public virtual ApiScrapReasonResponseModel MapBOToModel(
            BOScrapReason boScrapReason)
        {
            var model = new ApiScrapReasonResponseModel();

            model.SetProperties(boScrapReason.ScrapReasonID, boScrapReason.ModifiedDate, boScrapReason.Name);

            return(model);
        }
Example #2
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiScrapReasonModelMapper();
            var model  = new ApiScrapReasonResponseModel();

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

            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
        }
Example #3
0
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiScrapReasonResponseModel response = await client.ScrapReasonGetAsync(1);

            response.Should().NotBeNull();
        }
Example #4
0
        public void MapBOToModel()
        {
            var           mapper = new BOLScrapReasonMapper();
            BOScrapReason bo     = new BOScrapReason();

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

            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.ScrapReasonID.Should().Be(1);
        }
Example #5
0
        public async virtual Task <IActionResult> Get(short id)
        {
            ApiScrapReasonResponseModel response = await this.ScrapReasonService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Example #6
0
        public async virtual Task <IActionResult> ByName(string name)
        {
            ApiScrapReasonResponseModel response = await this.ScrapReasonService.ByName(name);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Example #7
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IScrapReasonRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <short>())).Returns(Task.FromResult <ScrapReason>(null));
            var service = new ScrapReasonService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.ScrapReasonModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLScrapReasonMapperMock,
                                                 mock.DALMapperMockFactory.DALScrapReasonMapperMock,
                                                 mock.BOLMapperMockFactory.BOLWorkOrderMapperMock,
                                                 mock.DALMapperMockFactory.DALWorkOrderMapperMock);

            ApiScrapReasonResponseModel response = await service.Get(default(short));

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

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

            ApiScrapReasonResponseModel model = await client.ScrapReasonGetAsync(1);

            ApiScrapReasonModelMapper mapper = new ApiScrapReasonModelMapper();

            UpdateResponse <ApiScrapReasonResponseModel> updateResponse = await client.ScrapReasonUpdateAsync(model.ScrapReasonID, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
Example #9
0
        public async void ByName_Exists()
        {
            var mock   = new ServiceMockFacade <IScrapReasonRepository>();
            var record = new ScrapReason();

            mock.RepositoryMock.Setup(x => x.ByName(It.IsAny <string>())).Returns(Task.FromResult(record));
            var service = new ScrapReasonService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.ScrapReasonModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLScrapReasonMapperMock,
                                                 mock.DALMapperMockFactory.DALScrapReasonMapperMock,
                                                 mock.BOLMapperMockFactory.BOLWorkOrderMapperMock,
                                                 mock.DALMapperMockFactory.DALWorkOrderMapperMock);

            ApiScrapReasonResponseModel response = await service.ByName(default(string));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.ByName(It.IsAny <string>()));
        }
        public async void Create_Errors()
        {
            ScrapReasonControllerMockFacade mock = new ScrapReasonControllerMockFacade();

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

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

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

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

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Example #12
0
        public virtual async Task <IActionResult> Patch(short id, [FromBody] JsonPatchDocument <ApiScrapReasonRequestModel> patch)
        {
            ApiScrapReasonResponseModel record = await this.ScrapReasonService.Get(id);

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

                UpdateResponse <ApiScrapReasonResponseModel> result = await this.ScrapReasonService.Update(id, model);

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

            response.Should().NotBeNull();
        }