Beispiel #1
0
        public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

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

                //ATTEMPT
                var status = await service.ResetCascadeSoftDeleteAsync(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);
            }
        }
Beispiel #2
0
        public async Task TestCascadeDeleteAsyncOneQuoteOk()
        {
            //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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

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

            //VERIFY
            status.IsValid.ShouldBeTrue(status.GetAllErrors());
            context.Companies.Count().ShouldEqual(0);
            context.CompanyInfos.Count().ShouldEqual(1);
        }
Beispiel #3
0
        public async Task TestDisconnectedResetCascadeSoftDeleteEmployeeSoftDelOk()
        {
            //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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

                var numSoftDeleted = (await service.SetCascadeSoftDeleteAsync(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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

                //ATTEMPT
                var status = await service.ResetCascadeSoftDeleteAsync(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);
            }
        }
Beispiel #4
0
        public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

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

                //ATTEMPT
                var status = await service.ResetCascadeSoftDeleteAsync(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);
                var cto = context.Employees.Include(x => x.WorksFromMe).Single(x => x.Name == "CTO");
                cto.WorksFromMe.Single(x => x.SoftDeleteLevel == 0).Name.ShouldEqual("ProjectManager2");
            }
        }
Beispiel #5
0
        public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

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

                //ATTEMPT
                var status = await service.ResetCascadeSoftDeleteAsync(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);
            }
        }
        public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

                //ATTEMPT
                var status = await service.SetCascadeSoftDeleteAsync(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");
            }
        }
        public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

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

                //ATTEMPT
                var status = await service.SetCascadeSoftDeleteAsync(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 });
            }
        }
        public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);
                var numSoftDeleted = (await service.SetCascadeSoftDeleteAsync(context.Employees.Single(x => x.Name == "CTO"))).Result;
                numSoftDeleted.ShouldEqual(7 + 6);
                Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);

                //ATTEMPT
                var status = await service.HardDeleteSoftDeletedEntriesAsync(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.ChangeTracker.Clear();
                context.Employees.IgnoreQueryFilters().Count().ShouldEqual(4);
            }
        }
        public async Task TestHardDeleteCascadeDeleteCompanySomeQuotesDifferentUserIdOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

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

                var config  = new ConfigCascadeDeleteWithUserId(context);
                var service = new CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);
                (await service.SetCascadeSoftDeleteAsync(company)).Result.ShouldEqual(1 + 4 + 4 + (4 * 4));

                //ATTEMPT
                var status = await service.HardDeleteSoftDeletedEntriesAsync(company);

                //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);
            }
        }
        public async Task TestResetCascadeDeleteCompanySomeQuotesDifferentUserIdOk()
        {
            //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);
                company.Quotes.First().UserId          = Guid.NewGuid();
                company.Quotes.First().SoftDeleteLevel = 1;  //Set to deleted
                context.SaveChanges();

                var config  = new ConfigCascadeDeleteWithUserId(context);
                var service = new CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);
                (await service.SetCascadeSoftDeleteAsync(company)).Result.ShouldEqual(1 + 3 + 3);
            }

            using (var context = new CascadeSoftDelDbContext(options, userId))
            {
                var config  = new ConfigCascadeDeleteWithUserId(context);
                var service = new CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

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

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(1 + 3 + 3);
                status.Message.ShouldEqual("You have recovered an entity and its 6 dependents");
                context.Quotes.Count().ShouldEqual(3);
            }
        }
        public async Task TestDisconnectedCascadeSoftDeleteEmployeeSoftDelOk(bool readEveryTime)
        {
            //SETUP
            var logs    = new List <string>();
            var options = SqliteInMemory.CreateOptionsWithLogging <CascadeSoftDelDbContext>(log => logs.Add(log.DecodeMessage()));

            using (var context = new CascadeSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                Employee.SeedEmployeeSoftDel(context);
            }
            using (var context = new CascadeSoftDelDbContext(options))
            {
                var config = new ConfigCascadeDeleteWithUserId(context)
                {
                    ReadEveryTime = readEveryTime
                };
                var service = new CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

                //ATTEMPT
                logs.Clear();
                var status = await service.SetCascadeSoftDeleteAsync(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);
            }
        }
        public async Task TestCascadeDeleteCompanySomeQuotePriceDifferentUserIdOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

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

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

                //ATTEMPT
                var status = await service.SetCascadeSoftDeleteAsync(company);

                //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);
            }
        }
        public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

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

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(7 + 6);
            }
        }
        public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

                //ATTEMPT
                var numInnerSoftDelete = (await service.SetCascadeSoftDeleteAsync(context.Employees.Single(x => x.Name == "ProjectManager1"))).Result;
                numInnerSoftDelete.ShouldEqual(3 + 3);
                var status = await service.SetCascadeSoftDeleteAsync(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 });
            }
        }
        public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

                //ATTEMPT
                var ex = await Assert.ThrowsAsync <InvalidOperationException>(
                    async() => await service.SetCascadeSoftDeleteAsync(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.");
            }
        }
        public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

                //ATTEMPT
                var status = await service.CheckCascadeSoftDeleteAsync(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.");
            }
        }
        public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);
                (await service.SetCascadeSoftDeleteAsync(ceo.WorksFromMe.First())).IsValid.ShouldBeTrue();

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

                //VERIFY
                softDeleted.Count.ShouldEqual(1);
                softDeleted.Single().Name.ShouldEqual(ceo.WorksFromMe.First().Name);
            }
        }
        public async Task 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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);

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

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                logs.Count(x => _selectMatchRegex.IsMatch(x)).ShouldEqual(selectCount);
                status.Result.ShouldEqual(7 + 6);

                context.ChangeTracker.Clear();
                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 });
            }
        }
        public async Task TestGetSoftDeletedEntriesCompanyOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

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

                var config  = new ConfigCascadeDeleteWithUserId(context);
                var service = new CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);
                var status  = await service.SetCascadeSoftDeleteAsync(company);

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

                //VERIFY
                softDeleted.Count.ShouldEqual(1);
                softDeleted.Single().CompanyName.ShouldEqual(company.CompanyName);
            }
        }
        public async Task TestCascadeDeleteCompanyOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

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

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

                //ATTEMPT
                var status = await service.SetCascadeSoftDeleteAsync(company);

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(1 + 4 + 4 + (4 * 4));
                status.Message.ShouldEqual("You have soft deleted an entity and its 24 dependents");
            }
        }
        public async Task TestCheckCascadeSoftOfPreviousDeleteInfo()
        {
            //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 CascadeSoftDelServiceAsync <ICascadeSoftDelete>(config);
                var numSoftDeleted = (await service.SetCascadeSoftDeleteAsync(context.Employees.Single(x => x.Name == "CTO"))).Result;
                numSoftDeleted.ShouldEqual(7 + 6);
                Employee.ShowHierarchical(ceo, x => _output.WriteLine(x), false);

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

                //VERIFY
                status.Result.ShouldEqual(7 + 6);
                status.Message.ShouldEqual("Are you sure you want to hard delete this entity and its 12 dependents");
            }
        }