예제 #1
0
        public void TestResetCascadeDeleteCompanySomeQuotesDifferentUserIdOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            options.StopNextDispose();
            using (var context = new CascadeSoftDelDbContext(options, userId))
            {
                context.Database.EnsureCreated();
                var customer = Customer.SeedCustomerWithQuotes(context, userId);
                customer.Quotes.First().UserId          = Guid.NewGuid();
                customer.Quotes.First().SoftDeleteLevel = 1;  //Set to deleted
                context.SaveChanges();

                var config  = new ConfigCascadeDeleteWithUserId(context);
                var service = new CascadeSoftDelService <ICascadeSoftDelete>(config);
                service.SetCascadeSoftDelete(customer).Result.ShouldEqual(1 + 3 + 3 + (3 * 4));
            }
            using (var context = new CascadeSoftDelDbContext(options, userId))
            {
                var config  = new ConfigCascadeDeleteWithUserId(context);
                var service = new CascadeSoftDelService <ICascadeSoftDelete>(config);

                //ATTEMPT
                var status = service.ResetCascadeSoftDelete(context.Companies.IgnoreQueryFilters().Single());

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(1 + 3 + 3 + (3 * 4));
                status.Message.ShouldEqual("You have recovered an entity and its 18 dependents");
                context.Quotes.Count().ShouldEqual(3);
            }
        }
예제 #2
0
        public void TestResetCascadeSoftOfPreviousDeleteNoCalSaveChangesOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);

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

                var numSoftDeleted = service.SetCascadeSoftDelete(context.Employees.Single(x => x.Name == "CTO")).Result;
                numSoftDeleted.ShouldEqual(7 + 6);
                Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);

                context.ChangeTracker.Clear();

                //ATTEMPT
                var status = service.ResetCascadeSoftDelete(context.Employees.IgnoreQueryFilters().Single(x => x.Name == "CTO"), false);
                context.Employees.Count().ShouldEqual(11 - 7);
                context.Contracts.Count().ShouldEqual(9 - 6);
                context.SaveChanges();
                context.Employees.Count().ShouldEqual(11);
                context.Contracts.Count().ShouldEqual(9);

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(7 + 6);
            }
        }
예제 #3
0
        public void TestDisconnectedResetCascadeSoftDeleteEmployeeSoftDelOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            options.StopNextDispose();
            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);

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

                var numSoftDeleted = service.SetCascadeSoftDelete(context.Employees.Single(x => x.Name == "CTO")).Result;
                numSoftDeleted.ShouldEqual(7 + 6);
            }
            using (var context = new CascadeSoftDelDbContext(options))
            {
                var config  = new ConfigCascadeDeleteWithUserId(context);
                var service = new CascadeSoftDelService <ICascadeSoftDelete>(config);

                //ATTEMPT
                var status = service.ResetCascadeSoftDelete(context.Employees.IgnoreQueryFilters().Single(x => x.Name == "CTO"));

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(7 + 6);
                context.Employees.Count().ShouldEqual(11);
                context.Contracts.Count().ShouldEqual(9);
            }
        }
예제 #4
0
        public void TestCascadeSoftDeleteEmployeeSoftDelInfoNoCallSaveChangesOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);

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

                //ATTEMPT
                var status = service.SetCascadeSoftDelete(ceo.WorksFromMe.First(), false);
                context.Employees.IgnoreQueryFilters().Count(x => x.SoftDeleteLevel != 0).ShouldEqual(0);
                context.SaveChanges();
                context.Employees.IgnoreQueryFilters().Count(x => x.SoftDeleteLevel != 0).ShouldEqual(7);

                //VERIFY
                //Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);
                status.Result.ShouldEqual(7 + 6);
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Message.ShouldEqual("You have soft deleted an entity and its 12 dependents");
            }
        }
