Example #1
0
        public IHttpActionResult Delete(int id)
        {
            var shoppinglistInDb = _service.Get(id);

            if (shoppinglistInDb == null)
            {
                return(NotFound());
            }
            var products = _service.GetAllProducts(shoppinglistInDb.Id);

            _service.RemoveRange(products);

            shoppinglistInDb.Products = null;

            _service.Remove(shoppinglistInDb);

            _service.Complete();

            return(Ok());
        }
Example #2
0
        public void Remove_Shoppinglist_Returns_True()
        {
            // Arrange
            var shoppinglist = new Shoppinglist {
                Name = "test"
            };
            var mockRepo = new Mock <IShoppinglistRepository>();

            mockRepo.Setup(m => m.Remove(shoppinglist))
            .Returns(
                true
                );
            var mockUnitOfWork = new Mock <IUnitOfWork>();

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

            ShoppinglistService service = new ShoppinglistService(mockUnitOfWork.Object);

            // Act
            var actual = service.Remove(shoppinglist);

            // Assert
            Assert.IsTrue(actual);
        }
Example #3
0
        public void Remove_Product_Returns_True()
        {
            // Arrange
            var product = new Product {
                Mass = 50
            };
            var mockRepo = new Mock <IProductRepository>();

            mockRepo.Setup(m => m.Remove(product))
            .Returns(
                true
                );
            var mockUnitOfWork = new Mock <IUnitOfWork>();

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

            ShoppinglistService service = new ShoppinglistService(mockUnitOfWork.Object);

            // Act
            var actual = service.Remove(product);

            // Assert
            Assert.IsTrue(actual);
        }