Пример #1
0
        public void AddNewProducts()
        {
            using (var db = new TestModel.TestModel())
            {
                // Product without new supplier and category.
                var product1         = db.Products.Create();
                var product1Category = "Beverages";
                var product1Supplier = "Exotic Liquids";
                product1.ProductName = "Milk";
                AddProduct(product1, product1Category, product1Supplier, db);

                // Product with new supplier and category.
                var product2 = db.Products.Create();
                product2.ProductName = "Chicken eggs";
                var product2Category = "Animal origin";
                var product2Supplier = "Test company";
                AddProduct(product2, product2Category, product2Supplier, db);

                var products = new List <Product> {
                    product1, product2
                };

                db.Products.AddRange(products);
                db.SaveChanges();
            }
        }
Пример #2
0
 public static void Cleanup()
 {
     using (var db = new TestModel.TestModel())
     {
         db.Products.RemoveRange(db.Products.Where(p => p.ProductName == "Milk" ||
                                                   p.ProductName == "Chicken eggs" ||
                                                   p.ProductName == "Cucumber"));
         db.Categories.RemoveRange(db.Categories.Where(c => c.CategoryName == "Animal origin"));
         db.Suppliers.RemoveRange(db.Suppliers.Where(s => s.CompanyName == "Test company"));
         db.SaveChanges();
     }
 }
Пример #3
0
        public void ChangeCategoryOfProduct()
        {
            using (var db = new TestModel.TestModel())
            {
                var chai              = db.Products.First(p => p.Id == 1);
                var seafoodCategory   = db.Categories.First(c => c.Id == 8);
                var beveragesCategory = db.Categories.First(c => c.Id == 1);

                try
                {
                    chai.Category = seafoodCategory;
                    db.SaveChanges();
                    Assert.AreEqual(seafoodCategory, db.Products.First(p => p.Id == 1).Category);
                }
                finally
                {
                    chai.Category = beveragesCategory;
                    db.SaveChanges();
                }
            }
        }
Пример #4
0
        public void AddNewEmployeeWithTerritories()
        {
            using (var db = new TestModel.TestModel())
            {
                var employee    = db.Employees.Create();
                var territories = db.Territories;
                employee.LastName  = "Ivanov";
                employee.FirstName = "Ivan";
                employee.Territories.Add(territories.First(t => t.Id == "01581"));
                employee.Territories.Add(territories.First(t => t.Id == "01730"));
                employee.Territories.Add(territories.First(t => t.Id == "01833"));
                db.Employees.Add(employee);
                db.SaveChanges();

                var newEmployee = db.Employees.First(e => e.Id == employee.Id);
                Assert.AreEqual(employee, newEmployee);
            }
        }