public async Task TestSoftDeleteServiceSetSoftDeleteViaKeysBadNumberOfKeys()
        {
            //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 ex = await Assert.ThrowsAsync <ArgumentException>(async() => await service.SetSoftDeleteViaKeysAsync <Book>(1, 2));

                //VERIFY
                ex.Message.ShouldEqual("Mismatch in keys: your provided 2 key(s) and the entity has 1 key(s) (Parameter 'keyValues')");
            }
        }
        public async Task TestSoftDeleteServiceSetSoftDeleteViaKeysBadKeyType()
        {
            //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 ex = await Assert.ThrowsAsync <ArgumentException>(async() => await service.SetSoftDeleteViaKeysAsync <Book>(book));

                //VERIFY
                ex.Message.ShouldEqual("Mismatch in keys: your provided key 1 (of 1) is of type Book but entity key's type is System.Int32 (Parameter 'keyValues')");
            }
        }
Exemplo n.º 3
0
        public async Task TestSoftDeleteServiceSetSoftDeleteOneToOneBad()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

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

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

                //ATTEMPT
                var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.SetSoftDeleteViaKeysAsync <OneToOne>(1));

                //VERIFY
                ex.Message.ShouldEqual("You cannot soft delete a one-to-one relationship. It causes problems if you try to create a new version.");
            }
        }
        public async Task TestSoftDeleteServiceSetSoftDeleteViaKeysNotFoundBad()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

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

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

                //ATTEMPT
                var status = await service.SetSoftDeleteViaKeysAsync <Book>(123);

                //VERIFY
                status.IsValid.ShouldBeFalse();
                status.GetAllErrors().ShouldEqual("Could not find the entry you ask for.");
                status.Result.ShouldEqual(0);
            }
        }
        public async Task TestSoftDeleteServiceSetSoftDeleteViaKeysNotFoundReturnsZero()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <SingleSoftDelDbContext>();

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

                var config = new ConfigSoftDeleteWithUserId(context)
                {
                    NotFoundIsNotAnError = true
                };
                var service = new SingleSoftDeleteServiceAsync <ISingleSoftDelete>(config);

                //ATTEMPT
                var status = await service.SetSoftDeleteViaKeysAsync <Book>(123);

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