/// <summary> /// Generates and returns a password as a protected string. /// </summary> /// <param name="prf">Password profile.</param> /// <param name="crsRandomSource">Cryptographic random source.</param> /// <returns>The generated password.</returns> public override ProtectedString Generate(PwProfile prf, CryptoRandomStream crsRandomSource) { UserConfig config = UserConfig.Deserialize(prf.CustomAlgorithmOptions); SystemConfig sysConfig = new SystemConfig(); RandomUtil random = new RandomUtil(crsRandomSource); IRepositoryFactory factory = new FileRepositoryFactory(config, sysConfig); IPhraseRepository repo = factory.Make(random); ISpecialCharsRepository specialCharsRepo = factory.MakeSpecialChars(random); IPhraseGenerator generator = new PhraseGenerator(config, repo, specialCharsRepo); return(generator.Generate()); }
// MethodName_Scenario_ExpectedBehavior (ex. CanBeCancelledBy_UserIsAdmin_ReturnsTrue) public void PhraseGenerator_InvokeGenerateMethod_DoesNotReturnNullOrEmptyString() { // Arrange bool isEmpty = false; // Act for (int i = 0; i < 1000; i++) { if (string.IsNullOrWhiteSpace(phraseGenerator.Generate())) { isEmpty = true; } } // Assert Assert.IsFalse(isEmpty); }
public void TestGenerate() { var generator = new PhraseGenerator(this.config, this.repo, this.specialCharsRepo); Assert.AreEqual("foo foo foo foo foo foo", generator.Generate().ReadString(), "Assert that the generated password matches expectations."); }