示例#1
0
        public void TestSoftDeleteServiceGetSoftDeletedEntriesOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

            using (var context = new SingleSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var book1 = context.AddBookWithReviewToDb("test1");
                var book2 = context.AddBookWithReviewToDb("test2");

                var config  = new ConfigSoftDeleteWithUserId(context);
                var service = new SingleSoftDeleteService <ISingleSoftDelete>(context, config);
                var status  = service.SetSoftDelete(book1);
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
            }
            using (var context = new SingleSoftDelDbContext(options))
            {
                var config  = new ConfigSoftDeleteWithUserId(context);
                var service = new SingleSoftDeleteService <ISingleSoftDelete>(context, config);

                //ATTEMPT
                var softDelBooks = service.GetSoftDeletedEntries <Book>().ToList();

                //VERIFY
                softDelBooks.Count.ShouldEqual(1);
                softDelBooks.Single().Title.ShouldEqual("test1");
                context.Books.Count().ShouldEqual(1);
                context.Books.IgnoreQueryFilters().Count().ShouldEqual(2);
            }
        }
        public void TestSoftDeleteServiceGetSoftDeletedEntriesWithUserIdOk()
        {
            //SETUP
            var currentUser = Guid.NewGuid();
            var options     = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

            using (var context = new SingleSoftDelDbContext(options, currentUser))
            {
                context.Database.EnsureCreated();
                var order1 = new Order
                {
                    OrderRef = "Cur user Order, soft del", SoftDeleted = true, UserId = currentUser
                };
                var order2 = new Order
                {
                    OrderRef = "Cur user Order", SoftDeleted = false, UserId = currentUser
                };
                var order3 = new Order
                {
                    OrderRef = "Diff user Order", SoftDeleted = true, UserId = Guid.NewGuid()
                };
                var order4 = new Order
                {
                    OrderRef = "Diff user Order", SoftDeleted = false, UserId = Guid.NewGuid()
                };
                context.AddRange(order1, order2, order3, order4);
                context.SaveChanges();

                context.ChangeTracker.Clear();

                var config  = new ConfigSoftDeleteWithUserId(context);
                var service = new SingleSoftDeleteService <ISingleSoftDelete>(config);

                //ATTEMPT
                var orders = service.GetSoftDeletedEntries <Order>().ToList();

                //VERIFY
                orders.Count.ShouldEqual(1);

                context.ChangeTracker.Clear();
                orders.Single(x => x.UserId == currentUser).OrderRef.ShouldEqual("Cur user Order, soft del");
                context.Orders.IgnoreQueryFilters().Count().ShouldEqual(4);
                var all = context.Orders.IgnoreQueryFilters().ToList();
                context.Orders.Count().ShouldEqual(1);
            }
        }
        public void TestGetSoftDeleteOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

            using var context = new SingleSoftDelDbContext(options);
            context.Database.EnsureCreated();
            var shadowClass = new ShadowDelClass();

            context.Add(shadowClass);
            context.Entry(shadowClass).Property("SoftDeleted").CurrentValue = true;
            context.SaveChanges();

            context.ChangeTracker.Clear();

            var config  = new ConfigSoftDeleteShadowDel(context);
            var service = new SingleSoftDeleteService <IShadowSoftDelete>(config);

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

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