ForgotPassword() приватный Метод

private ForgotPassword ( ) : System.Web.Mvc.ActionResult
Результат System.Web.Mvc.ActionResult
    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, null, null, 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 == AccountsController.UserDoesNotExistError);
      }
    }
    public void ForgotPasswordShouldReturnSuccessView([Frozen] IAccountRepository repo, INotificationService ns, PasswordResetInfo model, IAccountsSettingsService accountSetting, InfoMessage info)
    {
      var fakeSite = new FakeSiteContext(new StringDictionary
      {
        {
          "displayMode", "normal"
        }
      }) as SiteContext;

      using (new SiteContextSwitcher(fakeSite))
      {
        var controller = new AccountsController(repo, ns, accountSetting, null, null);
        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(ViewPath.InfoMessage);
      }
    }
    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, null, 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 == "Error");
      }
    }
Пример #4
0
        public void ForgotPassword_ValidData_ShouldReturnViewWithoutModel([Frozen] IAccountRepository repo, INotificationService service, IAccountsSettingsService accountsSettings, MailMessage mailMessage)
        {
            accountsSettings.GetForgotPasswordMailTemplate().ReturnsForAnyArgs(x => mailMessage);
            var controller = new AccountsController(repo, service, accountsSettings, null, null);

            var fakeSite = new FakeSiteContext(new StringDictionary
                                               {
                                                   {"displayMode", "normal"}
                                               }) as SiteContext;
            using (new SiteContextSwitcher(fakeSite))
            {
                var result = controller.ForgotPassword();
                result.Should().BeOfType<ViewResult>().Which.Model.Should().BeNull();
            }
        }