public async void CanFindAllPosts() { DbContextOptions <DotNetgramDBContext> options = new DbContextOptionsBuilder <DotNetgramDBContext>().UseInMemoryDatabase("FindPosts").Options; using (DotNetgramDBContext context = new DotNetgramDBContext(options)) { Post testPost1 = CreatePost(); Post testPost2 = CreatePost(); testPost2.ID = 2; List <Post> listPosts = new List <Post> { testPost1, testPost2 }; PostManagementService postService = new PostManagementService(context); await postService.SaveAsync(testPost1); await postService.SaveAsync(testPost2); IEnumerable <Post> expected = listPosts; IEnumerable <Post> actual = await postService.GetPosts(); Assert.Equal(expected, actual); } }
public async void CanCreatePost() { DbContextOptions <DotNetgramDBContext> options = new DbContextOptionsBuilder <DotNetgramDBContext>().UseInMemoryDatabase("CreatePost").Options; using (DotNetgramDBContext context = new DotNetgramDBContext(options)) { Post testPost = CreatePost(); PostManagementService postService = new PostManagementService(context); await postService.SaveAsync(testPost); var result = context.Posts.FirstOrDefault(a => a.ID == testPost.ID); Assert.Equal(testPost, result); } }
public PostManagementService(DotNetgramDBContext context) { _context = context; }