1- using Ploeh . AutoFixture ;
1+ using System . Text ;
2+ using Ploeh . AutoFixture ;
3+ using Ploeh . AutoFixture . Kernel ;
24
35namespace NTestDataBuilder . EquivalenceClasses
46{
@@ -17,6 +19,18 @@ public static string String(this AnonymousValueFixture fixture)
1719 return fixture . Fixture . Create < string > ( ) ;
1820 }
1921
22+ /// <summary>
23+ /// Generate and return a string matching the given regex.
24+ /// Only a limited subset of regex expressions are supported: http://www.brics.dk/automaton/faq.html.
25+ /// </summary>
26+ /// <param name="fixture">The fixture to generate a string for</param>
27+ /// <param name="regexPattern">The regex pattern to match</param>
28+ /// <returns>The generated string</returns>
29+ public static string StringMatching ( this AnonymousValueFixture fixture , string regexPattern )
30+ {
31+ return fixture . RegexGenerator . Create ( new RegularExpressionRequest ( regexPattern ) , new DummyContext ( ) ) . ToString ( ) ;
32+ }
33+
2034 /// <summary>
2135 /// Generate and return a string starting with the given prefix.
2236 /// </summary>
@@ -38,5 +52,21 @@ public static string StringEndingWith(this AnonymousValueFixture fixture, string
3852 {
3953 return string . Format ( "{0}{1}" , fixture . Fixture . Create < string > ( ) , suffix ) ;
4054 }
55+
56+ /// <summary>
57+ /// Generate and return a string of the given length.
58+ /// </summary>
59+ /// <param name="fixture">The fixture to generate a string for</param>
60+ /// <param name="length">The length of string to generate</param>
61+ /// <returns>The generated string</returns>
62+ public static string StringOfLength ( this AnonymousValueFixture fixture , int length )
63+ {
64+ var sb = new StringBuilder ( ) ;
65+ while ( sb . Length < length )
66+ {
67+ sb . Append ( String ( fixture ) ) ;
68+ }
69+ return sb . ToString ( ) . Substring ( 0 , length ) ;
70+ }
4171 }
4272}
0 commit comments