コード例 #1
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);
            }
        }
コード例 #2
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.");
                }
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        public void TestCascadeDeleteCompanyQuotesOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

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

                //ATTEMPT
                var customer = Customer.SeedCustomerWithQuotes(context, Guid.Empty);

                //VERIFY
                context.Companies.Count().ShouldEqual(1);
                context.Quotes.Count().ShouldEqual(4);
                context.Set <LineItem>().Count().ShouldEqual(4 * 4);
                context.Set <QuotePrice>().Count().ShouldEqual(4);
            }
        }
コード例 #5
0
        public void TestSeedCompanyWithQuotesOk()
        {
            //SETUP
            var userId  = Guid.NewGuid();
            var options = SqliteInMemory.CreateOptions <CascadeSoftDelDbContext>();

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

                //ATTEMPT
                var customer = Customer.SeedCustomerWithQuotes(context, userId);

                //VERIFY
                context.Companies.Count().ShouldEqual(1);
                context.Quotes.Count().ShouldEqual(4);
                context.Set <QuotePrice>().Count().ShouldEqual(4);
            }
        }