예제 #5
0
        public void TestCascadeDeleteOneQuoteThenStockCheckOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

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

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

                var status = service.SetCascadeSoftDelete(customer.Quotes.First());
                status.IsValid.ShouldBeTrue(status.GetAllErrors());

                //ATTEMPT
                var requiredProducts = context.Set <LineItem>().ToList()
                                       .GroupBy(x => x.ProductSku, y => y.NumProduct)
                                       .ToDictionary(x => x.Key, y => y.Sum());

                //VERIFY
                foreach (var productSku in requiredProducts.Keys)
                {
                    _output.WriteLine($"{productSku}: {requiredProducts [productSku]} needed.");
                }
            }
        }
예제 #6
0
        public void TestCascadeSoftDeleteEmployeeSoftDelInfoOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);
                Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);

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

                //ATTEMPT
                var status = service.SetCascadeSoftDelete(ceo.WorksFromMe.First());

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(7 + 6);
                status.Message.ShouldEqual("You have soft deleted an entity and its 12 dependents");

                context.ChangeTracker.Clear();

                _output.WriteLine("---------------------\nAfter Cascade SoftDelete of the CTO and his/her staff.");
                context.Employees.Count().ShouldEqual(4);
                var allEmployees = context.Employees
                                   .Include(x => x.WorksFromMe)
                                   .ToList();
                var readCeo = allEmployees.Single(x => x.Name == "CEO");
                Employee.ShowHierarchical(readCeo, x => _output.WriteLine(x), false);
            }
        }
예제 #7
0
        public void TestResetCascadeSoftDeletePartialOfPreviousDeleteDoesNothingOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);

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

                var numSoftDeleted = service.SetCascadeSoftDelete(context.Employees.Single(x => x.Name == "CTO")).Result;
                numSoftDeleted.ShouldEqual(7 + 6);
                Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);

                context.ChangeTracker.Clear();

                //ATTEMPT
                var status = service.ResetCascadeSoftDelete(context.Employees.IgnoreQueryFilters().Single(x => x.Name == "ProjectManager1"));

                //VERIFY
                Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);
                status.IsValid.ShouldBeFalse();
                status.GetAllErrors().ShouldEqual("This entry was soft deleted 1 level above here");
                status.Result.ShouldEqual(0);
            }
        }
예제 #8
0
        public void TestCascadeSoftDeleteTwoLevelOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);

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

                //ATTEMPT
                var numInnerSoftDelete = service.SetCascadeSoftDelete(context.Employees.Single(x => x.Name == "ProjectManager1")).Result;
                numInnerSoftDelete.ShouldEqual(3 + 3);
                var status = service.SetCascadeSoftDelete(context.Employees.Single(x => x.Name == "CTO"));

                //VERIFY
                Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(4 + 3);
                context.Employees.Count().ShouldEqual(4);
                context.Employees.IgnoreQueryFilters().Count().ShouldEqual(11);
                context.Employees.IgnoreQueryFilters().Select(x => x.SoftDeleteLevel).Where(x => x > 0)
                //.ToList().ForEach(x => _output.WriteLine(x.ToString()));
                .ToArray().ShouldEqual(new byte[] { 1, 1, 2, 2, 2, 3, 3 });
                context.Contracts.Count().ShouldEqual(3);
                context.Contracts.IgnoreQueryFilters().Count().ShouldEqual(9);
                context.Employees.IgnoreQueryFilters().Select(x => x.Contract).Where(x => x != null)
                .Select(x => x.SoftDeleteLevel).Where(x => x > 0)
                //.ToList().ForEach(x => _output.WriteLine(x.ToString()));
                .ToArray().ShouldEqual(new byte[] { 2, 2, 3, 3, 3, 4 });
            }
        }
예제 #9
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);
        }
