File tree Expand file tree Collapse file tree 2 files changed +18
-9
lines changed Expand file tree Collapse file tree 2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -19,12 +19,14 @@ public void TestFillPerson()
1919 . OnType < IAddress > ( ) . CreateInstanceOf < Address > ( )
2020 . OnType < string > ( ) . Use ( new MnemonicString ( 10 ) )
2121 . OnProperty ( person => person . FirstName ) . Use ( new MnemonicString ( 1 ) )
22- . OnProperty ( person => person . LastName ) . Use ( new RandomListItem < string > ( new List < string > ( ) { "Maik" , "Tom" , "Anton" } ) )
22+ . OnProperty ( person => person . LastName ) . Use ( new RandomListItem < string > ( "Maik" , "Tom" , "Anton" ) )
2323 . OnProperty ( person => person . Age ) . Use ( ( ) => new Random ( ) . Next ( 12 , 83 ) )
2424 . SetupFor < Address > ( )
2525 . OnProperty ( x => x . City , x => x . Country ) . IgnoreIt ( ) ;
2626
2727 Person pFilled = filler . Fill ( p ) ;
28+
29+ Assert . IsTrue ( new List < string > ( ) { "Maik" , "Tom" , "Anton" } . Contains ( pFilled . LastName ) ) ;
2830 }
2931
3032 [ TestMethod ]
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
33using System . Diagnostics ;
4+ using System . Linq ;
45
56namespace Tynamix . ObjectFiller
67{
78 public class RandomListItem < T > : IRandomizerPlugin < T >
89 {
9- private readonly List < T > _allAvailableValues ;
10+ private readonly T [ ] _allAvailableValues ;
1011
11- public RandomListItem ( List < T > allAvailableValues )
12+ public RandomListItem ( params T [ ] allAvailableValues )
1213 {
13- if ( allAvailableValues == null || allAvailableValues . Count == 0 )
14+ if ( allAvailableValues == null || allAvailableValues . Length == 0 )
1415 {
15- const string message = "List in RandomListItem ranomizer can not be empty!" ;
16- Debug . WriteLine ( "ObjectFiller: " + message ) ;
17- throw new ArgumentException ( message ) ;
16+ const string message = "List in RandomListItem ranomizer can not be empty!" ;
17+ Debug . WriteLine ( "ObjectFiller: " + message ) ;
18+ throw new ArgumentException ( message ) ;
1819 }
19- _allAvailableValues = allAvailableValues ;
20+ _allAvailableValues = allAvailableValues ;
21+ }
22+
23+ public RandomListItem ( IEnumerable < T > allAvailableValues )
24+ : this ( allAvailableValues . ToArray ( ) )
25+ {
2026
2127 }
2228
29+
2330 public T GetValue ( )
2431 {
25- int rndmListIndex = Random . Next ( 0 , _allAvailableValues . Count ) ;
32+ int rndmListIndex = Random . Next ( 0 , _allAvailableValues . Length - 1 ) ;
2633 return _allAvailableValues [ rndmListIndex ] ;
2734 }
2835 }
You can’t perform that action at this time.
0 commit comments