public virtual ApiProductCategoryResponseModel MapBOToModel(
            BOProductCategory boProductCategory)
        {
            var model = new ApiProductCategoryResponseModel();

            model.SetProperties(boProductCategory.ProductCategoryID, boProductCategory.ModifiedDate, boProductCategory.Name, boProductCategory.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());
            ApiProductCategoryResponseModel response = await client.ProductCategoryGetAsync(1);

            response.Should().NotBeNull();
        }
Exemplo n.º 3
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiProductCategoryModelMapper();
            var model  = new ApiProductCategoryResponseModel();

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

            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
Exemplo n.º 4
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiProductCategoryResponseModel response = await this.ProductCategoryService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
        public void MapBOToModel()
        {
            var mapper           = new BOLProductCategoryMapper();
            BOProductCategory bo = new BOProductCategory();

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

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

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ProductCategory>(null));
            var service = new ProductCategoryService(mock.LoggerMock.Object,
                                                     mock.RepositoryMock.Object,
                                                     mock.ModelValidatorMockFactory.ProductCategoryModelValidatorMock.Object,
                                                     mock.BOLMapperMockFactory.BOLProductCategoryMapperMock,
                                                     mock.DALMapperMockFactory.DALProductCategoryMapperMock,
                                                     mock.BOLMapperMockFactory.BOLProductSubcategoryMapperMock,
                                                     mock.DALMapperMockFactory.DALProductSubcategoryMapperMock);

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

            ApiProductCategoryResponseModel model = await client.ProductCategoryGetAsync(1);

            ApiProductCategoryModelMapper mapper = new ApiProductCategoryModelMapper();

            UpdateResponse <ApiProductCategoryResponseModel> updateResponse = await client.ProductCategoryUpdateAsync(model.ProductCategoryID, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
        public async void ByName_Exists()
        {
            var mock   = new ServiceMockFacade <IProductCategoryRepository>();
            var record = new ProductCategory();

            mock.RepositoryMock.Setup(x => x.ByName(It.IsAny <string>())).Returns(Task.FromResult(record));
            var service = new ProductCategoryService(mock.LoggerMock.Object,
                                                     mock.RepositoryMock.Object,
                                                     mock.ModelValidatorMockFactory.ProductCategoryModelValidatorMock.Object,
                                                     mock.BOLMapperMockFactory.BOLProductCategoryMapperMock,
                                                     mock.DALMapperMockFactory.DALProductCategoryMapperMock,
                                                     mock.BOLMapperMockFactory.BOLProductSubcategoryMapperMock,
                                                     mock.DALMapperMockFactory.DALProductSubcategoryMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.ByName(It.IsAny <string>()));
        }
Exemplo n.º 9
0
        public async void Create_Errors()
        {
            ProductCategoryControllerMockFacade mock = new ProductCategoryControllerMockFacade();

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

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiProductCategoryRequestModel>()));
        }
Exemplo n.º 10
0
        public async void All_Exists()
        {
            ProductCategoryControllerMockFacade mock = new ProductCategoryControllerMockFacade();
            var record  = new ApiProductCategoryResponseModel();
            var records = new List <ApiProductCategoryResponseModel>();

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Exemplo n.º 11
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiProductCategoryRequestModel> patch)
        {
            ApiProductCategoryResponseModel record = await this.ProductCategoryService.Get(id);

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

                UpdateResponse <ApiProductCategoryResponseModel> result = await this.ProductCategoryService.Update(id, model);

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

            response.Should().NotBeNull();
        }