@@ -42,21 +42,54 @@ public static T Create()
42
42
}
43
43
44
44
/// <summary>
45
- /// Creates a set of random items of the given type. It will use a <see cref="IRandomizerPlugin{T}"/> for that.
45
+ /// Creates a set of random items of the given type.
46
46
/// </summary>
47
47
/// <param name="amount">Amount of items created.</param>
48
48
/// <returns>Set of random items of the given type.</returns>
49
49
public static IEnumerable < T > Create ( int amount )
50
+ {
51
+ return Create ( amount , Create ) ;
52
+ }
53
+
54
+ /// <summary>
55
+ /// Creates the specified amount of elements using the given factory.
56
+ /// </summary>
57
+ /// <param name="amount">The amount to create.</param>
58
+ /// <param name="factory">The factory which provides the instance to add.</param>
59
+ /// <returns>Set of items created by the factory.</returns>
60
+ public static IEnumerable < T > Create ( int amount , Func < T > factory )
50
61
{
51
62
var resultSet = new List < T > ( ) ;
52
63
for ( int i = 0 ; i < amount ; i ++ )
53
64
{
54
- resultSet . Add ( Create ( ) ) ;
65
+ resultSet . Add ( factory ( ) ) ;
55
66
}
56
67
57
68
return resultSet ;
58
69
}
59
70
71
+ /// <summary>
72
+ /// Creates a set of random items of the given type and will use a <see cref="IRandomizerPlugin{T}"/> for that.
73
+ /// </summary>
74
+ /// <param name="randomizerPlugin">Plugin to use.</param>
75
+ /// <param name="amount">Amount of items created.</param>
76
+ /// <returns>Set of random items of the given type.</returns>
77
+ public static IEnumerable < T > Create ( IRandomizerPlugin < T > randomizerPlugin , int amount )
78
+ {
79
+ return Create ( amount , ( ) => Create ( randomizerPlugin ) ) ;
80
+ }
81
+
82
+ /// <summary>
83
+ /// Creates a set of random items of the given type and will use a <see cref="FillerSetup"/> for that.
84
+ /// </summary>
85
+ /// <param name="setup">Setup to use.</param>
86
+ /// <param name="amount">Amount of items created.</param>
87
+ /// <returns>Set of random items of the given type.</returns>
88
+ public static IEnumerable < T > Create ( FillerSetup setup , int amount )
89
+ {
90
+ return Create ( amount , ( ) => Create ( setup ) ) ;
91
+ }
92
+
60
93
/// <summary>
61
94
/// Creates a random value of the target type. It will use a <see cref="IRandomizerPlugin{T}"/> for that
62
95
/// </summary>
@@ -68,6 +101,31 @@ public static T Create(IRandomizerPlugin<T> randomizerPlugin)
68
101
return randomizerPlugin . GetValue ( ) ;
69
102
}
70
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
+
71
129
/// <summary>
72
130
/// Creates a factory method for the given type.
73
131
/// </summary>
@@ -78,7 +136,7 @@ internal static Func<T> CreateFactoryMethod(FillerSetup setup)
78
136
Type targetType = typeof ( T ) ;
79
137
if ( ! Setup . TypeToRandomFunc . ContainsKey ( targetType ) )
80
138
{
81
-
139
+
82
140
if ( targetType . IsClass ( ) )
83
141
{
84
142
var fillerType = typeof ( Filler < > ) . MakeGenericType ( typeof ( T ) ) ;
@@ -99,25 +157,5 @@ internal static Func<T> CreateFactoryMethod(FillerSetup setup)
99
157
100
158
return ( ) => ( T ) Setup . TypeToRandomFunc [ typeof ( T ) ] ( ) ;
101
159
}
102
-
103
- public static T Create ( FillerSetup setup )
104
- {
105
- var creationMethod = CreateFactoryMethod ( setup ) ;
106
-
107
- T result ;
108
- try
109
- {
110
- result = creationMethod ( ) ;
111
- }
112
- catch ( Exception ex )
113
- {
114
- throw new InvalidOperationException (
115
- "The type " + typeof ( T ) . FullName + " needs additional information to get created. "
116
- + "Please use the Filler class and call \" Setup\" to create a setup for that type. See Innerexception for more details." ,
117
- ex ) ;
118
- }
119
-
120
- return result ;
121
- }
122
160
}
123
161
}
0 commit comments