Inheritance: IAccountRepository
Ejemplo n.º 1
0
    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");
      }
    }
Ejemplo n.º 2
0
        public void Exists_UserExists_ShouldReturnTrue(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();
                }
            }
        }
Ejemplo n.º 3
0
 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();
   }
 }
Ejemplo n.º 4
0
    public void Register_ValidUser_ShouldTrackRegistraionEvents(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).TrackRegistration();
          }
        }
      }
    }
Ejemplo n.º 5
0
    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<string>(u => u == $@"somedomain\{registrationInfo.Email}"), Arg.Is<string>(p=>p== registrationInfo.Password), Arg.Any<bool>());
          }
        }
      }
    }
Ejemplo n.º 6
0
    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);
        }
      }
    }
Ejemplo n.º 7
0
 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>();
 }
Ejemplo n.º 8
0
    public void Login_NotLoggedInUser_ShouldNotTrackLoginEvents(FakeMembershipUser user, [Frozen]IAccountTrackerService accountTrackerService, AuthenticationProvider authenticationProvider, AccountRepository repo)
    {
      authenticationProvider.Login(@"somedomain\John", Arg.Any<string>(), Arg.Any<bool>()).Returns(false);

      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.DidNotReceive().TrackLogin(Arg.Any<string>());
        }
      }
    }
Ejemplo n.º 9
0
    public void LoginShouldReturnFalseIfUserIsNotLoggedIn(FakeMembershipUser user, AuthenticationProvider authenticationProvider, AccountRepository repo)
    {
      authenticationProvider.Login(@"somedomain\John", Arg.Any<string>(), Arg.Any<bool>()).Returns(false);

      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().BeFalse();
        }
      }
    }