예제 #10
0
        public void TestCascadeSoftDeleteExistingSoftDeleteEmployeeSoftDelOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);

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

                var preNumSoftDeleted = service.SetCascadeSoftDelete(ceo.WorksFromMe.First().WorksFromMe.First()).Result;
                Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);

                //ATTEMPT
                var status = service.SetCascadeSoftDelete(ceo.WorksFromMe.First());

                //VERIFY
                Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                preNumSoftDeleted.ShouldEqual(3 + 3);
                status.Result.ShouldEqual(4 + 3);
                context.Employees.Count().ShouldEqual(4);
                context.Employees.IgnoreQueryFilters().Count().ShouldEqual(11);
                context.Employees.IgnoreQueryFilters().Select(x => x.SoftDeleteLevel).Where(x => x > 0).ToArray()
                .ShouldEqual(new byte[] { 1, 1, 2, 2, 2, 3, 3 });
                context.Contracts.Count().ShouldEqual(3);
                context.Contracts.IgnoreQueryFilters().Count().ShouldEqual(9);
                context.Employees.IgnoreQueryFilters().Select(x => x.Contract).Where(x => x != null)
                .Select(x => x.SoftDeleteLevel).Where(x => x > 0)
                .ToArray().ShouldEqual(new byte[] { 2, 2, 3, 3, 3, 4 });
            }
        }
예제 #11
0
        public void TestDisconnectedCascadeSoftDeleteEmployeeSoftDelOk(bool readEveryTime)
        {
            //SETUP
            var logs    = new List <string>();
            var options = SqliteInMemory.CreateOptionsWithLogTo <CascadeSoftDelDbContext>(log => logs.Add(log));

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                Employee.SeedEmployeeSoftDel(context);

                context.ChangeTracker.Clear();

                var config = new ConfigCascadeDeleteWithUserId(context)
                {
                    ReadEveryTime = readEveryTime
                };
                var service = new CascadeSoftDelService <ICascadeSoftDelete>(config);

                //ATTEMPT
                logs.Clear();
                var status = service.SetCascadeSoftDelete(context.Employees.Single(x => x.Name == "CTO"));

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                logs.Count(x => _selectMatchRegex.IsMatch(x)).ShouldEqual(7);
                status.Result.ShouldEqual(7 + 6);
                context.Employees.Count().ShouldEqual(4);
                context.Employees.IgnoreQueryFilters().Count().ShouldEqual(11);
                context.Contracts.Count().ShouldEqual(3);
                context.Contracts.IgnoreQueryFilters().Count().ShouldEqual(9);
            }
        }
예제 #12
0
        public void TestCascadeDeleteOneQuoteOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

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

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

                //ATTEMPT
                var status = service.SetCascadeSoftDelete(customer.Quotes.First());

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Message.ShouldEqual("You have soft deleted an entity and its 5 dependents");

                context.ChangeTracker.Clear();
                context.Companies.Count().ShouldEqual(1);
                context.Quotes.Count().ShouldEqual(3);
                context.Set <LineItem>().Count().ShouldEqual(3 * 4);
                context.Set <QuotePrice>().Count().ShouldEqual(3);
                status.Result.ShouldEqual(1 + 4 + 1);
                context.Set <LineItem>().IgnoreQueryFilters().Count(x => x.SoftDeleteLevel != 0).ShouldEqual(4);
            }
        }
예제 #13
0
        public void TestCascadeDeleteCompanySomeQuotePriceDifferentUserIdOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options, userId))
            {
                context.Database.EnsureCreated();
                var customer = Customer.SeedCustomerWithQuotes(context, userId);
                customer.Quotes.First().PriceInfo.UserId = Guid.NewGuid();
                context.SaveChanges();

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

                //ATTEMPT
                var status = service.SetCascadeSoftDelete(customer);

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(1 + 4 + 3 + (4 * 4));
                status.Message.ShouldEqual("You have soft deleted an entity and its 23 dependents");
                context.Set <QuotePrice>().IgnoreQueryFilters().Count(x => x.SoftDeleteLevel != 0).ShouldEqual(3);
            }
        }
