Beispiel #1
0
        public void Test_UpdateStock(int id)
        {
            var fakeContext = new FakeContext("UpdateProduct_Helper");

            fakeContext.FillWithAll();

            using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object))
            {
                var productRepository = new ProductRepository(context);
                var repository        = new SaleRepository(context);
                var productService    = new Mock <IProductService>();
                productService.Setup(x => x.GetById(It.IsAny <int>())).Returns(productRepository.GetById(id));
                productService.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <Product>()))
                .Returns <int, Product>((productId, product) => "{ Message = Produto alterado com sucesso. }");
                var update = new UpdateProduct(productService.Object);

                var oldSale = repository.GetById(id);
                var newSale = new Sale();
                newSale.ProductId = id;
                newSale.Quantity  = 15;
                update.UpdateStock(newSale, oldSale);

                Assert.Equal(115, productRepository.GetById(id).Quantity);
            }
        }