public async Task GetByUserIdShouldReturnCount2() { var comments = new List <Comment>(); var mockCommentRepo = new Mock <IDeletableEntityRepository <Comment> >(); mockCommentRepo.Setup(x => x.All()).Returns(comments.AsQueryable()); mockCommentRepo.Setup(x => x.AddAsync(It.IsAny <Comment>())).Callback((Comment comm) => comments.Add(comm)); var service = new CommentsService(mockCommentRepo.Object, null, null); var comment = new Comment { Id = "1", PhotoId = "1", Content = "Test", }; var secondComment = new Comment { Id = "2", PhotoId = "1", Content = "Another test", }; comments.Add(comment); comments.Add(secondComment); var countOfCommentsByUser = service.GetByUserId <CommentViewModel>("1"); var expectedResult = 2; Assert.Equal(expectedResult, countOfCommentsByUser.Count()); }
public async void TestCreateAsync() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new EfDeletableEntityRepository <Comment>(new ApplicationDbContext(options.Options)); var commentsService = new CommentsService(repository); var userId = Guid.NewGuid().ToString(); await commentsService.Create(1, userId, "testContent", 0); AutoMapperConfig.RegisterMappings(typeof(MyTestComment).Assembly); var comment = commentsService.GetByUserId <MyTestComment>(userId).FirstOrDefault(); Assert.Equal("testContent", comment.Content); }