public async void CannotDeletePost() { DbContextOptions <PostDbContext> options = new DbContextOptionsBuilder <PostDbContext>().UseInMemoryDatabase("CanotDeletePost").Options; using (PostDbContext context = new PostDbContext(options)) { PostManager postService = new PostManager(context); Post post = new Post(); post.Author = "John"; post.ImageURL = "test.img"; post.Caption = "Read me!"; await postService.SaveAsync(post); Post postTwo = new Post(); postTwo.Author = "Bob"; postTwo.ImageURL = "new.img"; postTwo.Caption = "Hello world!"; await postService.SaveAsync(postTwo); Post postThree = new Post(); postThree.Author = "Tim"; postThree.ImageURL = "house.img"; postThree.Caption = "Hi!"; await postService.SaveAsync(postThree); await postService.DeleteAsync(4); var result = await context.Posts.ToListAsync(); Assert.Equal(3, result.Count); } }
public async void CanDeletePostTest() { //testing post manger service DbContextOptions <PostDbContext> options = new DbContextOptionsBuilder <PostDbContext>().UseInMemoryDatabase("Create").Options; using (PostDbContext context = new PostDbContext(options)) { //arrange Post post = new Post(); post.ID = 1; post.Title = "Fun"; post.Caption = "in the sun"; post.URL = "www.funinthesun.com"; //act PostManager postservice = new PostManager(context); await postservice.SaveAsync(post); await postservice.DeleteAsync(1); var result = context.Posts.FirstOrDefault(p => p.ID == 1); //assert Assert.Null(result); } }
public async void TestPostCanDelete() { ///Test that you can delete a post DbContextOptions <GramDbContext> options = new DbContextOptionsBuilder <GramDbContext>().UseInMemoryDatabase("DeletePost").Options; using (GramDbContext context = new GramDbContext(options)) { Post post = new Post(); PostManager manager = new PostManager(context); post.ID = 4; post.Details = "Cray"; post.Author = "JTT"; await manager.SaveAsync(post); await manager.DeleteAsync(post.ID); Assert.Null(await manager.FindPost(post.ID)); } }