public void GetForgotPasswordMailTemplateShouldNotThrowExceptionWhenSubjIsEmpty(Db db) { var fakeSite = BuildUpSiteContext(db, subj: null); using (new SiteContextSwitcher(fakeSite)) { var settings = new AccountsSettingsService(); settings.GetForgotPasswordMailTemplate().Subject.Should().BeEmpty(); } }
public void GetForgotPasswordMailTemplateShouldThrowExceptionWhenFromAddressIsEmpty(Db db) { var fakeSite = BuildUpSiteContext(db, @from: null); using (new SiteContextSwitcher(fakeSite)) { var settings = new AccountsSettingsService(); Action act = () => settings.GetForgotPasswordMailTemplate(); act.ShouldThrow <InvalidValueException>().WithMessage("'From' field in mail template should be set"); } }
public void GetForgotPasswordMailTemplateShouldRetreiveSourceAddressFromItem(Db db) { var fakeSite = BuildUpSiteContext(db); using (new SiteContextSwitcher(fakeSite)) { var settings = new AccountsSettingsService(); var mailTemplate = settings.GetForgotPasswordMailTemplate(); mailTemplate.From.Address.Should().Be("*****@*****.**"); } }
public void GetForgotPasswordMailTemplateShouldRetreiveSubjectFromItem(Db db) { var fakeSite = BuildUpSiteContext(db); using (new SiteContextSwitcher(fakeSite)) { var settings = new AccountsSettingsService(); var mailTemplate = settings.GetForgotPasswordMailTemplate(); mailTemplate.Subject.Should().Be("restore password subject"); } }
public void GetForgotPasswordMailTemplateShouldThrowExceptionWhenMailTemplateNotfound(Db db) { var fakeSite = BuildUpSiteContext(db, @from: null); db.GetItem("/sitecore/content/siteroot").DeleteChildren(); using (new SiteContextSwitcher(fakeSite)) { var settings = new AccountsSettingsService(); Action act = () => settings.GetForgotPasswordMailTemplate(); act.ShouldThrow <ItemNotFoundException>(); } }
public void GetRegisterOutcome_NullSettingsItem_ShouldthrowException(Db db, AccountsSettingsService accountsSettingsService) { //Arrange var fakeSite = BuildUpSiteContext(db, null); db.GetItem("/sitecore/content").DeleteChildren(); using (new SiteContextSwitcher(fakeSite)) { //Act //Assert accountsSettingsService.Invoking(x => x.GetRegistrationOutcome(null)).ShouldThrow <ItemNotFoundException>(); } }
public void _Login_LoggedIn_ShouldRedirect(Database db, [Content] DbItem item, User user, [Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, AccountsSettingsService accountSetting, IUserProfileService userProfileService) { userProfileService.ValidateUser(Arg.Any <User>()).ReturnsForAnyArgs(true); var controller = new AccountsController(repo, service, accountSetting, null, userProfileService, null); repo.Login(string.Empty, string.Empty).ReturnsForAnyArgs(x => user); var result = controller._Login(info); result.Should().BeOfType <JsonResult>(); ((result as JsonResult).Data as LoginResult).RedirectUrl.Should().BeEquivalentTo(info.ReturnUrl); }
public void Logout_ShouldRedirectUserToHomePage(Database db, [Content] DbItem item, IAccountRepository repo, INotificationService ns, AccountsSettingsService acc) { 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)) { var ctrl = new AccountsController(repo, ns, acc, null, null, null); var result = ctrl.Logout(); result.Should().BeOfType <RedirectResult>().Which.Url.Should().Be("/"); } }
public void Logout_ShouldCallSitecoreLogout(Database db, [Content] DbItem item, IAccountRepository repo, INotificationService ns, AccountsSettingsService acc) { var fakeSite = new FakeSiteContext(new StringDictionary { { "rootPath", "/sitecore/content" }, { "startItem", item.Name } }) as SiteContext; fakeSite.Database = db; using (new SiteContextSwitcher(fakeSite)) { var ctrl = new AccountsController(repo, ns, acc, null, null, null); ctrl.Logout(); repo.Received(1).Logout(); } }
public void Register_RegistrationThrowsMembershipException_ShouldReturnError(Database db, [Content] DbItem item, Item profileItem, RegistrationInfo registrationInfo, MembershipCreateUserException exception, [Frozen] IAccountRepository repo, [Frozen] INotificationService notifyService, [Frozen] AccountsSettingsService accountsSettingsService, [Frozen] IUserProfileService userProfileService) { repo.When(x => x.RegisterUser(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>())).Do(x => { throw new MembershipCreateUserException(); }); userProfileService.GetUserDefaultProfileId().Returns(profileItem.ID.ToString()); var controller = new AccountsController(repo, notifyService, accountsSettingsService, null, userProfileService, null); 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)) { var result = controller.Register(registrationInfo); result.Should().BeOfType <ViewResult>().Which.Model.Should().Be(registrationInfo); result.Should().BeOfType <ViewResult>().Which.ViewData.ModelState.Should().ContainKey(nameof(registrationInfo.Email)).WhichValue.Errors.Should().Contain(x => x.ErrorMessage == exception.Message); } }
public void ForgotPassword_ShouldCatchAndReturnViewWithError(PasswordResetInfo model, [Frozen] IAccountRepository repo, INotificationService notificationService, AccountsSettingsService 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, 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"); } }
public void ForgotPassword_ValidPassword_ShouldReturnSuccessView([Frozen] IAccountRepository repo, INotificationService ns, PasswordResetInfo model, AccountsSettingsService 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, 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(Constants.InfoMessageView); } }
public void GetRegisterOutcome_SettingsExist_ShouldReturnOutcomeID(Db db, ID outcomeId, AccountsSettingsService accountsSettingsService) { //Arrange var fakeSite = BuildUpSiteContext(db, outcomeID: outcomeId); using (new SiteContextSwitcher(fakeSite)) { //Act var resultOutcomeId = accountsSettingsService.GetRegistrationOutcome(null); //Assert resultOutcomeId.Should().Be(outcomeId); } }
public void GetPageLinkOrDefaultShouldReturnPageNotFoundUrlIfDefaultIsNull(Item item, ID id, AccountsSettingsService accountSettingsService) { var result = accountSettingsService.GetPageLinkOrDefault(item, id, null); result.Should().Be(AccountsSettingsService.PageNotFoundUrl); }
public void GetPageLinkOrDefaultShouldThrowIfDefaultIsNull(Item item, ID id, AccountsSettingsService accountSettingsService) { //var accountSettingsService = Substitute.ForPartsOf<AccountsSettingsService>(); //accountSettingsService accountSettingsService.Invoking(x => x.GetPageLinkOrDefault(item, id, null)).ShouldThrow <ArgumentNullException>(); }
public void GetPageLinkOrDefaultShouldThrowIfDefaultIsNull(Item item, ID id, AccountsSettingsService accountSettingsService) { accountSettingsService.Invoking(x => x.GetPageLinkOrDefault(item, id, null)).ShouldThrow <ArgumentNullException>(); }