public void TestComment_ShouldCallAuthenticationProviderCurrentUserId() { // Arrange var model = new NewCommentViewModel(); var mockedService = new Mock <ICommentService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var controller = new CommentController(mockedService.Object, mockedAuthenticationProvider.Object); // Act controller.Comment(model); // Assert mockedAuthenticationProvider.Verify(p => p.CurrentUserId, Times.Once); }
public void TestComment_ModelStateIsNotValid_ShouldNotCallAuthenticationProviderCurrentUserId() { // Arrange var model = new NewCommentViewModel(); var mockedService = new Mock <ICommentService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var controller = new CommentController(mockedService.Object, mockedAuthenticationProvider.Object); controller.ModelState.AddModelError("", ""); // Act controller.Comment(model); // Assert mockedAuthenticationProvider.Verify(p => p.CurrentUserId, Times.Never); }
public void TestComment_ShouldCallEntryServiceAddEntryToLogCorrectly(int logId, string content, string userId) { // Arrange var model = new NewCommentViewModel { LogId = logId, Content = content }; var mockedService = new Mock <ICommentService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); mockedAuthenticationProvider.Setup(p => p.CurrentUserId).Returns(userId); var controller = new CommentController(mockedService.Object, mockedAuthenticationProvider.Object); // Act controller.Comment(model); // Assert mockedService.Verify(s => s.AddCommentToLog(content, logId, userId), Times.Once); }