Exemplo n.º 1
0
 public void ForgotPasswordShoudCatchAndReturnViewWithError(PasswordResetInfo model, [Frozen] IAccountRepository repo, INotificationService notificationService, IAccountsSettingsService settingService)
 {
     var fakeSite = new FakeSiteContext(new StringDictionary
       {
     {
       "displayMode", "normal"
     }
       }) as SiteContext;
       using (new SiteContextSwitcher(fakeSite))
       {
     repo.RestorePassword(Arg.Any<string>()).ThrowsForAnyArgs(new Exception("Error"));
     repo.Exists(Arg.Any<string>()).Returns(true);
     var controller = new AccountsController(repo, notificationService, settingService);
     var result = controller.ForgotPassword(model);
     result.Should().BeOfType<ViewResult>().Which.Model.Should().Be(model);
     result.Should().BeOfType<ViewResult>().Which.ViewData.ModelState.Should().ContainKey(nameof(model.Email))
       .WhichValue.Errors.Should().Contain(x => x.ErrorMessage == "Error");
       }
 }
 public void ForgotPasswordShouldRedirectLoggedUser(PasswordResetInfo model, IAccountRepository repo, INotificationService ns)
 {
     var fakeSite = new FakeSiteContext(new StringDictionary
       {
     {
       "displayMode", "normal"
     }
       }) as SiteContext;
       using (new SiteContextSwitcher(fakeSite))
       {
     using (new UserSwitcher(@"extranet\fake", true))
     {
       repo.RestorePassword(Arg.Any<string>()).Returns("new password");
       repo.Exists(Arg.Any<string>()).Returns(true);
       var controller = new AccountsController(repo, ns);
       var result = controller.ForgotPassword(model);
       result.Should().BeOfType<RedirectResult>();
     }
       }
 }
 public void ForgotPasswordShouldReturnModelIfUserNotExist(PasswordResetInfo model, [Frozen] IAccountRepository repo)
 {
     var fakeSite = new FakeSiteContext(new StringDictionary
       {
     {
       "displayMode", "normal"
     }
       }) as SiteContext;
       using (new SiteContextSwitcher(fakeSite))
       {
     repo.RestorePassword(Arg.Any<string>()).Returns("new password");
     repo.Exists(Arg.Any<string>()).Returns(false);
     var controller = new AccountsController(repo, null);
     var result = controller.ForgotPassword(model);
     result.Should().BeOfType<ViewResult>().Which.Model.Should().Be(model);
     result.Should().BeOfType<ViewResult>().Which.ViewData.ModelState.Should().ContainKey(nameof(model.Email))
       .WhichValue.Errors.Should().Contain(x => x.ErrorMessage == Errors.UserDoesNotExist);
       }
 }
 public void ForgotPasswordShouldReturnSuccessView([Frozen] IAccountRepository repo, INotificationService ns, PasswordResetInfo model)
 {
     var fakeSite = new FakeSiteContext(new StringDictionary
       {
     {
       "displayMode", "normal"
     }
       }) as SiteContext;
       using (new SiteContextSwitcher(fakeSite))
       {
     var controller = new AccountsController(repo, ns);
     repo.RestorePassword(Arg.Any<string>()).Returns("new password");
     repo.Exists(Arg.Any<string>()).Returns(true);
     var result = controller.ForgotPassword(model);
     result.Should().BeOfType<ViewResult>().Which.ViewName.Should().Be("ForgotPasswordSuccess");
       }
 }