public void ShouldGetProductsFeed()
        {
            ProductCatalog catalog = new ProductCatalog(
                new InMemoryProductRepository(
                    new List <Product> {
                new Product {
                    Id = "1", Category = "foo", Name = "Foo1", UnitPrice = 1
                },
                new Product {
                    Id = "2", Category = "bar", Name = "bar2", UnitPrice = 2
                }
            }));

            Mock <IWebOperationContext> mockContext = new Mock <IWebOperationContext>
            {
                DefaultValue = DefaultValue.Mock
            };

            IEnumerable <SyndicationItem> items;

            using (new MockedWebOperationContext(mockContext.Object))
            {
                var formatter = catalog.GetProducts("foo");
                items = formatter.Feed.Items;
            }

            mockContext.VerifySet(c => c.OutgoingResponse.ContentType, "application/atom+xml");

            Assert.AreEqual(1, items.Count());
            Assert.IsTrue(items.Any(i => i.Id == "http://products/1" && i.Title.Text == "Foo1"));
        }
Beispiel #2
0
        public void GenerateProductReport(ProductCatalog prodCat)
        {
            MakeRoom();
            MakeHeader("PRODUCTS");

            Console.Write("ID".PadRight(10));
            Console.Write("DESCRIPTION".PadRight(50));
            Console.Write("WEIGHT".PadRight(20));
            Console.WriteLine();

            foreach (Product aProd in prodCat.GetProducts())
            {
                Console.Write($"{aProd.ProductId}".PadRight(10));
                Console.Write($"{aProd.Description}".PadRight(50));
                Console.Write($"{aProd.Weight:F3}".PadRight(15));
                Console.WriteLine(" kgs.");
            }

            MakeFooter();
            Console.WriteLine($"Summary: a total of {prodCat.GetProducts().Count} Products are available");
            Console.WriteLine();
        }
 public IEnumerable <Product> CreateProductCollection(ProductCatalog prodCat)
 {
     return(prodCat.GetProducts());
 }