public void Test_CancelSale_Helper(int id) { var fakeContext = new FakeContext("CancelSale_Helpe"); 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 sale = repository.GetById(id); Assert.Equal(100, productRepository.GetById(id).Quantity); update.CancelSale(sale); Assert.Equal(130, productRepository.GetById(id).Quantity); } }