public void TestAddCommentToLog_ShouldCallLogServiceAddCommentToLogCorrectly(string content, int logId, string userId) { // Arrange var mockedLogService = new Mock <ILogService>(); var date = new DateTime(); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); mockedDateTimeProvider.Setup(p => p.GetCurrentTime()) .Returns(date); var user = new User(); var mockedUserService = new Mock <IUserService>(); mockedUserService.Setup(s => s.GetUserById(It.IsAny <string>())) .Returns(user); var comment = new Comment(); var mockedCommentFactory = new Mock <ICommentFactory>(); mockedCommentFactory.Setup(f => f.CreateComment(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <User>())) .Returns(comment); var mockedRepository = new Mock <IRepository <Comment> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var service = new CommentService(mockedLogService.Object, mockedDateTimeProvider.Object, mockedUserService.Object, mockedCommentFactory.Object, mockedRepository.Object, mockedUnitOfWork.Object); // Act service.AddCommentToLog(content, logId, userId); // Assert mockedLogService.Verify(s => s.AddCommentToLog(logId, comment), Times.Once); }
public void TestAddCommentToLog_ShouldUserServiceGetUserByIdCorrectly(string content, int logId, string userId) { // Arrange var mockedLogService = new Mock <ILogService>(); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var mockedUserService = new Mock <IUserService>(); var mockedCommentFactory = new Mock <ICommentFactory>(); var mockedRepository = new Mock <IRepository <Comment> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var service = new CommentService(mockedLogService.Object, mockedDateTimeProvider.Object, mockedUserService.Object, mockedCommentFactory.Object, mockedRepository.Object, mockedUnitOfWork.Object); // Act service.AddCommentToLog(content, logId, userId); // Assert mockedUserService.Verify(s => s.GetUserById(userId), Times.Once); }