public void RegisterShouldReturnErrorIfRegistrationThrowsMembershipException(RegistrationInfo registrationInfo, MembershipCreateUserException exception, [Frozen] IAccountRepository repo, [Frozen] INotificationService notifyService)
        {
            repo.When(x => x.RegisterUser(Arg.Any<RegistrationInfo>())).Do(x => { throw new MembershipCreateUserException(); });
              var controller = new AccountsController(repo, notifyService);

              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 RegisterShouldReturnErrorIfRegistrationThrowsMembershipException(Database db, [Content] DbItem item, Item profileItem, RegistrationInfo registrationInfo, MembershipCreateUserException exception, [Frozen] IAccountRepository repo, [Frozen] INotificationService notifyService, [Frozen] IAccountsSettingsService 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, userProfileService);

              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 RegisterShouldCallRegisterUserAndRedirectToHomePage(Database db, [Content] DbItem item, RegistrationInfo registrationInfo, [Frozen] IAccountRepository repo, [Frozen] INotificationService notifyService)
        {
            repo.Exists(Arg.Any<string>()).Returns(false);
              var controller = new AccountsController(repo, notifyService);

              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<RedirectResult>().Which.Url.Should().Be("/");

            repo.Received(1).RegisterUser(registrationInfo);
              }
        }
        public void RegisterShouldCallRegisterUserAndRedirectToHomePage(Database db, [Content] DbItem item, Item profileItem, RegistrationInfo registrationInfo, [Frozen] IAccountRepository repo, [Frozen] INotificationService notifyService, [Frozen] IAccountsSettingsService accountsSettingsService, [Frozen] IUserProfileService userProfileService)
        {
            accountsSettingsService.GetPageLinkOrDefault(Arg.Any<Item>(), Arg.Any<ID>(), Arg.Any<Item>()).Returns("/redirect");
              repo.Exists(Arg.Any<string>()).Returns(false);
              userProfileService.GetUserDefaultProfileId().Returns(profileItem.ID.ToString());

              var controller = new AccountsController(repo, notifyService, accountsSettingsService, userProfileService);

              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<RedirectResult>().Which.Url.Should().Be("/redirect");

            repo.Received(1).RegisterUser(registrationInfo.Email, registrationInfo.Password, Arg.Any<string>());
              }
        }