public void Constructs_with_invalid_property_should_throw_exception(string pattern, int count) { var generator = new RandomRegexLiteStringGenerator { RegularExpressionPattern = pattern, Count = count }; Assert.Throws<GenerationException>(() => generator.Run().Cast<string>().ToArray()); }
public void Generate_sequence_ok(string pattern, string expected, int count) { var generator = new RandomRegexLiteStringGenerator { RegularExpressionPattern = pattern, Count = count }; var values = generator.Run().Cast<string>().ToArray(); Assert.Count(count, values); Assert.Multiple(() => { foreach (string value in values) { Assert.FullMatch(value, expected); } }); }
/// <summary> /// Returns an enumeration of random strings based on a regular expression filter. /// </summary> /// <param name="count">The number of strings to generate.</param> /// <param name="regularExpressionPattern">The regular expression filter.</param> /// <param name="seed">A seed value to initialize the random number generator.</param> /// <returns>An enumeration of random string values.</returns> /// <exception cref="GenerationException">Thrown if the specified parameters are inconsistent or invalid.</exception> public static IEnumerable<string> Strings(int count, string regularExpressionPattern, int seed) { var generator = new RandomRegexLiteStringGenerator { Count = count, RegularExpressionPattern = regularExpressionPattern, Seed = seed, }; foreach (string value in generator.Run()) yield return value; }