Exemplo n.º 1
0
 public void Init()
 {
     ctx = EFContext.CreateContext();
     repo = new ProductRepository(ctx);
     entity = new Product()
     {
         Home = ctx.HomeSet.FirstOrDefault(p => p.Title == "LaCorderie"),
         Title = "EFTest",
         Supplier = null,
         PriceHT = 300M,
         ProductCategory = null,
         Stock = 10,
         Tax = null,
         Threshold = 3,
         RefHide = false,
         Hide = false,
         IsUnderThreshold = false
     };
 }
Exemplo n.º 2
0
        public void DeleteProduct()
        {
            Product toDelete1 = repo.GetUniq(p => p.Title == "<span style='background-color:red'>Massage</span>");
            Product toDelete2 = repo.GetUniq(p => p.Title == "Vin");

            Assert.IsNotNull(ctx.ProductBookingSet.Include("Product").FirstOrDefault(p => p.Product.Id == toDelete1.Id));
            Assert.IsNotNull(ctx.ProductBookingSet.Include("Product").FirstOrDefault(p => p.Product.Id == toDelete2.Id));

            repo.Delete(toDelete1);
            repo.Save();
            repo.Delete(toDelete2);
            repo.Save();

            Product toAdd;

            repo.Add(toAdd = new Product()
            {
                Home = ctx.HomeSet.FirstOrDefault(p => p.Title == "LaCorderie"),
                Title = "EFTest",
                Supplier = null,
                PriceHT = 300M,
                ProductCategory = null,
                Stock = 10,
                Tax = null,
                Threshold = 3,
                RefHide = false,
                Hide = false,
                BillItemCategory = ctx.BillItemCategorySet.FirstOrDefault(),
                IsUnderThreshold = false
            });

            repo.Save();
            repo.Delete(toAdd);
            repo.Save();

            Assert.IsNull(ctx.ProductBookingSet.Include("Product").FirstOrDefault(p => p.Product.Id == toDelete1.Id));
            Assert.IsNull(ctx.ProductBookingSet.Include("Product").FirstOrDefault(p => p.Product.Id == toDelete2.Id));
            Assert.IsNull(ctx.ProductSet.FirstOrDefault(p => p.Id == toDelete1.Id));
            Assert.IsNull(ctx.ProductSet.FirstOrDefault(p => p.Id == toDelete2.Id));
        }