示例#1
0
        public void ShouldAddAnObjectGraph()
        {
            var prod = new Product
            {
                CurrentPrice = 12.99M,
                UnitCost     = 10.99M,
                UnitsInStock = 5,
            };
            var cat = new Category {
                CategoryName = "CatName"
            };

            ExecuteInATransaction(RunTheTest);

            void RunTheTest()
            {
                SampleDataInitializer.ClearData(Context);
                cat.Products.Add(prod);
                Assert.Equal(0, cat.Id);
                Assert.Equal(0, prod.CategoryId);
                Assert.Equal(0, prod.Id);
                Context.Categories.Add(cat);
                Assert.True(cat.Id == 0);
                Assert.True(prod.CategoryId == 0);
                Assert.Equal(cat.Id, prod.CategoryId);
                Context.SaveChanges();
                Assert.Single(Context.Categories);
                Assert.Single(Context.Products);
                Assert.True(cat.Id > 0);
                Assert.True(prod.Id > 0);
                Assert.Equal(cat.Id, prod.CategoryId);
            }
        }
示例#2
0
        public void ShouldAddListOfNewCategoryRecords()
        {
            var cats = new List <Category>
            {
                new Category {
                    CategoryName = "Cat1Name"
                },
                new Category {
                    CategoryName = "Cat2Name"
                },
                new Category {
                    CategoryName = "Cat3Name"
                },
            };

            ExecuteInATransaction(RunTheTest);

            void RunTheTest()
            {
                SampleDataInitializer.ClearData(Context);
                Context.Categories.AddRange(cats);
                Context.SaveChanges();
                Assert.Equal(3, Context.Categories.Count());
            }
        }
示例#3
0
        protected void CreateCategoryAndProducts(StoreContext context)
        {
            SampleDataInitializer.ClearData(context);
            var prod1 = new Product
            {
                CurrentPrice = 12.99M,
                UnitCost     = 10.99M,
                UnitsInStock = 5,
                Details      = { ModelName = "Product 1" },
            };
            var prod2 = new Product
            {
                CurrentPrice = 99.99M,
                UnitCost     = 89.99M,
                UnitsInStock = 2,
                Details      = { ModelName = "Product 2" }
            };
            var cat = new Category {
                CategoryName = "CatName"
            };

            cat.Products.AddRange(new List <Product> {
                prod1, prod2
            });
            context.Categories.Add(cat);
            context.SaveChanges();
        }
示例#4
0
        public void ShouldClearTheData()
        {
            SampleDataInitializer.InitializeData(Context);
            SampleDataInitializer.ClearData(Context);
            var cars = Context.Cars.IgnoreQueryFilters();

            Assert.Empty(cars);
        }
        public void ShouldClearTheData()
        {
            SampleDataInitializer.InitializeData(Context);
            var cars = Context.Cars.IgnoreQueryFilters().ToList();

            Assert.NotNull(cars);
            Assert.Equal(9, cars.Count);
            SampleDataInitializer.ClearData(Context);
            var cars2 = Context.Cars.IgnoreQueryFilters();

            Assert.NotNull(cars2);
            Assert.Empty(cars2);
        }
示例#6
0
        public void ShouldAddNewCategoryRecord()
        {
            var cat = new Category {
                CategoryName = "CatName"
            };

            ExecuteInATransaction(RunTheTest);

            void RunTheTest()
            {
                SampleDataInitializer.ClearData(Context);
                Context.Categories.Add(cat);
                Context.SaveChanges();
                Assert.Single(Context.Categories.ToList());
            }
        }
示例#7
0
        public void ShouldGetOrderWithDetails()
        {
            ExecuteInATransaction(RunTheTest);
            void RunTheTest()
            {
                ResetContext();
                SampleDataInitializer.ClearData(Context);
                CreateCategoryAndProducts();
                var cust = new Customer()
                {
                    EmailAddress = "*****@*****.**",
                    FullName     = "Ful Name",
                    Password     = "******"
                };
                var order = new Order
                {
                    OrderDate = DateTime.Now,
                    ShipDate  = DateTime.Now
                };
                var product     = Context.Products.FirstOrDefault();
                var orderDetail = new OrderDetail
                {
                    ProductNavigation = product,
                    UnitCost          = 12.99M,
                    Quantity          = 1
                };

                order.OrderDetails.Add(orderDetail);
                cust.Orders.Add(order);
                ICustomerRepo custRepo = new CustomerRepo(Context);

                custRepo.Add(cust);
                Context.CustomerId = cust.Id;
                Assert.NotNull(Context.Customers.FirstOrDefault());
                Assert.NotNull(Context.Orders.FirstOrDefault());
                Assert.NotNull(Context.OrderDetails.FirstOrDefault());

                var orderRepo = new OrderRepo(Context, new OrderDetailRepo(Context));
                var record    = orderRepo.GetOneWithDetails(1);
                var foo       = "foo";
            }
        }
示例#8
0
        public void ShouldSetServerSideProperties()
        {
            var cat = new Category {
                CategoryName = "CatName"
            };

            ExecuteInATransaction(RunTheTest);

            void RunTheTest()
            {
                SampleDataInitializer.ClearData(Context);
                Assert.Equal(0, cat.Id);
                Assert.Null(cat.TimeStamp);
                Context.Categories.Add(cat);
                Assert.True(cat.Id == 0);
                Assert.Null(cat.TimeStamp);
                Context.SaveChanges();
                Assert.Single(Context.Categories.ToList());
                Assert.True(cat.Id > 0);
                Assert.NotNull(cat.TimeStamp);
            }
        }
示例#9
0
 public void Dispose()
 {
     SampleDataInitializer.ClearData(_db);
     _db.Dispose();
 }
示例#10
0
 protected void CleanDatabase()
 {
     SampleDataInitializer.ClearData(Db);
 }
 private void CleanDatabase()
 {
     SampleDataInitializer.ClearData(_db);
 }
 public override void Dispose()
 {
     SampleDataInitializer.ClearData(Context);
     _repo.Dispose();
 }
 public CategoryRepoTests()
 {
     _repo = new CategoryRepo(Context);
     SampleDataInitializer.ClearData(Context);
 }
示例#14
0
 public void Dispose()
 {
     SampleDataInitializer.ClearData(_repo.Context);
     _repo.Dispose();
 }
示例#15
0
 public CustomerRepoGetTests()
 {
     _repo = new CustomerRepo();
     SampleDataInitializer.ClearData(_repo.Context);
     SampleDataInitializer.InitializeData(_repo.Context);
 }