File tree Expand file tree Collapse file tree 2 files changed +29
-24
lines changed
Tynamix.ObjectFiller.Test Expand file tree Collapse file tree 2 files changed +29
-24
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ public void RandomizerCreatesAListOfRandomItemsWithAPlugin()
6565 {
6666 int amount = 5 ;
6767
68- IEnumerable < int > result = Randomizer < int > . Create ( amount , new IntRange ( 1 , 1 ) ) ;
68+ IEnumerable < int > result = Randomizer < int > . Create ( new IntRange ( 1 , 1 ) , amount ) ;
6969
7070 Assert . Equal ( amount , result . Count ( ) ) ;
7171 Assert . True ( result . Count ( x => x == 1 ) == amount ) ;
@@ -87,12 +87,12 @@ public void RandomizerCreatesAListOfItemBasedOnASetup()
8787 {
8888 int amount = 5 ;
8989
90- var setup = FillerSetup . Create < Person > ( ) . OnType < int > ( ) . Use ( 1 ) . Result ;
90+ var setup = FillerSetup . Create < Address > ( ) . OnType < int > ( ) . Use ( 1 ) . Result ;
9191
92- IEnumerable < Person > result = Randomizer < Person > . Create ( amount , setup ) ;
92+ IEnumerable < Address > result = Randomizer < Address > . Create ( setup , amount ) ;
9393
9494 Assert . Equal ( amount , result . Count ( ) ) ;
95- Assert . True ( result . Count ( x => x . Age == 1 ) == amount ) ;
95+ Assert . True ( result . Count ( x => x . HouseNumber == 1 ) == amount ) ;
9696 }
9797 }
9898}
Original file line number Diff line number Diff line change @@ -101,6 +101,31 @@ public static T Create(IRandomizerPlugin<T> randomizerPlugin)
101101 return randomizerPlugin . GetValue ( ) ;
102102 }
103103
104+ /// <summary>
105+ /// Creates a value base on a filler setup
106+ /// </summary>
107+ /// <param name="setup">Setup for the objectfiller</param>
108+ /// <returns>Created value</returns>
109+ public static T Create ( FillerSetup setup )
110+ {
111+ var creationMethod = CreateFactoryMethod ( setup ) ;
112+
113+ T result ;
114+ try
115+ {
116+ result = creationMethod ( ) ;
117+ }
118+ catch ( Exception ex )
119+ {
120+ throw new InvalidOperationException (
121+ "The type " + typeof ( T ) . FullName + " needs additional information to get created. "
122+ + "Please use the Filler class and call \" Setup\" to create a setup for that type. See Innerexception for more details." ,
123+ ex ) ;
124+ }
125+
126+ return result ;
127+ }
128+
104129 /// <summary>
105130 /// Creates a factory method for the given type.
106131 /// </summary>
@@ -132,25 +157,5 @@ internal static Func<T> CreateFactoryMethod(FillerSetup setup)
132157
133158 return ( ) => ( T ) Setup . TypeToRandomFunc [ typeof ( T ) ] ( ) ;
134159 }
135-
136- public static T Create ( FillerSetup setup )
137- {
138- var creationMethod = CreateFactoryMethod ( setup ) ;
139-
140- T result ;
141- try
142- {
143- result = creationMethod ( ) ;
144- }
145- catch ( Exception ex )
146- {
147- throw new InvalidOperationException (
148- "The type " + typeof ( T ) . FullName + " needs additional information to get created. "
149- + "Please use the Filler class and call \" Setup\" to create a setup for that type. See Innerexception for more details." ,
150- ex ) ;
151- }
152-
153- return result ;
154- }
155160 }
156161}
You can’t perform that action at this time.
0 commit comments