예제 #1
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);
        }
        public void TestHardDeleteCascadeDeleteCompanySomeQuotesDifferentUserIdOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options, userId))
            {
                context.Database.EnsureCreated();
                var customerId = Customer.SeedCustomerWithQuotes(context, userId).Id;
                Customer.SeedCustomerWithQuotes(context, Guid.Empty, "Other customer");

                context.ChangeTracker.Clear();

                var config  = new ConfigCascadeDeleteWithUserId(context);
                var service = new CascadeSoftDelService <ICascadeSoftDelete>(config);
                service.SetCascadeSoftDeleteViaKeys <Customer>(customerId).Result.ShouldEqual(1 + 4 + 4 + (4 * 4));

                //ATTEMPT
                var status = service.HardDeleteSoftDeletedEntriesViaKeys <Customer>(customerId);

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(1 + 4 + 4 + (4 * 4));
                status.Message.ShouldEqual("You have hard deleted an entity and its 24 dependents");

                context.ChangeTracker.Clear();
                context.Quotes.Count().ShouldEqual(0);
                context.Quotes.IgnoreQueryFilters().Count().ShouldEqual(4);
            }
        }
예제 #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);
        }