@@ -42,21 +42,54 @@ public static T Create()
4242 }
4343
4444 /// <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.
4646 /// </summary>
4747 /// <param name="amount">Amount of items created.</param>
4848 /// <returns>Set of random items of the given type.</returns>
4949 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 )
5061 {
5162 var resultSet = new List < T > ( ) ;
5263 for ( int i = 0 ; i < amount ; i ++ )
5364 {
54- resultSet . Add ( Create ( ) ) ;
65+ resultSet . Add ( factory ( ) ) ;
5566 }
5667
5768 return resultSet ;
5869 }
5970
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+
6093 /// <summary>
6194 /// Creates a random value of the target type. It will use a <see cref="IRandomizerPlugin{T}"/> for that
6295 /// </summary>
@@ -68,6 +101,31 @@ public static T Create(IRandomizerPlugin<T> randomizerPlugin)
68101 return randomizerPlugin . GetValue ( ) ;
69102 }
70103
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+
71129 /// <summary>
72130 /// Creates a factory method for the given type.
73131 /// </summary>
@@ -78,7 +136,7 @@ internal static Func<T> CreateFactoryMethod(FillerSetup setup)
78136 Type targetType = typeof ( T ) ;
79137 if ( ! Setup . TypeToRandomFunc . ContainsKey ( targetType ) )
80138 {
81-
139+
82140 if ( targetType . IsClass ( ) )
83141 {
84142 var fillerType = typeof ( Filler < > ) . MakeGenericType ( typeof ( T ) ) ;
@@ -99,25 +157,5 @@ internal static Func<T> CreateFactoryMethod(FillerSetup setup)
99157
100158 return ( ) => ( T ) Setup . TypeToRandomFunc [ typeof ( T ) ] ( ) ;
101159 }
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- }
122160 }
123161}
0 commit comments