File tree Expand file tree Collapse file tree 3 files changed +50
-1
lines changed
Tynamix.ObjectFiller.Test
Tynamix.ObjectFiller/Plugins/List Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Original file line number Diff line number Diff line change 1+ using System . Collections . Generic ;
2+
3+ namespace Tynamix . ObjectFiller . Test
4+ {
5+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
6+
7+ public class SimpleList
8+ {
9+ public List < string > Strings10 { get ; set ; }
10+ public ICollection < string > Strings2050 { get ; set ; }
11+ public string [ ] Strings50100 { get ; set ; }
12+
13+ public int Item { get ; set ; }
14+ }
15+
16+ [ TestClass ]
17+ public class TestSpecifyListCount
18+ {
19+
20+ [ TestMethod ]
21+ public void Generate10Strings ( )
22+ {
23+ Filler < SimpleList > filler = new Filler < SimpleList > ( ) ;
24+
25+ filler . Setup ( )
26+ . OnProperty ( x => x . Strings10 ) . Use ( new Collectionizer < string , CityName > ( 1 , 10 ) )
27+ . OnProperty ( x => x . Strings2050 ) . Use ( new Collectionizer < string , StreetName > ( 20 , 50 ) )
28+ . OnProperty ( x => x . Strings50100 ) . Use ( new Collectionizer < string , RealNames > ( 50 , 100 ) )
29+ . OnProperty ( x => x . Item ) . Use ( 1 ) ;
30+
31+ var result = filler . Create ( ) ;
32+
33+ Assert . IsTrue ( result . Strings10 . Count > 0 && result . Strings10 . Count <= 10 ) ;
34+ Assert . IsTrue ( result . Strings2050 . Count >= 20 && result . Strings2050 . Count <= 50 ) ;
35+ Assert . IsTrue ( result . Strings50100 . Length >= 50 && result . Strings50100 . Length <= 100 ) ;
36+ }
37+ }
38+ }
Original file line number Diff line number Diff line change 8181 <Compile Include =" SaveFillerSetupTest.cs" />
8282 <Compile Include =" SequenceGeneratorTest.cs" />
8383 <Compile Include =" SetupTests.cs" />
84+ <Compile Include =" SpecifyListCount.cs" />
8485 <Compile Include =" StreetNamesPluginTest.cs" />
8586 <Compile Include =" TestIgnoranceOfInheritance.cs" />
8687 <Compile Include =" TestPoco\Library\Book.cs" />
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ namespace Tynamix.ObjectFiller
88 /// </summary>
99 /// <typeparam name="T">Typeparameter of of the target List</typeparam>
1010 /// <typeparam name="TRandomizer">Plugin which will be used to create the List</typeparam>
11- public class Collectionizer < T , TRandomizer > : IRandomizerPlugin < List < T > >
11+ public class Collectionizer < T , TRandomizer > : IRandomizerPlugin < List < T > > , IRandomizerPlugin < T [ ] >
1212#if ! NETSTANDARD1_0
1313 , IRandomizerPlugin < ArrayList >
1414#endif
@@ -110,6 +110,15 @@ public List<T> GetValue()
110110 return result ;
111111 }
112112
113+ /// <summary>
114+ /// Gets random data for type <see cref="T"/>
115+ /// </summary>
116+ /// <returns>Random data for type <see cref="T"/></returns>
117+ T [ ] IRandomizerPlugin < T [ ] > . GetValue ( )
118+ {
119+ return this . GetValue ( ) . ToArray ( ) ;
120+ }
121+
113122#if ! NETSTANDARD1_0
114123 /// <summary>
115124 /// Gets random data for type <see cref="T"/>
@@ -123,6 +132,7 @@ ArrayList IRandomizerPlugin<ArrayList>.GetValue()
123132 return arrayList ;
124133 }
125134#endif
135+
126136 }
127137
128138}
You can’t perform that action at this time.
0 commit comments