Esempio n. 1
0
        public void RemoveRange_Products_Returns_True()
        {
            // Arrange
            IEnumerable <Product> products = new[] {
                new Product {
                    Id = 1
                },
                new Product {
                    Id = 2
                },
                new Product {
                    Id = 3
                }
            };

            var mockRepo = new Mock <IProductRepository>();

            mockRepo.Setup(m => m.RemoveRange(products))
            .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.RemoveRange(products);

            // Assert
            Assert.IsTrue(actual);
        }
Esempio n. 2
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());
        }