public void _Call_CommentService_AddCommentToPost(int postId, string userId, string content) { //Arrange var model = new AddCommentViewModel() { Content = content, CommentedItemId = postId }; var mockedCommentService = new Mock <ICommentService>(); var mockedAuthProvider = new Mock <IAuthenticationProvider>(); mockedAuthProvider.Setup(a => a.CurrentUserId).Returns(userId); var commentControllerSUT = new CommentController(mockedCommentService.Object, mockedAuthProvider.Object); commentControllerSUT.ModelState.Clear(); //Act var res = commentControllerSUT.CommentPost(model) as ActionResult; //Assert mockedCommentService.Verify(s => s.AddCommentToPost(model.Content, model.CommentedItemId, userId)); }
public void _Return_Correct_Controller_RedirectToAction_AddCommentToPost(int postId, string userId, string content) { //Arrange var model = new AddCommentViewModel() { Content = content, CommentedItemId = postId }; var mockedCommentService = new Mock <ICommentService>(); var mockedAuthProvider = new Mock <IAuthenticationProvider>(); mockedAuthProvider.Setup(a => a.CurrentUserId).Returns(userId); var commentControllerSUT = new CommentController(mockedCommentService.Object, mockedAuthProvider.Object); commentControllerSUT.ModelState.Clear(); //Act var res = commentControllerSUT.CommentPost(model) as RedirectToRouteResult; //Assert Assert.AreEqual("Post", res.RouteValues["controller"]); }
public void _Call_AuthProvider_CurrentUserId() { //Arrange var model = new AddCommentViewModel(); var mockedCommentService = new Mock <ICommentService>(); var mockedAuthProvider = new Mock <IAuthenticationProvider>(); var commentControllerSUT = new CommentController(mockedCommentService.Object, mockedAuthProvider.Object); commentControllerSUT.ModelState.Clear(); //Act var res = commentControllerSUT.CommentPost(model) as ActionResult; //Assert mockedAuthProvider.Verify(a => a.CurrentUserId, Times.Once); }