Example #1
0
        public IHttpActionResult UpdateProduct(ProductDto productDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var product = _service.GetProduct(productDto.Id);

            if (product == null)
            {
                return(BadRequest());
            }

            product.Mass       = productDto.Mass;
            product.PricePerKg = productDto.PricePerKg;
            product.PriceTotal = productDto.Mass * (productDto.PricePerKg / 1000);
            var food     = _service.GetFood(product.FoodId);
            var category = _service.GetCategoryType(food.Category1);

            product.Food         = food;
            product.CategoryType = category;

            productDto = Mapper.Map <Product, ProductDto>(product);

            _service.Complete();

            return(Ok(productDto));
        }
Example #2
0
        public void GetProduct_IdOne_Returns_Product()
        {
            // Arrange
            var ID       = 1;
            var mockRepo = new Mock <IProductRepository>();

            mockRepo.Setup(m => m.Get(ID))
            .Returns(
                new Product {
                Id = ID
            }
                );
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(uow => uow.Products).Returns(mockRepo.Object);

            ShoppinglistService service = new ShoppinglistService(mockUnitOfWork.Object);

            // Act
            var actual = service.GetProduct(ID);

            // Assert
            Assert.IsTrue(actual.GetType() == typeof(Product));
        }