Esempio n. 1
0
        public void TestMethod1()
        {
            var dataSource = GetTestProducts(10);
            var enumerable = dataSource as Product[] ?? dataSource.ToArray();

            enumerable.ToList().ForEach(p =>
            {
                Console.WriteLine(p.UnitPrice);
            });

            var productMockSet = new MockDbSet <Product>(enumerable.ToList());

            productMockSet.Setup(prod => prod.Include(nameof(Category))).Returns(productMockSet.Object);
            productMockSet.Setup(prod => prod.Include(nameof(Supplier))).Returns(productMockSet.Object);

            var mockContext = new Mock <NorthWindContext>();

            mockContext.Setup(c => c.Products).Returns(productMockSet.Object);

            var provider = new ProductProvider(mockContext.Object);
            var products = provider.GetAllProducts();

            Console.WriteLine(products);
            products.Count().Should().Be(10);

            var discounted = provider.GetDiscountedProducts();

            discounted.Count().Should().Be(0);

            var cheap = provider.GetCheaperProducts(10m).ToArray <Product>();

            cheap.Should().NotBeNull();
            var cnt = cheap.Length;

            cnt.Should().Be(10);
        }