예제 #14
0
        public void TestResetCascadeSoftDeleteTwoLevelSoftDeleteThenResetTopOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);

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

                var numInnerSoftDelete = service.SetCascadeSoftDelete(context.Employees.Single(x => x.Name == "ProjectManager1")).Result;
                numInnerSoftDelete.ShouldEqual(3 + 3);
                var numOuterSoftDelete = service.SetCascadeSoftDelete(context.Employees.Single(x => x.Name == "CTO")).Result;
                numOuterSoftDelete.ShouldEqual(4 + 3);
                Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);

                context.ChangeTracker.Clear();

                //ATTEMPT
                var status = service.ResetCascadeSoftDelete(context.Employees.IgnoreQueryFilters().Single(x => x.Name == "CTO"));

                //VERIFY
                Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(4 + 3);

                context.ChangeTracker.Clear();
                var cto = context.Employees.Include(x => x.WorksFromMe).Single(x => x.Name == "CTO");
                cto.WorksFromMe.Single(x => x.SoftDeleteLevel == 0).Name.ShouldEqual("ProjectManager2");
            }
        }
예제 #15
0
        public void TestHardDeleteCascadeSoftOfPreviousDeleteInfo()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);

                var config         = new ConfigCascadeDeleteWithUserId(context);
                var service        = new CascadeSoftDelService <ICascadeSoftDelete>(config);
                var numSoftDeleted = service.SetCascadeSoftDelete(context.Employees.Single(x => x.Name == "CTO")).Result;
                numSoftDeleted.ShouldEqual(7 + 6);
                Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);

                //ATTEMPT
                var status = service.HardDeleteSoftDeletedEntries(context.Employees.IgnoreQueryFilters().Single(x => x.Name == "CTO"));

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(7 + 6);
                status.Message.ShouldEqual("You have hard deleted an entity and its 12 dependents");
                context.Employees.IgnoreQueryFilters().Count().ShouldEqual(4);
            }
        }
예제 #16
0
        public void TestCascadeDeleteQuoteDoesNotSoftDeleteCompanyOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options, userId))
            {
                context.Database.EnsureCreated();
                var customer = Customer.SeedCustomerWithQuotes(context, userId);
                customer.Quotes.First().UserId = Guid.NewGuid();
                context.SaveChanges();

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

                //ATTEMPT
                var status = service.SetCascadeSoftDelete(customer.Quotes.First());

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(1 + 1 + 4);
                status.Message.ShouldEqual("You have soft deleted an entity and its 5 dependents");
                context.Companies.Count().ShouldEqual(1);
                context.Quotes.Count().ShouldEqual(3);
            }
        }
예제 #17
0
        public void TestHardDeleteCascadeDeleteCompanySomeQuotesDifferentUserIdOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

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

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

                //ATTEMPT
                var status = service.HardDeleteSoftDeletedEntries(customer);

                //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.Quotes.Count().ShouldEqual(0);
                context.Quotes.IgnoreQueryFilters().Count().ShouldEqual(4);
            }
        }
예제 #18
0
        public void TestCircularLoopCascadeSoftDeleteEmployeeSoftDelOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo      = Employee.SeedEmployeeSoftDel(context);
                var devEntry = context.Employees.Single(x => x.Name == "dev1a");
                devEntry.WorksFromMe = new List <Employee> {
                    devEntry.Manager.Manager
                };

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

                //ATTEMPT
                var status = service.SetCascadeSoftDelete(context.Employees.Single(x => x.Name == "CTO"));

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(7 + 6);
            }
        }
예제 #19
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);
        }
예제 #20
0
        public void TestCascadeSoftDeleteEmployeeSoftDelOneToOneOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);

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

                //ATTEMPT
                var ex = Assert.Throws <InvalidOperationException>(() => service.SetCascadeSoftDelete(ceo.WorksFromMe.First().Contract));

                //VERIFY
                ex.Message.ShouldEqual("You cannot soft delete a one-to-one relationship. It causes problems if you try to create a new version.");
            }
        }
