/// <summary> /// Generate a password string /// </summary> /// <param name="characterVariants">The variants of characters to use</param> /// <returns>The password string</returns> public string GeneratePassword(params CharacterVariant[] characterVariants) { _generatorHelper.EnsurePositiveCharacterCount(DefaultPasswordLength); _generatorHelper.EnsurePositiveCharacterVariantCount(characterVariants); _generatorHelper.AddCharacterVariantsToDictionary(characterVariants); var password = _generatorHelper.CreatePasswordString(DefaultPasswordLength); Dispose(); return(password); }
public void EnsurePositiveCharacterCount_PositiveCount_DoesNotThrow() { // Arrange var characters = new Dictionary <CharacterVariant, string>(); var passwordGeneratorHelper = new PasswordGeneratorHelper(characters); int characterCount = 12; // Act and Assert passwordGeneratorHelper.EnsurePositiveCharacterCount(characterCount); }
public void EnsurePositiveCharacterCount_NonPositiveCount_ThrowsArgumentException() { // Arrange var characters = new Dictionary <CharacterVariant, string>(); characters.Add(CharacterVariant.Digits, CharacterLists.Digits); characters.Add(CharacterVariant.Lowercase, CharacterLists.Lowercase); characters.Add(CharacterVariant.Uppercase, CharacterLists.Uppercase); var passwordGeneratorHelper = new PasswordGeneratorHelper(characters); int characterCount = 0; // Act and Assert Assert.Throws <ArgumentException>(() => passwordGeneratorHelper.EnsurePositiveCharacterCount(characterCount)); }