Пример #1
0
        public ActionResult DeletePost(string id)
        {
            PostsManager manager = new PostsManager();

            manager.Delete(int.Parse(id));
            return(RedirectToAction("Index", "Home"));
        }
Пример #2
0
        public async void DeletePost()
        {
            DbContextOptions <PostsDbContext> options = new DbContextOptionsBuilder <PostsDbContext>().UseInMemoryDatabase("ChangePosts").Options;

            using (PostsDbContext context = new PostsDbContext(options))
            {
                PostsManager postService = new PostsManager(context);
                Posts        post        = new Posts();
                post.Author   = "Cat";
                post.ImageURL = "test.img";
                post.Title    = "Seattle";
                await postService.SaveAsync(post);

                Posts post2 = new Posts();
                post.Author   = "Cat";
                post.ImageURL = "test.img";
                post.Title    = "Tacoma";
                await postService.SaveAsync(post);


                await postService.Delete(post2.ID);

                var result = await context.Post.FirstOrDefaultAsync(p => p.ID == post2.ID);

                Assert.Null(result);
            }
        }