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()
65
65
{
66
66
int amount = 5 ;
67
67
68
- IEnumerable < int > result = Randomizer < int > . Create ( amount , new IntRange ( 1 , 1 ) ) ;
68
+ IEnumerable < int > result = Randomizer < int > . Create ( new IntRange ( 1 , 1 ) , amount ) ;
69
69
70
70
Assert . Equal ( amount , result . Count ( ) ) ;
71
71
Assert . True ( result . Count ( x => x == 1 ) == amount ) ;
@@ -87,12 +87,12 @@ public void RandomizerCreatesAListOfItemBasedOnASetup()
87
87
{
88
88
int amount = 5 ;
89
89
90
- var setup = FillerSetup . Create < Person > ( ) . OnType < int > ( ) . Use ( 1 ) . Result ;
90
+ var setup = FillerSetup . Create < Address > ( ) . OnType < int > ( ) . Use ( 1 ) . Result ;
91
91
92
- IEnumerable < Person > result = Randomizer < Person > . Create ( amount , setup ) ;
92
+ IEnumerable < Address > result = Randomizer < Address > . Create ( setup , amount ) ;
93
93
94
94
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 ) ;
96
96
}
97
97
}
98
98
}
Original file line number Diff line number Diff line change @@ -101,6 +101,31 @@ public static T Create(IRandomizerPlugin<T> randomizerPlugin)
101
101
return randomizerPlugin . GetValue ( ) ;
102
102
}
103
103
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
+
104
129
/// <summary>
105
130
/// Creates a factory method for the given type.
106
131
/// </summary>
@@ -132,25 +157,5 @@ internal static Func<T> CreateFactoryMethod(FillerSetup setup)
132
157
133
158
return ( ) => ( T ) Setup . TypeToRandomFunc [ typeof ( T ) ] ( ) ;
134
159
}
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
- }
155
160
}
156
161
}
You can’t perform that action at this time.
0 commit comments