private static void AddNounWithAdjectiveGenerators(IRandomWordGenerator adjectiveGenerator, IRandomWordGenerator nounGenerator, Dictionary <int, IList <PasswordGeneratingChain> > operatorsByLength) { foreach (int nounLength in nounGenerator.WordLengths) { foreach (int adjectiveLength in adjectiveGenerator.WordLengths) { int passwordLength = adjectiveLength + nounLength; var passwordGeneratingChain = new PasswordGeneratingChain( () => adjectiveGenerator.GetRandomWord(adjectiveLength), () => nounGenerator.GetRandomWord(nounLength)); if (operatorsByLength.ContainsKey(passwordLength)) { operatorsByLength[passwordLength].Add(passwordGeneratingChain); } else { operatorsByLength[passwordLength] = new List <PasswordGeneratingChain> { passwordGeneratingChain }; } } } }
public Game(IConsoleRenderer renderer, IRandomWordGenerator generator, ICommandManager commandManager) { this.renderer = renderer; this.generator = generator; this.commandManager = commandManager; this.scoreManager = ScoreManager.Instance; InitializeGameSettings(); }
private static void AddNounOnlyGenerators(IRandomWordGenerator nounGenerator, Dictionary <int, IList <PasswordGeneratingChain> > operatorsByLength) { foreach (int length in nounGenerator.WordLengths) { operatorsByLength.Add( length, new List <PasswordGeneratingChain> { new PasswordGeneratingChain(() => nounGenerator.GetRandomWord(length)), }); } }
public Word(IRandomWordGenerator randomWordGenerator) { this.secretWord = randomWordGenerator.GenerateRandomWord(); this.maskedWord = this.Mask(this.secretWord); }
public static IDictionary <int, IList <PasswordGeneratingChain> > CalculateAvailableLengths(IRandomWordGenerator adjectiveGenerator, IRandomWordGenerator nounGenerator) { var operatorsByLength = new Dictionary <int, IList <PasswordGeneratingChain> >(); AddNounOnlyGenerators(nounGenerator, operatorsByLength); AddNounWithAdjectiveGenerators(adjectiveGenerator, nounGenerator, operatorsByLength); Dictionary <int, IList <PasswordGeneratingChain> > readOnlyCollectionDict = operatorsByLength.Keys.ToDictionary(key => key, key => operatorsByLength[key]); return(readOnlyCollectionDict); }
public PasswordGenerator(IRandomWordGenerator adjectiveGenerator, IRandomWordGenerator nounGenerator) { this.adjectiveGenerator = adjectiveGenerator; this.nounGenerator = nounGenerator; this.operatorsByLength = CalculateAvailableLengths(adjectiveGenerator, nounGenerator); }
public Generate() { this.adjectiveGenerator = Substitute.For <IRandomWordGenerator>(); this.nounGenerator = Substitute.For <IRandomWordGenerator>(); }