public void TestEdit_ShouldCallCommentServiceEditCommentCorrectly(int commentId, string content) { // Arrange var model = new CommentViewModel { CommentId = commentId, Content = content }; var mockedService = new Mock <ICommentService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var controller = new CommentController(mockedService.Object, mockedAuthenticationProvider.Object); // Act controller.Edit(model); // Assert mockedService.Verify(s => s.EditComment(commentId, content), Times.Once); }
public void TestEdit_ShouldSetModelContentCorrectly(int commentId, string content) { // Arrange var model = new CommentViewModel { CommentId = commentId, Content = content }; var mockedService = new Mock <ICommentService>(); mockedService.Setup(s => s.EditComment(It.IsAny <int>(), It.IsAny <string>())) .Returns(new Comment { Content = content }); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var controller = new CommentController(mockedService.Object, mockedAuthenticationProvider.Object); // Act var result = controller.Edit(model) as PartialViewResult; // Assert Assert.AreSame(content, ((CommentViewModel)result.Model).Content); }
public void TestEdit_ModelStateIsNotValid_ShouldNotCallCommentServiceEditCommentCorrectly(int commentId, string content) { // Arrange var model = new CommentViewModel { CommentId = commentId, Content = content }; var mockedService = new Mock <ICommentService>(); mockedService.Setup(s => s.EditComment(It.IsAny <int>(), It.IsAny <string>())) .Returns(new Comment()); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var controller = new CommentController(mockedService.Object, mockedAuthenticationProvider.Object); controller.ModelState.AddModelError("", ""); // Act controller.Edit(model); // Assert mockedService.Verify(s => s.EditComment(It.IsAny <int>(), It.IsAny <string>()), Times.Never); }