public void ShouldAddErrorToModelStateIfNotLoggedIn([Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, IAccountsSettingsService accountSetting) { repo.Login(string.Empty, string.Empty).ReturnsForAnyArgs(x => false); var controller = new AccountsController(repo, service, accountSetting, null); var result = controller.Login(info); controller.ModelState.IsValid.Should().BeFalse(); controller.ModelState.Keys.Should().Contain("invalidCredentials"); }
public void LoginShouldRedirectToRootIfReturnUrlNotSet(Database db, [Content] DbItem item, [Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, IAccountsSettingsService accountSetting) { accountSetting.GetPageLinkOrDefault(Arg.Any<Item>(), Arg.Any<ID>(), Arg.Any<Item>()).Returns("/"); var fakeSite = new FakeSiteContext(new StringDictionary { { "rootPath", "/sitecore/content" }, { "startItem", item.Name } }) as SiteContext; fakeSite.Database = db; Language.Current = Language.Invariant; using (new SiteContextSwitcher(fakeSite)) { info.ReturnUrl = null; var controller = new AccountsController(repo, service, accountSetting, null); repo.Login(string.Empty, string.Empty).ReturnsForAnyArgs(x => true); var result = controller.Login(info); result.Should().BeOfType<RedirectResult>().Which.Url.Should().Be("/"); } }
public void LoginShouldReturnViewModelIfModelStateNotValid([Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, IAccountsSettingsService accountSetting) { var controller = new AccountsController(repo, service, accountSetting, null); controller.ModelState.AddModelError("Error", "Error"); var result = controller.Login(info); result.Should().BeOfType<ViewResult>(); }
public void LoginShouldRedirectToReturnUrlIfLoggedIn([Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, IAccountsSettingsService accountSetting) { var controller = new AccountsController(repo, service, accountSetting, null); repo.Login(string.Empty, string.Empty).ReturnsForAnyArgs(x => true); var result = controller.Login(info); result.Should().BeOfType<RedirectResult>().Which.Url.Should().Be(info.ReturnUrl); }