Esempio n. 1
0
        public void relationships_work_between_sales_and_employees()
        {
            AwesomeMartDb context = DbInitializer.SeededAwesomeMartDbContext;

            Sale sale = new Sale();
            sale.Employee = (from e in context.Employees
                             where e.Name.Equals("John Davis")
                             select e).FirstOrDefault();

            sale.Customer = (from c in context.Customers
                             where c.Name.Equals("Ricky Ricardo")
                             select c).FirstOrDefault();

            sale.Products = new List<Product>();

            foreach (Product p in context.Products)
            {
                sale.Products.Add(p);
            }

            context.Sales.Add(sale);
            context.SaveChanges();

            Employee employee = context.Employees.Where(e => e.Name.Equals("John Davis")).FirstOrDefault();

            Assert.AreEqual(sale.Employee.ID, employee.ID);
        }
Esempio n. 2
0
        public void can_have_more_than_one_product_in_sale()
        {
            AwesomeMartDb context = DbInitializer.SeededAwesomeMartDbContext;

            Sale sale = new Sale();
            sale.Employee = (from e in context.Employees
                             where e.Name.Equals("John Davis")
                             select e).FirstOrDefault();

            sale.Customer = (from c in context.Customers
                             where c.Name.Equals("Ricky Ricardo")
                             select c).FirstOrDefault();

            sale.Products = new List<Product>();

            foreach (Product p in context.Products)
            {
                sale.Products.Add(p);
            }

            context.Sales.Add(sale);
            context.SaveChanges();

            Assert.IsTrue(1 < sale.Products.Count());
        }
Esempio n. 3
0
        private static AwesomeMartDb Seed(AwesomeMartDb context)
        {
            context.Employees.Add(new Employee
            {
                Name = "John Davis",
                Position = Position.Cashier,
                PayType = Enumerations.PayType.Hourly,
                PayRate = 10.25,
                Address = "1234 Some Street, Onett CA, 93123",
                Phone = "233-433-2907"
            });

             context.Customers.Add(new Customer
             {
                Name = "Ricky Ricardo",
                Address = "54321 Different Road, Twoson, AZ, 43667",
                Phone = "678-555-1254"
             });

            context.Products.Add(new Product
            {
                Name = "Snuggie, Blue",
                Price = 24.99
            });

            context.Products.Add(new Product
            {
                Name = "Snuggie, Blue",
                Price = 24.99
            });

            context.Products.Add(new Product
            {
                Name = "Snuggie, Grey",
                Price = 24.99
            });

            context.Products.Add(new Product
            {
                Name = "Slap Chop",
                Price = 19.99
            });

            context.Products.Add(new Product
            {
                Name = "Slap Chop",
                Price = 19.99
            });

            context.Products.Add(new Product
            {
                Name = "Oxyclean, 24oz",
                Price = 9.99
            });

            context.Products.Add(new Product
            {
                Name = "Oxyclean, 24oz",
                Price = 9.99
            });

            context.Products.Add(new Product
            {
                Name = "Oxyclean, 24oz",
                Price = 9.99
            });

            context.Products.Add(new Product
            {
                Name = "Oxyclean, 24oz",
                Price = 9.99
            });

            context.Products.Add(new Product
            {
                Name = "Oxyclean, 24oz",
                Price = 9.99
            });

            context.SaveChanges();

            Sale sale = new Sale();
            sale.Employee = (from e in context.Employees
                             where e.Name.Equals("John Davis")
                             select e).FirstOrDefault();

            sale.Customer = (from c in context.Customers
                             where c.Name.Equals("Ricky Ricardo")
                             select c).FirstOrDefault();

            sale.Products.Add((from p in context.Products
                             where p.Name.Equals("Snuggie, Blue")
                             select p).FirstOrDefault());

            context.Sales.Add(sale);
            context.SaveChanges();

            return context;
        }