public void ExistsShouldReturnTrueIfUserExists(FakeMembershipUser user, MembershipProvider membershipProvider, AccountRepository repo)
        {
            membershipProvider.GetUser(@"somedomain\John", Arg.Any<bool>()).Returns(user);

              var context = new FakeSiteContext(new StringDictionary
              {
            {
              "domain", "somedomain"
            }
              });
              using (new Switcher<Domain, Domain>(new Domain("somedomain")))
              {
            using (new MembershipSwitcher(membershipProvider))
            {
              var exists = repo.Exists("John");
              exists.Should().BeTrue();
            }
              }
        }
        public void RegisterShouldTrackLoginAndRegisterEvents(FakeMembershipUser user, [Substitute]MembershipProvider membershipProvider, [Substitute]AuthenticationProvider authenticationProvider, RegistrationInfo registrationInfo, [Frozen]IAccountTrackerService accountTrackerService, AccountRepository repository, string profileId)
        {
            user.UserName.Returns("name");
              MembershipCreateStatus status;
              membershipProvider.CreateUser(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<bool>(), Arg.Any<object>(), out status).Returns(user);
              membershipProvider.GetUser(Arg.Any<string>(), Arg.Any<bool>()).Returns(user);

              using (new Switcher<Domain, Domain>(new Domain("somedomain")))
              {
            using (new MembershipSwitcher(membershipProvider))
            {
              using (new AuthenticationSwitcher(authenticationProvider))
              {
            repository.RegisterUser(registrationInfo.Email, registrationInfo.Password, profileId);
            accountTrackerService.Received(1).TrackLogin();
            accountTrackerService.Received(1).TrackRegister();
              }
            }
              }
        }
        public void RestorePasswordShouldReturnsNewPassword(FakeMembershipUser user, MembershipProvider membershipProvider, AccountRepository repo)
        {
            user.ProviderName.Returns("fake");
              membershipProvider.ResetPassword(Arg.Any<string>(), Arg.Any<string>()).Returns("new password");
              membershipProvider.Name.Returns("fake");
              membershipProvider.GetUser(Arg.Any<string>(), Arg.Any<bool>()).Returns(user);

              using (new MembershipSwitcher(membershipProvider))
              {
            repo.RestorePassword(@"extranet\John").Should().Be("new password");
              }
        }
        public void RegisterShouldCreateUserWithEmailAndPassword(FakeMembershipUser user, MembershipProvider membershipProvider, RegistrationInfo registrationInfo, string userProfile, AccountRepository repository)
        {
            user.ProviderName.Returns("fake");
              user.UserName.Returns("name");
              MembershipCreateStatus status;
              membershipProvider.CreateUser(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<bool>(), Arg.Any<object>(), out status).Returns(user);
              membershipProvider.GetUser(Arg.Any<string>(), Arg.Any<bool>()).Returns(user);

              using (new Switcher<Domain, Domain>(new Domain("somedomain")))
              {
            using (new MembershipSwitcher(membershipProvider))
            {
              repository.RegisterUser(registrationInfo.Email,registrationInfo.Password, userProfile);
              membershipProvider.Received(1).CreateUser($@"somedomain\{registrationInfo.Email}", registrationInfo.Password, Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<bool>(), Arg.Any<object>(), out status);
            }
              }
        }
 public void RegisterShouldThrowArgumentException(string email, string password, string profileId)
 {
     var repository = new AccountRepository(Substitute.For<IAccountTrackerService>());
       repository.Invoking(x => x.RegisterUser(email,password, profileId)).ShouldThrow<ArgumentNullException>();
 }
        public void RegisterShouldCreateLoginUser(FakeMembershipUser user, [Substitute] MembershipProvider membershipProvider, [Substitute] AuthenticationProvider authenticationProvider, RegistrationInfo registrationInfo, AccountRepository repository, string profileId)
        {
            user.ProviderName.Returns("fake");
              user.UserName.Returns("name");
              MembershipCreateStatus status;
              membershipProvider.CreateUser(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<bool>(), Arg.Any<object>(), out status).Returns(user);
              membershipProvider.GetUser(Arg.Any<string>(), Arg.Any<bool>()).Returns(user);

              using (new Switcher<Domain, Domain>(new Domain("somedomain")))
              {
            using (new MembershipSwitcher(membershipProvider))
            {
              using (new AuthenticationSwitcher(authenticationProvider))
              {
            repository.RegisterUser(registrationInfo.Email, registrationInfo.Password, profileId);
            authenticationProvider.Received(1).Login(Arg.Is<User>(u => u.Name == $@"somedomain\{registrationInfo.Email}"));
              }
            }
              }
        }
 public void LogoutShouldLogoutUser(User user, MembershipProvider membershipProvider, RegistrationInfo registrationInfo, AccountRepository repository)
 {
     var authenticationProvider = Substitute.For<AuthenticationProvider>();
       authenticationProvider.GetActiveUser().Returns(user);
       using (new AuthenticationSwitcher(authenticationProvider))
       {
       repository.Logout();
       authenticationProvider.Received(1).Logout();
       }
 }
        public void LoginShouldTriggerLoginEventIfUserIsLoggedIn(FakeMembershipUser user, [Frozen]IAccountTrackerService accountTrackerService, AuthenticationProvider authenticationProvider, AccountRepository repo)
        {
            authenticationProvider.Login(@"somedomain\John", Arg.Any<string>(), Arg.Any<bool>()).Returns(true);

              var context = new FakeSiteContext(new StringDictionary
              {
            {
              "domain", "somedomain"
            }
              });
              using (new Switcher<Domain, Domain>(new Domain("somedomain")))
              {
            using (new AuthenticationSwitcher(authenticationProvider))
            {
              var loginResult = repo.Login("John", "somepassword");
              accountTrackerService.Received(1).TrackLogin();
            }
              }
        }
        public void LoginShouldReturnTrueIfUserIsLoggedIn(FakeMembershipUser user, AuthenticationProvider authenticationProvider, AccountRepository repo)
        {
            authenticationProvider.Login(@"somedomain\John", Arg.Any<string>(), Arg.Any<bool>()).Returns(true);

              var context = new FakeSiteContext(new StringDictionary
              {
            {
              "domain", "somedomain"
            }
              });
              using (new Switcher<Domain, Domain>(new Domain("somedomain")))
              {
            using (new AuthenticationSwitcher(authenticationProvider))
            {
              var loginResult = repo.Login("John", "somepassword");
              loginResult.Should().BeTrue();
            }
              }
        }
 public void RegisterShouldThrowArgumentException(RegistrationInfo registrationInfo)
 {
     var repository = new AccountRepository();
       repository.Invoking(x => x.RegisterUser(registrationInfo)).ShouldThrow<ArgumentNullException>();
 }