public async Task TestSoftDeleteServiceSetSoftDddDeleteViaKeysOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

            using (var context = new SingleSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var bookDdd = new BookDDD("Test");
                context.Add(bookDdd);
                context.SaveChanges();

                var config  = new ConfigSoftDeleteDDD(context);
                var service = new SingleSoftDeleteServiceAsync <ISingleSoftDeletedDDD>(config);

                //ATTEMPT
                var status = await service.SetSoftDeleteViaKeysAsync <BookDDD>(bookDdd.Id);

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(1);
            }
            using (var context = new SingleSoftDelDbContext(options))
            {
                context.BookDdds.Count().ShouldEqual(0);
                context.BookDdds.IgnoreQueryFilters().Count().ShouldEqual(1);
            }
        }
        public void TestCanFilterUsingAccessorOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

            using (var context = new SingleSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var book = new Book {
                    Title = "test", SoftDeleted = true
                };
                context.Add(book);
                context.SaveChanges();

                var config = new ConfigSoftDeleteWithUserId(context);

                //ATTEMPT
                var getSoftValue = config.GetSoftDeleteValue.Compile().Invoke(book);
                getSoftValue.ShouldBeTrue();
                var query = context.Books.IgnoreQueryFilters().Where(config.GetSoftDeleteValue).Cast <Book>()
                            .Select(x => x.Title.Length);
                var result = query.ToList();

                //VERIFY
                _output.WriteLine(query.ToQueryString());
                result.Count.ShouldEqual(1);
            }
        }
        public void TestSetSoftDeleteOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

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

            context.Add(shadowClass);
            context.SaveChanges();

            context.ChangeTracker.Clear();

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

            //ATTEMPT
            var status = service.SetSoftDeleteViaKeys <ShadowDelClass>(shadowClass.Id);

            //VERIFY
            status.IsValid.ShouldBeTrue(status.GetAllErrors());
            status.Result.ShouldEqual(1);
            context.ShadowDelClasses.Count().ShouldEqual(0);
            context.ShadowDelClasses.IgnoreQueryFilters().Count().ShouldEqual(1);
        }
示例#4
0
        public async Task TestSoftDeleteAsyncOrderWithAddressOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

            using var context = new SingleSoftDelDbContext(options);
            context.Database.EnsureCreated();
            context.Add(new Order
            {
                OrderRef    = "123",
                UserAddress = new Address {
                    FullAddress = "xxx"
                }
            });
            context.SaveChanges();

            context.ChangeTracker.Clear();

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

            //ATTEMPT
            var status = await service.SetSoftDeleteViaKeysAsync <Order>(1);

            //VERIFY
            status.IsValid.ShouldBeTrue(status.GetAllErrors());
            context.Orders.Count().ShouldEqual(0);
            context.Addresses.Count().ShouldEqual(1);
        }
        public void TestSoftDeleteServiceDddResetSoftDeleteOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

            using (var context = new SingleSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                context.Database.EnsureCreated();
                var bookDdd = new BookDDD("Test");
                context.Add(bookDdd);
                context.SaveChanges();

                var config  = new ConfigSoftDeleteDDD(context);
                var service = new SingleSoftDeleteService <ISingleSoftDeletedDDD>(config);
                service.SetSoftDelete(bookDdd);

                //ATTEMPT
                var status = service.ResetSoftDelete(bookDdd);

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(1);

                context.ChangeTracker.Clear();
                context.BookDdds.Count().ShouldEqual(1);
                context.BookDdds.IgnoreQueryFilters().Count().ShouldEqual(1);
            }
        }
示例#6
0
        public static Book AddBookWithReviewToDb(this SingleSoftDelDbContext context, string title = "test")
        {
            var book = new Book
            {
                Title = title, Reviews = new List <Review> {
                    new Review {
                        NumStars = 1
                    }
                }
            };

            context.Add(book);
            context.SaveChanges();
            return(book);
        }
        public void TestManuallySoftDeleteOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

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

            context.Add(shadowClass);
            context.SaveChanges();

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

            //VERIFY
            context.ShadowDelClasses.Count().ShouldEqual(0);
            context.ShadowDelClasses.IgnoreQueryFilters().Count().ShouldEqual(1);
        }
        public void TestResetSoftDeleteOk()
        {
            //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();

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

            //ATTEMPT
            var status = service.ResetSoftDelete(shadowClass);

            //VERIFY
            status.IsValid.ShouldBeTrue(status.GetAllErrors());
            status.Result.ShouldEqual(1);
            context.ShadowDelClasses.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);
        }