public async void CanFindPostTest() { //testing post manger service DbContextOptions <PostDbContext> options = new DbContextOptionsBuilder <PostDbContext>().UseInMemoryDatabase("CreatePost").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); Post check = context.Posts.FirstOrDefault(p => p.ID == p.ID); Post validate = await postservice.FindPost(1); //assert Assert.Equal(check, validate); } }
public async void CanReadSinglePost() { DbContextOptions <PostDbContext> options = new DbContextOptionsBuilder <PostDbContext>().UseInMemoryDatabase("ReadPost").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 result = await postService.FindPost(post.ID); Assert.Equal(post, result); } }
public async void TestPostCanFind() { ///Test that you can find a post DbContextOptions <GramDbContext> options = new DbContextOptionsBuilder <GramDbContext>().UseInMemoryDatabase("FindPost").Options; using (GramDbContext context = new GramDbContext(options)) { Post post = new Post(); PostManager manager = new PostManager(context); post.ID = 3; post.Details = "Cray"; await manager.SaveAsync(post); Post testPost = await manager.FindPost(post.ID); Assert.Equal(3, testPost.ID); } }
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)); } }
public async void TestPostCanEdit() { ///Test that you can edit a post DbContextOptions <GramDbContext> options = new DbContextOptionsBuilder <GramDbContext>().UseInMemoryDatabase("EditPost").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); post.Details = "Changed cray"; string expected = "Changed cray"; Post testPost = await manager.FindPost(post.ID); Assert.Equal(expected, testPost.Details); } }