public virtual ApiProductListPriceHistoryResponseModel MapBOToModel(
            BOProductListPriceHistory boProductListPriceHistory)
        {
            var model = new ApiProductListPriceHistoryResponseModel();

            model.SetProperties(boProductListPriceHistory.ProductID, boProductListPriceHistory.EndDate, boProductListPriceHistory.ListPrice, boProductListPriceHistory.ModifiedDate, boProductListPriceHistory.StartDate);

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

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

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

            response.EndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ListPrice.Should().Be(1m);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.StartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
        }
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiProductListPriceHistoryResponseModel response = await this.ProductListPriceHistoryService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Exemplo n.º 5
0
        public void MapBOToModel()
        {
            var mapper = new BOLProductListPriceHistoryMapper();
            BOProductListPriceHistory bo = new BOProductListPriceHistory();

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

            response.EndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ListPrice.Should().Be(1m);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ProductID.Should().Be(1);
            response.StartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
        }
Exemplo n.º 6
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IProductListPriceHistoryRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ProductListPriceHistory>(null));
            var service = new ProductListPriceHistoryService(mock.LoggerMock.Object,
                                                             mock.RepositoryMock.Object,
                                                             mock.ModelValidatorMockFactory.ProductListPriceHistoryModelValidatorMock.Object,
                                                             mock.BOLMapperMockFactory.BOLProductListPriceHistoryMapperMock,
                                                             mock.DALMapperMockFactory.DALProductListPriceHistoryMapperMock);

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

            ApiProductListPriceHistoryResponseModel model = await client.ProductListPriceHistoryGetAsync(1);

            ApiProductListPriceHistoryModelMapper mapper = new ApiProductListPriceHistoryModelMapper();

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

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

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

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

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

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

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

            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 <ApiProductListPriceHistoryRequestModel> patch)
        {
            ApiProductListPriceHistoryResponseModel record = await this.ProductListPriceHistoryService.Get(id);

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

                UpdateResponse <ApiProductListPriceHistoryResponseModel> result = await this.ProductListPriceHistoryService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Exemplo n.º 11
0
        public async void TestGet()
        {
            ApiProductListPriceHistoryResponseModel response = await this.Client.ProductListPriceHistoryGetAsync(1);

            response.Should().NotBeNull();
        }