@@ -48,7 +48,8 @@ public static class TestApplication
48
48
private static bool initialiazed ;
49
49
50
50
private static string testAssemblyName ;
51
- private static TestConfiguration testConfiguration ;
51
+ private static IConfigurationBuilder configurationBuilder ;
52
+ private static TestConfiguration configuration ;
52
53
53
54
private static IHostingEnvironment environment ;
54
55
@@ -72,8 +73,7 @@ static TestApplication()
72
73
#if NET451
73
74
FindTestAssembly ( ) ;
74
75
#endif
75
-
76
- PrepareTestConfiguration ( ) ;
76
+
77
77
FindTestAssemblyName ( ) ;
78
78
}
79
79
@@ -115,7 +115,7 @@ internal static Type StartupType
115
115
116
116
set
117
117
{
118
- if ( startupType != null && TestConfiguration . General . AsynchronousTests )
118
+ if ( startupType != null && Configuration ( ) . General ( ) . AsynchronousTests ( ) )
119
119
{
120
120
throw new InvalidOperationException ( "Multiple Startup types per test project while running asynchronous tests is not supported. Either set 'General.AsynchronousTests' in the 'testconfig.json' file to 'false' or separate your tests into different test projects. The latter is recommended. If you choose the first option, you may need to disable asynchronous testing in your preferred test runner too." ) ;
121
121
}
@@ -163,31 +163,38 @@ internal static IHostingEnvironment Environment
163
163
}
164
164
}
165
165
166
- public static TestConfiguration TestConfiguration
166
+ internal static string ApplicationName =>
167
+ Configuration ( ) . General ( ) . ApplicationName ( )
168
+ ?? TestAssembly ? . GetName ( ) . Name
169
+ ?? StartupAssemblyName
170
+ ?? PlatformServices . Default . Application . ApplicationName ;
171
+
172
+ public static TestConfiguration Configuration ( )
167
173
{
168
- get
174
+ if ( configuration == null || AdditionalConfiguration != null )
169
175
{
170
- if ( testConfiguration == null || AdditionalConfiguration ! = null )
176
+ if ( configurationBuilder = = null )
171
177
{
172
- testConfiguration = TestConfiguration . With ( PrepareTestConfiguration ( ) ) ;
173
- PrepareLicensing ( ) ;
178
+ configurationBuilder = new ConfigurationBuilder ( )
179
+ . AddJsonFile ( "testconfig.json" , optional : true ) ;
174
180
}
175
181
176
- return testConfiguration ;
182
+ AdditionalConfiguration ? . Invoke ( configurationBuilder ) ;
183
+ AdditionalConfiguration = null ;
184
+
185
+ configuration = TestConfiguration . With ( configurationBuilder . Build ( ) ) ;
186
+
187
+ PrepareLicensing ( ) ;
177
188
}
178
- }
179
189
180
- internal static string ApplicationName =>
181
- TestConfiguration . General . ApplicationName
182
- ?? TestAssembly ? . GetName ( ) . Name
183
- ?? StartupAssemblyName
184
- ?? PlatformServices . Default . Application . ApplicationName ;
190
+ return configuration ;
191
+ }
185
192
186
193
public static void TryInitialize ( )
187
194
{
188
195
lock ( Sync )
189
196
{
190
- if ( ! initialiazed && TestConfiguration . General . AutomaticStartup )
197
+ if ( ! initialiazed && Configuration ( ) . General ( ) . AutomaticStartup ( ) )
191
198
{
192
199
var defaultStartupType = TryFindDefaultStartupType ( ) ;
193
200
@@ -267,7 +274,7 @@ internal static Type TryFindDefaultStartupType()
267
274
{
268
275
var applicationAssembly = TestAssembly ?? Assembly . Load ( new AssemblyName ( testAssemblyName ) ) ;
269
276
270
- var defaultStartupType = TestConfiguration . General . StartupType ?? $ "{ Environment . EnvironmentName } Startup";
277
+ var defaultStartupType = Configuration ( ) . General ( ) . StartupType ( ) ?? $ "{ Environment . EnvironmentName } Startup";
271
278
272
279
// check root of the test project
273
280
var startup =
@@ -292,21 +299,10 @@ private static void Initialize()
292
299
293
300
initialiazed = true ;
294
301
}
295
-
296
- private static IConfiguration PrepareTestConfiguration ( )
297
- {
298
- var configurationBuilder = new ConfigurationBuilder ( )
299
- . AddJsonFile ( "testconfig.json" , optional : true ) ;
300
-
301
- AdditionalConfiguration ? . Invoke ( configurationBuilder ) ;
302
- AdditionalConfiguration = null ;
303
-
304
- return configurationBuilder . Build ( ) ;
305
- }
306
-
302
+
307
303
private static void FindTestAssemblyName ( )
308
304
{
309
- testAssemblyName = TestConfiguration . General . TestAssemblyName
305
+ testAssemblyName = Configuration ( ) . General ( ) . TestAssemblyName ( )
310
306
?? TestAssembly ? . GetName ( ) . Name
311
307
?? DependencyContext
312
308
. Default
@@ -318,7 +314,7 @@ private static void FindTestAssemblyName()
318
314
private static void PrepareLicensing ( )
319
315
{
320
316
TestCounter . SetLicenseData (
321
- TestConfiguration . Licenses ,
317
+ Configuration ( ) . Licenses ( ) ,
322
318
DateTime . ParseExact ( ReleaseDate , "yyyy-MM-dd" , CultureInfo . InvariantCulture ) ,
323
319
TestAssembly ? . GetName ( ) . Name ?? StartupAssemblyName ) ;
324
320
}
@@ -328,7 +324,7 @@ private static IHostingEnvironment PrepareEnvironment()
328
324
return new HostingEnvironment
329
325
{
330
326
ApplicationName = ApplicationName ,
331
- EnvironmentName = TestConfiguration . General . EnvironmentName ,
327
+ EnvironmentName = Configuration ( ) . General ( ) . EnvironmentName ( ) ,
332
328
ContentRootPath = PlatformServices . Default . Application . ApplicationBasePath
333
329
} ;
334
330
}
@@ -515,6 +511,8 @@ private static void TryLockedInitialization()
515
511
private static void Reset ( )
516
512
{
517
513
initialiazed = false ;
514
+ configurationBuilder = null ;
515
+ configuration = null ;
518
516
environment = null ;
519
517
startupType = null ;
520
518
serviceProvider = null ;
@@ -531,29 +529,29 @@ private static void Reset()
531
529
RoutingServiceRegistrationPlugins . Clear ( ) ;
532
530
InitializationPlugins . Clear ( ) ;
533
531
LicenseValidator . ClearLicenseDetails ( ) ;
534
- }
532
+ }
535
533
536
534
#if NET451
537
- private static void FindTestAssembly ( )
538
- {
539
- var executingAssembly = Assembly . GetExecutingAssembly ( ) ;
540
-
541
- var stackTrace = new StackTrace ( false ) ;
542
-
543
- foreach ( var frame in stackTrace . GetFrames ( ) )
535
+ private static void FindTestAssembly ( )
544
536
{
545
- var method = frame . GetMethod ( ) ;
546
- var methodAssembly = method ? . DeclaringType ? . Assembly ;
537
+ var executingAssembly = Assembly . GetExecutingAssembly ( ) ;
538
+
539
+ var stackTrace = new StackTrace ( false ) ;
547
540
548
- if ( methodAssembly != null
549
- && methodAssembly != executingAssembly
550
- && ! methodAssembly . FullName . StartsWith ( TestFrameworkName ) )
541
+ foreach ( var frame in stackTrace . GetFrames ( ) )
551
542
{
552
- TestAssembly = methodAssembly ;
553
- return ;
543
+ var method = frame . GetMethod ( ) ;
544
+ var methodAssembly = method ? . DeclaringType ? . Assembly ;
545
+
546
+ if ( methodAssembly != null
547
+ && methodAssembly != executingAssembly
548
+ && ! methodAssembly . FullName . StartsWith ( TestFrameworkName ) )
549
+ {
550
+ TestAssembly = methodAssembly ;
551
+ return ;
552
+ }
554
553
}
555
554
}
556
- }
557
555
#endif
558
- }
556
+ }
559
557
}
0 commit comments