示例#1
0
        public void Get_ProductIsRequestedWithFilteredClauseWithoutLazyLoading_ProductCollectionContainsNoProductList()
        {
            var testProduct1 = new Product("Kildevand", 18, true);
            var testProduct2 = new Product("Øl", 20, false);

            var testProductGroup = new ProductGroup() { Name = "Drikkevarer" };
            testProductGroup.Products.Add(testProduct1);
            testProductGroup.Products.Add(testProduct2);

            using (var context = new CashRegisterContext())
            {
                context.ProductGroups.Add(testProductGroup);
                context.SaveChanges();
            }

            using (var context = new CashRegisterContext())
            {
                context.Configuration.LazyLoadingEnabled = false;
                var uut = new Repository<ProductGroup>(context);
                var result = uut.Get().ElementAt(0);
                Assert.That(result.Products.Count, Is.EqualTo(0));
            }
        }
示例#2
0
        public void Get_ProductIsRequestedWithEmptyFilteredClause_ArgumentExceptionIsThrown()
        {
            var testProduct1 = new Product("Kildevand", 18, true);
            var testProduct2 = new Product("Øl", 20, false);

            var testProductGroup = new ProductGroup() { Name = "Drikkevarer" };
            testProductGroup.Products.Add(testProduct1);
            testProductGroup.Products.Add(testProduct2);

            using (var context = new CashRegisterContext())
            {
                context.ProductGroups.Add(testProductGroup);
                context.SaveChanges();
            }

            using (var context = new CashRegisterContext())
            {
                var uut = new Repository<ProductGroup>(context);
                var filter = new[] { "" };
                Assert.That(() => uut.Get(null, null, filter).ElementAt(0), Throws.ArgumentException);
            }
        }