public async Task ValidateAsync_WhenPasswordOptionsAreExtendedPasswordOptionsButNotSet_ExpectSuccess() { var options = new ExtendedPasswordOptions(); var sut = CreateMockedSut(); var result = await sut.Object.ValidateAsync(CreateMockUserManager(options).Object, new IdentityUser(), "123"); result.Succeeded.Should().BeTrue(); }
public async Task ValidateAsync_WhenExtendedPasswordOptionsAndPasswordIsNotTooLong_ExpectSuccess(int maxLength, string password) { var options = new ExtendedPasswordOptions { MaxLength = maxLength }; var sut = CreateMockedSut(); var result = await sut.Object.ValidateAsync(CreateMockUserManager(options).Object, new IdentityUser(), password); result.Succeeded.Should().BeTrue(); }
public void ProcessIdentityPasswordRules_WhenExtendedOptionsWithInvalidMaxConsecutiveChars_ExpectNoMaxConsecutiveCharsAttribute(int?expectedMaxConsecutiveChars) { var sut = CreateSut(); var options = new ExtendedPasswordOptions { MaxConsecutiveChars = expectedMaxConsecutiveChars }; sut.ProcessIdentityPasswordRules(options, testOutput); testOutput.Attributes["passwordrules"].Value.As <string>().Should().NotContain("max-consecutive"); }
public async Task ValidateAsync_WhenExtendedPasswordOptionsAndPasswordIsTooLong_ExpectError(int maxLength, string password) { var options = new ExtendedPasswordOptions { MaxLength = maxLength }; var sut = CreateMockedSut(); var result = await sut.Object.ValidateAsync(CreateMockUserManager(options).Object, new IdentityUser(), password); result.Succeeded.Should().BeFalse(); result.Errors.Should().Contain(x => x.Code == "PasswordTooLong" && x.Description.Contains(options.MaxLength.ToString())); }
public void ProcessIdentityPasswordRules_WhenExtendedOptionsWithInvalidMaxLength_ExpectNoMaxLengthAttribute(int?expectedMaxLength) { var sut = CreateSut(); var options = new ExtendedPasswordOptions { MaxLength = expectedMaxLength }; sut.ProcessIdentityPasswordRules(options, testOutput); testOutput.Attributes["passwordrules"].Value.As <string>().Should().NotContain("maxlength"); testOutput.Attributes["maxlength"].Should().BeNull(); }
public async Task ValidateAsync_WhenExtendedPasswordOptionsAndMaxConsecutiveCharactersValid_ExpectSuccess(int maxConsecutive, string password) { var options = new ExtendedPasswordOptions { MaxConsecutiveChars = maxConsecutive }; var sut = CreateMockedSut(); sut.Setup(x => x.HasConsecutiveCharacters(password, maxConsecutive)).Returns(false); var result = await sut.Object.ValidateAsync(CreateMockUserManager(options).Object, new IdentityUser(), password); result.Succeeded.Should().BeTrue(); }
public void ProcessIdentityPasswordRules_WhenExtendedOptionsWithMaxLength_ExpectMaxLengthAttribute() { const int expectedMaxLength = 42; var sut = CreateSut(); var options = new ExtendedPasswordOptions { MaxLength = expectedMaxLength }; sut.ProcessIdentityPasswordRules(options, testOutput); testOutput.Attributes["passwordrules"].Value.As <string>().Should().Contain($"maxlength: {expectedMaxLength};"); testOutput.Attributes["maxlength"].Value.Should().Be(expectedMaxLength); }
public async Task ValidateAsync_WhenExtendedPasswordOptionsAndTooManyMaxConsecutiveCharacters_ExpectError() { const string password = "******"; var options = new ExtendedPasswordOptions { MaxConsecutiveChars = 2 }; var sut = CreateMockedSut(); sut.Setup(x => x.HasConsecutiveCharacters(password, options.MaxConsecutiveChars.Value)).Returns(true); var result = await sut.Object.ValidateAsync(CreateMockUserManager(options).Object, new IdentityUser(), password); result.Succeeded.Should().BeFalse(); result.Errors.Should().Contain(x => x.Code == "TooManyConsecutiveCharacters" && x.Description.Contains(options.MaxConsecutiveChars.ToString())); }