public virtual ApiProductDescriptionResponseModel MapBOToModel(
            BOProductDescription boProductDescription)
        {
            var model = new ApiProductDescriptionResponseModel();

            model.SetProperties(boProductDescription.ProductDescriptionID, boProductDescription.Description, boProductDescription.ModifiedDate, boProductDescription.Rowguid);

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

            response.Should().NotBeNull();
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiProductDescriptionModelMapper();
            var model  = new ApiProductDescriptionResponseModel();

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

            response.Description.Should().Be("A");
            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 void MapBOToModel()
        {
            var mapper = new BOLProductDescriptionMapper();
            BOProductDescription bo = new BOProductDescription();

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

            response.Description.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ProductDescriptionID.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiProductDescriptionResponseModel response = await this.ProductDescriptionService.Get(id);

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

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ProductDescription>(null));
            var service = new ProductDescriptionService(mock.LoggerMock.Object,
                                                        mock.RepositoryMock.Object,
                                                        mock.ModelValidatorMockFactory.ProductDescriptionModelValidatorMock.Object,
                                                        mock.BOLMapperMockFactory.BOLProductDescriptionMapperMock,
                                                        mock.DALMapperMockFactory.DALProductDescriptionMapperMock,
                                                        mock.BOLMapperMockFactory.BOLProductModelProductDescriptionCultureMapperMock,
                                                        mock.DALMapperMockFactory.DALProductModelProductDescriptionCultureMapperMock);

            ApiProductDescriptionResponseModel 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());

            ApiProductDescriptionResponseModel model = await client.ProductDescriptionGetAsync(1);

            ApiProductDescriptionModelMapper mapper = new ApiProductDescriptionModelMapper();

            UpdateResponse <ApiProductDescriptionResponseModel> updateResponse = await client.ProductDescriptionUpdateAsync(model.ProductDescriptionID, mapper.MapResponseToRequest(model));

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

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

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

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

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

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

            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 <ApiProductDescriptionRequestModel> patch)
        {
            ApiProductDescriptionResponseModel record = await this.ProductDescriptionService.Get(id);

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

                UpdateResponse <ApiProductDescriptionResponseModel> result = await this.ProductDescriptionService.Update(id, model);

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

            response.Should().NotBeNull();
        }