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");
      }
    }
Example #2
0
    public void ShouldReturnTrueIfUserExists()
    {
      // arrange
      var user = new FakeMembershipUser();
      this.provider.GetUser(UserName, true).Returns(user);

      // act
      using (new MembershipSwitcher(this.provider))
      {
        // assert
        User.Exists(UserName).Should().BeTrue();
      }
    }
        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();
                }
            }
        }
        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 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 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 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 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))
                {
                    repo.Login("John", "somepassword");
                    accountTrackerService.DidNotReceive().TrackLogin(Arg.Any<string>());
                }
            }
        }