Exemplo n.º 1
0
        public void test_repository_factory_usage()
        {
            RepositoryFactoryTestClass factoryTest = new RepositoryFactoryTestClass();

            IEnumerable<Product> products = factoryTest.GetProducts();

            Assert.IsTrue(products != null);
        }
Exemplo n.º 2
0
        public void test_factory_mocking2()
        {
            List<Product> products = new List<Product>()
            {
                new Product() { ProductId = 1, Name = "Product1" ,Asin = "ABC" , Price = 15.5m},
                new Product() { ProductId = 2, Name = "Product2" , Asin = "ABC", Price = 55.99m}
            };


            Mock<IProductRepository> mockProductRepository = new Mock<IProductRepository>();
            mockProductRepository.Setup(obj => obj.Get()).Returns(products);

            Mock<IDataRepositoryFactory> mockDataRepository = new Mock<IDataRepositoryFactory>();
            mockDataRepository.Setup(obj => obj.GetDataRepository<IProductRepository>()).Returns(mockProductRepository.Object);

            RepositoryFactoryTestClass factoryTest = new RepositoryFactoryTestClass(mockDataRepository.Object);

            IEnumerable<Product> ret = factoryTest.GetProducts();

            Assert.IsTrue(ret == products);
        }