Example #1
0
        static void Main(string[] args)
        {
            var service  = new ProductService(new ProductRepository());

            Console.WriteLine("Now starting application.....");

            try
            {
                IProduct product = new Grains();//new Grains("Barley and Oats","Grains",0);
                product.Name = "Barlet and Oats";
                product.Category = "Bread";
                service.AddProduct(product);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occurred :" + e.Message);
                Console.WriteLine("Error occurred :" + e);
            }

            Console.WriteLine("\n \n.....");
            try
            {
                service.GetAllProducts();
                service.PrintAll();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occurred :" + e.Message);
                Console.WriteLine("Error occurred :" + e);
            }
            Console.WriteLine("Now ending  application.....");
            Console.Read();
        }
Example #2
0
        public void SaveProductWasCalled()
        {
            var mock = new MockRepository();
            var productRepository = mock.CreateMock<IProductRepository>();

            //Class under test
            var product = new Grains("Wonder Bread","Grains",1);
            var service = new ProductService(productRepository);
            Expect.Call(() => productRepository.SaveProduct(product));

            mock.ReplayAll();

            service.SaveProduct(product);

            mock.VerifyAll();
        }
Example #3
0
        public void GetAllProductsWasCalled()
        {
            var mock = new MockRepository();
            var productRepository = mock.CreateMock<IProductRepository>();

            IList list = new ArrayList();
            //Class under test
            var service = new ProductService(productRepository);
            Expect.Call(productRepository.GetAllProducts()).Return(list);

            mock.ReplayAll();

            IList allProducts = service.GetAllProducts();

            mock.VerifyAll();
        }