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

            using (var context = new SingleSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var book = context.AddBookWithReviewToDb();

                var config  = new ConfigSoftDeleteWithUserId(context);
                var service = new SingleSoftDeleteService <ISingleSoftDelete>(context, config);
                var status  = service.SetSoftDelete(book);
                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 status = service.HardDeleteViaKeys <Book>(context.Books.IgnoreQueryFilters().Single().Id);

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(1);
            }
            using (var context = new SingleSoftDelDbContext(options))
            {
                context.Books.IgnoreQueryFilters().Count().ShouldEqual(0);
            }
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        public void TestSoftDeleteServiceDddSetSoftDeleteOk()
        {
            //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();
                var service = new SingleSoftDeleteService <ISingleSoftDeletedDDD>(context, config);

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

                //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 TestSoftDeleteServiceResetSoftDeleteNoCallSaveChangesOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

            using (var context = new SingleSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var book = context.AddBookWithReviewToDb();

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

                //ATTEMPT
                var status = service.ResetSoftDelete(book, false);
                context.Books.Count().ShouldEqual(0);
                context.SaveChanges();
                context.Books.Count().ShouldEqual(1);

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

                context.ChangeTracker.Clear();
                context.Books.IgnoreQueryFilters().Count().ShouldEqual(1);
            }
        }
Exemple #5
0
        public void TestHardDeleteViaKeysNotFoundOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

            using (var context = new SingleSoftDelDbContext(options))
            {
                context.Database.EnsureCreated();
                var book = context.AddBookWithReviewToDb();

                var config  = new ConfigSoftDeleteWithUserId(context);
                var service = new SingleSoftDeleteService <ISingleSoftDelete>(context, config);
                var status1 = service.SetSoftDelete(book);
                status1.IsValid.ShouldBeTrue(status1.GetAllErrors());

                //ATTEMPT
                var status = service.HardDeleteViaKeys <Book>(234);

                //VERIFY
                status.IsValid.ShouldBeFalse(status.GetAllErrors());
                status.GetAllErrors().ShouldEqual("Could not find the entry you ask for.");
            }
        }