예제 #1
0
        public static Company SeedCompanyWithQuotes(CascadeSoftDelDbContext context, Guid userId, string companyName = "Company1")
        {
            var company = new Company
            {
                CompanyName = companyName,
                UserId      = userId,
                Quotes      = new HashSet <Quote>()
            };

            for (int i = 0; i < 4; i++)
            {
                company.Quotes.Add(
                    new Quote {
                    Name = $"quote{i}", UserId = userId, PriceInfo = new QuotePrice {
                        UserId = userId, Price = i
                    }
                }
                    );
            }

            context.Add(company);
            context.SaveChanges();

            return(company);
        }
예제 #2
0
        public void TestCascadeDeleteOneQuoteOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using var context = new CascadeSoftDelDbContext(options);
            context.Database.EnsureCreated();
            context.Add(new Customer
            {
                CompanyName = "xxx",
                MoreInfo    = new CustomerInfo()
            });
            context.SaveChanges();

            context.ChangeTracker.Clear();

            var config  = new ConfigCascadeDeleteWithUserId(context);
            var service = new CascadeSoftDelService <ICascadeSoftDelete>(config);

            //ATTEMPT
            var status = service.SetCascadeSoftDeleteViaKeys <Customer>(1);

            //VERIFY
            status.IsValid.ShouldBeTrue(status.GetAllErrors());
            context.Companies.Count().ShouldEqual(0);
            context.CompanyInfos.Count().ShouldEqual(1);
        }
예제 #3
0
        public void TestSetSoftDeleteOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using var context = new CascadeSoftDelDbContext(options);
            context.Database.EnsureCreated();
            var shadowClass = new ShadowCascadeDelClass();

            context.Add(shadowClass);
            context.SaveChanges();

            context.ChangeTracker.Clear();

            var config  = new ConfigCascadeDeleteShadowDel(context);
            var service = new CascadeSoftDelService <IShadowCascadeSoftDelete>(config);

            //ATTEMPT
            var status = service.SetCascadeSoftDeleteViaKeys <ShadowCascadeDelClass>(shadowClass.Id);

            //VERIFY
            status.IsValid.ShouldBeTrue(status.GetAllErrors());
            status.Result.ShouldEqual(1);
            context.ShadowCascadeDelClasses.Count().ShouldEqual(0);
            context.ShadowCascadeDelClasses.IgnoreQueryFilters().Count().ShouldEqual(1);
        }
예제 #4
0
        public void TestManuallySoftDeleteOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using var context = new CascadeSoftDelDbContext(options);
            context.Database.EnsureCreated();
            var shadowClass = new ShadowCascadeDelClass();

            context.Add(shadowClass);
            context.SaveChanges();

            //ATTEMPT
            context.Entry(shadowClass).Property("SoftDeleteLevel").CurrentValue = (byte)1;
            context.SaveChanges();

            //VERIFY
            context.ShadowCascadeDelClasses.Count().ShouldEqual(0);
            context.ShadowCascadeDelClasses.IgnoreQueryFilters().Count().ShouldEqual(1);
        }
        public static Customer SeedCustomerWithQuotes(CascadeSoftDelDbContext context, Guid userId, string companyName = "Company1")
        {
            var customer = new Customer
            {
                CompanyName = companyName,
                UserId      = userId,
                Quotes      = new HashSet <Quote>()
            };

            for (int i = 0; i < 4; i++)
            {
                customer.Quotes.Add(
                    new Quote {
                    Name      = $"quote{i}", UserId = userId,
                    PriceInfo = new QuotePrice {
                        UserId = userId, Price = i
                    },
                    LineItems = new List <LineItem>
                    {
                        new LineItem {
                            LineNum = 1, ProductSku = "Door", NumProduct = 2
                        },
                        new LineItem {
                            LineNum = 2, ProductSku = "Window", NumProduct = 6
                        },
                        new LineItem {
                            LineNum = 3, ProductSku = "Wall", NumProduct = 4
                        },
                        new LineItem {
                            LineNum = 3, ProductSku = "Roof", NumProduct = 1
                        },
                    }
                }
                    );
            }

            context.Add(customer);
            context.SaveChanges();

            return(customer);
        }
예제 #6
0
        public void TestResetSoftDeleteOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using var context = new CascadeSoftDelDbContext(options);
            context.Database.EnsureCreated();
            var shadowClass = new ShadowCascadeDelClass();

            context.Add(shadowClass);
            context.Entry(shadowClass).Property("SoftDeleteLevel").CurrentValue = (byte)1;
            context.SaveChanges();

            var config  = new ConfigCascadeDeleteShadowDel(context);
            var service = new CascadeSoftDelService <IShadowCascadeSoftDelete>(config);

            //ATTEMPT
            var status = service.ResetCascadeSoftDelete(shadowClass);

            //VERIFY
            status.IsValid.ShouldBeTrue(status.GetAllErrors());
            status.Result.ShouldEqual(1);
            context.ShadowCascadeDelClasses.Count().ShouldEqual(1);
        }
예제 #7
0
        public void TestGetSoftDeleteOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using var context = new CascadeSoftDelDbContext(options);
            context.Database.EnsureCreated();
            var shadowClass = new ShadowCascadeDelClass();

            context.Add(shadowClass);
            context.Entry(shadowClass).Property("SoftDeleteLevel").CurrentValue = (byte)1;
            context.SaveChanges();

            context.ChangeTracker.Clear();

            var config  = new ConfigCascadeDeleteShadowDel(context);
            var service = new CascadeSoftDelService <IShadowCascadeSoftDelete>(config);

            //ATTEMPT
            var entities = service.GetSoftDeletedEntries <ShadowCascadeDelClass>().ToList();

            //VERIFY
            entities.Count().ShouldEqual(1);
        }