Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ListSoftDeleted([FromServices] SingleSoftDeleteServiceAsync <ISoftDelete> service)
        {
            Request.ThrowErrorIfNotLocal();

            var softDeletedBooks = await service.GetSoftDeletedEntries <Book>()
                                   .Select(x => new SimpleBookList {
                BookId = x.BookId, LastUpdatedUtc = x.LastUpdatedUtc, Title = x.Title
            })
                                   .ToListAsync();

            SetupTraceInfo();
            return(View(softDeletedBooks));
        }
Exemplo n.º 3
0
        public async Task 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 SingleSoftDeleteServiceAsync <ISingleSoftDelete>(config);

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

                //VERIFY
                orders.Count.ShouldEqual(1);
                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);
            }
        }