예제 #21
0
        public void TestCheckCascadeSoftDeleteNoSoftDeleteInfo()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);

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

                //ATTEMPT
                var status = service.CheckCascadeSoftDelete(context.Employees.IgnoreQueryFilters().Single(x => x.Name == "ProjectManager1"));

                //VERIFY
                status.IsValid.ShouldBeFalse();
                status.Result.ShouldEqual(0);
                status.GetAllErrors().ShouldEqual("This entry isn't soft deleted.");
            }
        }
예제 #22
0
        public void TestGetSoftDeletedEntriesEmployeeSoftDeletedOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);

                var config  = new ConfigCascadeDeleteWithUserId(context);
                var service = new CascadeSoftDelService <ICascadeSoftDelete>(config);
                service.SetCascadeSoftDelete(ceo.WorksFromMe.First()).IsValid.ShouldBeTrue();

                //ATTEMPT
                var softDeleted = service.GetSoftDeletedEntries <Employee>().ToList();

                //VERIFY
                softDeleted.Count.ShouldEqual(1);
                softDeleted.Single().Name.ShouldEqual(ceo.WorksFromMe.First().Name);
            }
        }
        public void TestCascadeDeleteCompanyOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options, userId))
            {
                context.Database.EnsureCreated();
                var company = Company.SeedCompanyWithQuotes(context, userId);

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

                //ATTEMPT
                var status = service.SetCascadeSoftDelete(company);

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(1 + 4 + 4);
                status.Message.ShouldEqual("You have soft deleted an entity and its 8 dependents");
            }
        }
예제 #24
0
        public void TestGetSoftDeletedEntriesCompanyOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

            using (var context = new CascadeSoftDelDbContext(options, userId))
            {
                context.Database.EnsureCreated();
                var customer = Customer.SeedCustomerWithQuotes(context, userId);

                var config  = new ConfigCascadeDeleteWithUserId(context);
                var service = new CascadeSoftDelService <ICascadeSoftDelete>(config);
                var status  = service.SetCascadeSoftDelete(customer);

                //ATTEMPT
                var softDeleted = service.GetSoftDeletedEntries <Customer>().ToList();

                //VERIFY
                softDeleted.Count.ShouldEqual(1);
                softDeleted.Single().CompanyName.ShouldEqual(customer.CompanyName);
            }
        }
예제 #25
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);
        }
예제 #26
0
        public void TestCascadeSoftDeleteEmployeeSoftDelWithLoggingOk(bool readEveryTime, int selectCount)
        {
            //SETUP
            var logs    = new List <string>();
            var options = SqliteInMemory.CreateOptionsWithLogTo <CascadeSoftDelDbContext>(log => logs.Add(log));

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var ceo = Employee.SeedEmployeeSoftDel(context);

                var config = new ConfigCascadeDeleteWithUserId(context)
                {
                    ReadEveryTime = readEveryTime
                };
                var service = new CascadeSoftDelService <ICascadeSoftDelete>(config);

                //ATTEMPT
                logs.Clear();
                var status = service.SetCascadeSoftDelete(ceo.WorksFromMe.First());

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                logs.Count(x => _selectMatchRegex.IsMatch(x)).ShouldEqual(selectCount);
                status.Result.ShouldEqual(7 + 6);
                context.Employees.Count().ShouldEqual(4);
                context.Employees.IgnoreQueryFilters().Count().ShouldEqual(11);
                context.Employees.IgnoreQueryFilters().Select(x => x.SoftDeleteLevel).Where(x => x > 0).ToArray()
                .ShouldEqual(new byte[] { 1, 2, 2, 3, 3, 3, 3 });
                context.Contracts.Count().ShouldEqual(3);
                context.Contracts.IgnoreQueryFilters().Count().ShouldEqual(9);
                context.Employees.IgnoreQueryFilters().Select(x => x.Contract).Where(x => x != null)
                .Select(x => x.SoftDeleteLevel).Where(x => x > 0).ToArray()
                .ShouldEqual(new byte[] { 2, 3, 3, 4, 4, 4 });
            }
        }
예제 #27
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);
        }