public void GetCountOfPostsShouldWorkCorrectly() { var posts = new List <Post>(); var mockPostRepo = new Mock <IDeletableEntityRepository <Post> >(); mockPostRepo.Setup(x => x.All()).Returns(posts.AsQueryable()); mockPostRepo.Setup(x => x.AddAsync(It.IsAny <Post>())).Callback((Post post) => posts.Add(post)); var service = new AdminsService(mockPostRepo.Object, null, null, null, null); var post = new Post { Id = "1", Title = "Can you help me", Content = "I am 16 yo and...", }; posts.Add(post); var result = service.GetCountOfPosts(); var expectedResult = 1; Assert.Equal(expectedResult, result); }