Exemplo n.º 1
0
        public void AddProduct()
        {
            Random       rnd          = new Random();
            CategoryInfo categoryInfo = new CategoryInfo();
            ProductInfo  productInfo  = new ProductInfo();

            productInfo.Product = new Product()
            {
                ProductName  = "New Product",
                Discontinued = false
            };
            productInfo.Supplier = new Supplier()
            {
                CompanyName = "New supplier"
            };
            ProductInfo productInfo2 = new ProductInfo();

            productInfo2.Product = new Product()
            {
                ProductName  = "New Product2",
                Discontinued = true
            };
            productInfo2.Supplier = new Supplier()
            {
                CompanyName = "New supplier2"
            };
            categoryInfo.Products = new List <Product>()
            {
                productInfo.Product,
                productInfo2.Product
            };
            categoryInfo.Category = new Category()
            {
                CategoryName = $"New Category{rnd.Next(150)}"
            };
            List <CategoryInfo> categoryInfos = new List <CategoryInfo>()
            {
                categoryInfo
            };
            List <ProductInfo> productsInfos = new List <ProductInfo>()
            {
                productInfo, productInfo2
            };

            categoryInfos.ForEach(c => c.Products.ForEach(p => p.CategoryID = c.Category.CategoryID));
            NorthwindDataStore northwindDataStore = new NorthwindDataStore();

            northwindDataStore.AddProducts(categoryInfos, productsInfos);
            Assert.IsTrue(northwindDataStore.GetCategoriesInfo().Any(x => x.Category.CategoryName == categoryInfo.Category.CategoryName));
        }