public void _Call_UserService_GetUserById(string text, int newsId, string userId) { //Arrange var mockedPostService = new Mock <IPostService>(); var mockedNewsService = new Mock <INewsService>(); var mockedUserService = new Mock <IUserService>(); var mockedCommentFactory = new Mock <ICommentFactory>(); var mockedRepository = new Mock <IRepository <Comment> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var commentService = new CommentService( mockedPostService.Object, mockedNewsService.Object, mockedCommentFactory.Object, mockedUserService.Object, mockedRepository.Object, mockedDateTimeProvider.Object, mockedUnitOfWork.Object); //Act commentService.AddCommentToNews(text, newsId, userId); //Assert mockedUserService.Verify(d => d.GetUserById(userId), Times.Once); }
public void _Call_NewsService_AddComment(string text, int newsId, string userId) { //Arrange var user = new User(); var date = new DateTime(); var comment = new Comment(); var mockedPostService = new Mock <IPostService>(); var mockedNewsService = new Mock <INewsService>(); var mockedUserService = new Mock <IUserService>(); mockedUserService.Setup(u => u.GetUserById(It.IsAny <string>())).Returns(user); var mockedCommentFactory = new Mock <ICommentFactory>(); mockedCommentFactory.Setup(c => c.CreateComment(It.IsAny <User>(), It.IsAny <DateTime>(), It.IsAny <string>())) .Returns(comment); var mockedRepository = new Mock <IRepository <Comment> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); mockedDateTimeProvider.Setup(d => d.GetCurrentDate()).Returns(date); var commentService = new CommentService( mockedPostService.Object, mockedNewsService.Object, mockedCommentFactory.Object, mockedUserService.Object, mockedRepository.Object, mockedDateTimeProvider.Object, mockedUnitOfWork.Object); //Act commentService.AddCommentToNews(text, newsId, userId); //Assert mockedNewsService.Verify(d => d.AddComment(newsId, comment), Times.Once); }