public async Task TestSoftDeleteServiceSetSoftDeleteOk()
        {
            //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 SingleSoftDeleteServiceAsync <ISingleSoftDelete>(config);

                //ATTEMPT
                var status = await service.SetSoftDeleteAsync(book);

                //VERIFY
                status.IsValid.ShouldBeTrue(status.GetAllErrors());
                status.Result.ShouldEqual(1);
            }
            using (var context = new SingleSoftDelDbContext(options))
            {
                context.Books.Count().ShouldEqual(0);
                context.Books.IgnoreQueryFilters().Count().ShouldEqual(1);
            }
        }
        public async Task 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(context);
                var service = new SingleSoftDeleteServiceAsync <ISingleSoftDeletedDDD>(config);

                //ATTEMPT
                var status = await service.SetSoftDeleteAsync(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);
            }
        }
Exemplo n.º 3
0
        public async Task 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 config1  = new ConfigSoftDeleteWithUserId(context);
                var service1 = new SingleSoftDeleteServiceAsync <ISingleSoftDelete>(config1);
                var status   = await service1.SetSoftDeleteAsync(book1);

                status.IsValid.ShouldBeTrue(status.GetAllErrors());

                context.ChangeTracker.Clear();

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

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

                //VERIFY
                softDelBooks.Count.ShouldEqual(1);
                softDelBooks.Single().Title.ShouldEqual("test1");
                context.Books.Count().ShouldEqual(1);
                context.Books.IgnoreQueryFilters().Count().ShouldEqual(2);
            }
        }
        public async Task 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 SingleSoftDeleteServiceAsync <ISingleSoftDelete>(config);
                var status1 = await service.SetSoftDeleteAsync(book);

                status1.IsValid.ShouldBeTrue(status1.GetAllErrors());

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

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