public async Task EditPhotoCommentShouldReturnFalse() { var comments = new List <Comment>(); var appUsers = new List <ApplicationUser>(); 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 mockAppUser = new Mock <IDeletableEntityRepository <ApplicationUser> >(); mockAppUser.Setup(x => x.All()).Returns(appUsers.AsQueryable()); mockAppUser.Setup(x => x.AddAsync(It.IsAny <ApplicationUser>())).Callback((ApplicationUser appU) => appUsers.Add(appU)); var service = new CommentsService(mockCommentRepo.Object, null, mockAppUser.Object); var commentToChangeContent = new Comment { Id = "1", UserId = "1", SentById = "1", Content = "Are you crazy?", }; comments.Add(commentToChangeContent); Task result = service.EditPhotoComment("1", "newContent", "2"); Assert.False(result.IsFaulted); }
public async Task EditPhotoCommentShouldWorkCorrectly() { var comments = new List <Comment>(); var appUsers = new List <ApplicationUser>(); 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 mockAppUser = new Mock <IDeletableEntityRepository <ApplicationUser> >(); mockAppUser.Setup(x => x.All()).Returns(appUsers.AsQueryable()); mockAppUser.Setup(x => x.AddAsync(It.IsAny <ApplicationUser>())).Callback((ApplicationUser appU) => appUsers.Add(appU)); var service = new CommentsService(mockCommentRepo.Object, null, mockAppUser.Object); var commentToChangeContent = new Comment { Id = "1", UserId = "1", SentById = "1", Content = "Are you crazy?", }; comments.Add(commentToChangeContent); await service.EditPhotoComment("1", "newContent", "1"); var expectedOutput = "newContent"; Assert.Equal(expectedOutput, commentToChangeContent.Content); }