public void Find_ShouldReturnAllPostsMatchingPredicate()
        {
            var posts = new List <BlogPost> {
                new BlogPost {
                    BlogPostId = Guid.NewGuid(), Title = "The First Post"
                },
                new BlogPost {
                    BlogPostId = Guid.NewGuid(), Title = "The Second Post"
                },
                new BlogPost {
                    BlogPostId = Guid.NewGuid(), Title = "The Third Post"
                },
                new BlogPost {
                    BlogPostId = Guid.NewGuid(), Title = "The Fourth Post"
                }
            };

            _inMemoryContext.Posts.AddRange(posts);
            _inMemoryContext.SaveChanges();

            Expression <Func <IBlogPost, bool> > predicate = post =>
                                                             post.Title.Contains("ir");

            var expected = new List <IBlogPost> {
                posts[0], posts[2]
            };

            _blogPostRepository.Find(predicate).Result.Should().BeEquivalentTo(expected,
                                                                               "because we expect to get all the posts stored in the database");
        }
Exemplo n.º 2
0
 public ActionResult <Post> GetBlogPost(long id)
 {
     return(Ok(_postRepository.Find(id)));
 }