예제 #1
0
        public static async Task DeletePostGenericDirectAsync(this SampleWebAppDb db, int postId)
        {
            var service = new DeleteServiceAsync(db);
            var status  = await service.DeleteAsync <Post>(postId);

            status.IsValid.ShouldEqual(true, status.Errors);
        }
예제 #2
0
        public void Check01DirectReferenceOk()
        {
            //SETUP

            //ATTEMPT
            ICreateServiceAsync <Post> createService = new CreateServiceAsync <Post>(null);
            IDetailServiceAsync <Post> detailService = new DetailServiceAsync <Post>(null);
            IDeleteServiceAsync        deleteService = new DeleteServiceAsync(null);
            IUpdateServiceAsync <Post> updateService = new UpdateServiceAsync <Post>(null);

            //VERIFY
            (updateService is IUpdateServiceAsync <Post>).ShouldEqual(true);
        }
        public void Test41DeleteWithRelationshipsViaDtoBad()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new DeleteServiceAsync(db);

                //ATTEMPT
                var ex = Assert.Throws <InvalidOperationException>(async() => await service.DeleteWithRelationshipsAsync <SimplePostDto>(DeleteBloggerWithPostAsync, 0));

                //VERIFY
                ex.Message.ShouldEqual("The entity type SimplePostDto is not part of the model for the current context.");
            }
        }
        public void Check01DirectReferenceOk()
        {

            //SETUP    

            //ATTEMPT
            ICreateServiceAsync<Post> createService = new CreateServiceAsync<Post>(null);
            IDetailServiceAsync<Post> detailService = new DetailServiceAsync<Post>(null);
            IDeleteServiceAsync deleteService = new DeleteServiceAsync(null);
            IUpdateServiceAsync<Post> updateService = new UpdateServiceAsync<Post>(null);

            //VERIFY
            (updateService is IUpdateServiceAsync<Post>).ShouldEqual(true);
        }
예제 #5
0
        public async void Check11DeleteWithRelationshipsDirectOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var snap = new DbSnapShot(db);
                var firstPostUntracked = db.Posts.AsNoTracking().First();
                var service            = new DeleteServiceAsync(db);

                //ATTEMPT
                var status = await service.DeleteWithRelationshipsAsync <Post>(DeleteBloggerWithPost, firstPostUntracked.PostId);

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.SuccessMessage.ShouldEqual("Successfully deleted Post and given relationships.");
                snap.CheckSnapShot(db, -1, -2, -1, 0, -2);
            }
        }
예제 #6
0
        public async void Check12DeleteWithRelationshipsDirectFailOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var snap = new DbSnapShot(db);
                var firstPostUntracked = db.Posts.AsNoTracking().First();
                var service            = new DeleteServiceAsync(db);

                //ATTEMPT
                var status = await service.DeleteWithRelationshipsAsync <Post>(FailDeleteRelationships, firstPostUntracked.PostId);

                //VERIFY
                status.IsValid.ShouldEqual(false);
                status.Errors.Count.ShouldEqual(1);
                status.Errors[0].ErrorMessage.ShouldEqual("I failed.");
                snap.CheckSnapShot(db);
            }
        }
예제 #7
0
 public async Task <ISuccessOrErrors> DeleteAsync(int key)
 {
     return(await DeleteServiceAsync.DeleteAsync <TEntity>(key));
 }
        public async void Check12DeleteWithRelationshipsDirectFailOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var snap = new DbSnapShot(db);
                var firstPostUntracked = db.Posts.AsNoTracking().First();
                var service = new DeleteServiceAsync(db);

                //ATTEMPT
                var status = await service.DeleteWithRelationshipsAsync<Post>(FailDeleteRelationships, firstPostUntracked.PostId);

                //VERIFY
                status.IsValid.ShouldEqual(false);
                status.Errors.Count.ShouldEqual(1);
                status.Errors[0].ErrorMessage.ShouldEqual("I failed.");
                snap.CheckSnapShot(db);
            }
        }
        public async void Check11DeleteWithRelationshipsDirectOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var snap = new DbSnapShot(db);
                var firstPostUntracked = db.Posts.AsNoTracking().First();
                var service = new DeleteServiceAsync(db);

                //ATTEMPT
                var status = await service.DeleteWithRelationshipsAsync<Post>(DeleteBloggerWithPost, firstPostUntracked.PostId);

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.SuccessMessage.ShouldEqual("Successfully deleted Post and given relationships.");
                snap.CheckSnapShot(db, -1, -2, -1, 0, -2);
            }
        }
        public void Test41DeleteWithRelationshipsViaDtoBad()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new DeleteServiceAsync(db);

                //ATTEMPT
                var ex = Assert.Throws<InvalidOperationException>(async () => await service.DeleteWithRelationshipsAsync<SimplePostDto>(DeleteBloggerWithPostAsync, 0));

                //VERIFY
                ex.Message.ShouldEqual("The entity type SimplePostDto is not part of the model for the current context.");
            }
        }