예제 #1
0
        public async Task AllPosts()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "AllPosts_Database")
                          .Options;
            var dbContext   = new ApplicationDbContext(options);
            var postService = new PostService(dbContext);

            await postService.CreatePostAsync("Tweets", "Hello i am tweet", "u1", 1);

            await postService.CreatePostAsync("Tweets2", "Hello i am tweet2", "u1", 1);

            var allPosts  = postService.AllPosts(null, null);
            var firstPost = await allPosts.FirstAsync();

            Assert.Equal("Tweets", firstPost.Title);
            Assert.Equal("Hello i am tweet", firstPost.Content);
            Assert.Equal("u1", firstPost.UserId);
            Assert.Equal(2, await allPosts.CountAsync());
        }