コード例 #1
0
        public async Task TestSoftDeleteServiceResetSoftDeleteViaKeysOk()
        {
            //SETUP
            int bookId;
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

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

                var config  = new ConfigSoftDeleteWithUserId(context);
                var service = new SingleSoftDeleteServiceAsync <ISingleSoftDelete>(config);
                var status1 = await service.SetSoftDeleteViaKeysAsync <Book>(bookId);

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

                //ATTEMPT
                var status2 = await service.ResetSoftDeleteViaKeysAsync <Book>(bookId);

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

                context.ChangeTracker.Clear();

                context.Books.Count().ShouldEqual(1);
                context.Books.IgnoreQueryFilters().Count().ShouldEqual(1);
            }
        }
コード例 #2
0
        public async Task <IActionResult> UnSoftDelete(int id, [FromServices] SingleSoftDeleteServiceAsync <ISoftDelete> service)
        {
            Request.ThrowErrorIfNotLocal();
            var status = await service.ResetSoftDeleteViaKeysAsync <Book>(id);

            SetupTraceInfo();
            return(View("BookUpdated", status.IsValid ? status.Message : status.GetAllErrors()));
        }
コード例 #3
0
        public async Task TestResetSoftDeleteViaKeysAsyncWithWrongUserIdBad()
        {
            //SETUP
            var currentUser = Guid.NewGuid();
            int orderId;
            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();
                orderId = order3.Id;

                context.ChangeTracker.Clear();

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

                //ATTEMPT
                var status = await service.ResetSoftDeleteViaKeysAsync <Order>(orderId);

                //VERIFY
                status.IsValid.ShouldBeFalse();
                status.GetAllErrors().ShouldEqual("Could not find the entry you ask for.");
                context.Orders.IgnoreQueryFilters().Count().ShouldEqual(4);
                context.Orders.Count().ShouldEqual(1);
            }
        }