public async void password_change_should_return_with_password_change_model_if_model_is_valid() { // Arrange const string actionName = "PasswordChange"; const string email = "*****@*****.**"; const string token = "token"; const string password = "******"; var validModel = new PasswordChangeModel { Email = email, Password = password, Token = token }; var userService = new Mock<IUserService>(); userService.Setup(x => x.IsPasswordResetRequestValid(email, token)) .Returns(() => Task.FromResult(true)); userService.Setup(x => x.ChangePassword(email, token, password)) .Returns(() => Task.FromResult(true)); var formsAuthenticationService = new Mock<IFormsAuthenticationService>(); formsAuthenticationService.Setup(x => x.SignOut()); // Act var sut = new UserControllerBuilder().WithUserService(userService.Object) .WithFormsAuthenticationService(formsAuthenticationService.Object) .BuildWithMockControllerContext(); var view = await sut.PasswordChange(validModel) as ViewResult; // Assert Assert.NotNull(view); Assert.NotNull(view.Model); Assert.IsInstanceOf<BaseController>(sut); Assert.IsAssignableFrom<PasswordChangeModel>(view.Model); userService.Verify(x => x.IsPasswordResetRequestValid(email, token), Times.Once); userService.Verify(x => x.ChangePassword(email, token, password), Times.Once); formsAuthenticationService.Verify(x => x.SignOut(), Times.Once); sut.AssertPostAttribute(actionName, new[] { typeof(PasswordChangeModel) }); sut.AssertAllowAnonymousAttribute(actionName, new[] { typeof(PasswordChangeModel) }); }
public async void password_change_should_return_with_password_change_model() { // Arrange const string actionName = "PasswordChange"; const string email = "*****@*****.**"; const string token = "token"; var userService = new Mock<IUserService>(); userService.Setup(x => x.IsPasswordResetRequestValid(email, token)) .Returns(() => Task.FromResult(true)); // Act var sut = new UserControllerBuilder().WithUserService(userService.Object) .Build(); var task = await sut.PasswordChange(email, token); var view = task as ViewResult; // Assert Assert.NotNull(view); Assert.NotNull(view.Model); Assert.IsInstanceOf<BaseController>(sut); Assert.IsAssignableFrom<PasswordChangeModel>(view.Model); sut.AssertGetAttribute(actionName, new[] { typeof(string), typeof(string) }); sut.AssertAllowAnonymousAttribute(actionName, new[] { typeof(string), typeof(string) }); }