Skip to content

Commit e337e78

Browse files
committed
Removed IsUsingDefaultServices (#135 #168)
1 parent cf6273a commit e337e78

File tree

69 files changed

+628
-543
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+628
-543
lines changed

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/Application/TestApplication.cs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
using Microsoft.AspNetCore.Hosting.Builder;
1515
using Microsoft.AspNetCore.Hosting.Internal;
1616
using Microsoft.AspNetCore.Http;
17+
#if NET451
18+
using Microsoft.AspNetCore.Mvc.ApplicationParts;
19+
#endif
1720
using Microsoft.AspNetCore.Mvc.Internal;
1821
using Microsoft.AspNetCore.Routing;
1922
using Microsoft.DotNet.InternalAbstractions;
@@ -72,7 +75,6 @@ static TestApplication()
7275

7376
PrepareTestConfiguration();
7477
FindTestAssemblyName();
75-
PrepareLicensing();
7678
}
7779

7880
public static IServiceProvider Services
@@ -196,7 +198,7 @@ public static void TryInitialize()
196198
}
197199

198200
internal static DependencyContext LoadDependencyContext()
199-
=> TestAssembly != null
201+
=> TestAssembly != null
200202
? DependencyContext.Load(TestAssembly)
201203
?? DependencyContext.Default
202204
: DependencyContext.Default;
@@ -213,7 +215,7 @@ internal static void LoadPlugins(DependencyContext dependencyContext)
213215
{
214216
throw new InvalidOperationException("Test plugins could not be loaded. Depending on your project's configuration you may need to set the 'preserveCompilationContext' property under 'buildOptions' to 'true' in the test assembly's 'project.json' file and/or may need to call '.StartsFrom<TStartup>().WithTestAssembly(this)'.");
215217
}
216-
218+
217219
plugins.ForEach(t =>
218220
{
219221
var plugin = Activator.CreateInstance(t);
@@ -265,13 +267,15 @@ internal static Type TryFindDefaultStartupType()
265267
// check root of the test project
266268
var startup =
267269
applicationAssembly.GetType(defaultStartupType) ??
268-
applicationAssembly.GetType($"{testAssemblyName}.{defaultStartupType}");
270+
applicationAssembly.GetType($"{applicationAssembly.GetName().Name}.{defaultStartupType}");
269271

270272
return startup;
271273
}
272274

273275
private static void Initialize()
274276
{
277+
PrepareLicensing();
278+
275279
var dependencyContext = LoadDependencyContext();
276280
LoadPlugins(dependencyContext);
277281

@@ -297,7 +301,7 @@ private static IConfiguration PrepareTestConfiguration()
297301

298302
private static void FindTestAssemblyName()
299303
{
300-
testAssemblyName = TestConfiguration.General.TestAssemblyName
304+
testAssemblyName = TestConfiguration.General.TestAssemblyName
301305
?? TestAssembly?.GetName().Name
302306
?? DependencyContext
303307
.Default
@@ -401,7 +405,7 @@ private static void PrepareServices(IServiceCollection serviceCollection, Startu
401405

402406
#if NET451
403407
var baseStartupType = StartupType;
404-
while(baseStartupType?.BaseType != typeof(object))
408+
while (baseStartupType?.BaseType != typeof(object))
405409
{
406410
baseStartupType = baseStartupType.BaseType;
407411
}
@@ -517,29 +521,34 @@ private static void Reset()
517521
TestAssembly = null;
518522
TestServiceProvider.Current = null;
519523
TestServiceProvider.ClearServiceLifetimes();
520-
}
524+
DefaultRegistrationPlugins.Clear();
525+
ServiceRegistrationPlugins.Clear();
526+
RoutingServiceRegistrationPlugins.Clear();
527+
InitializationPlugins.Clear();
528+
LicenseValidator.ClearLicenseDetails();
529+
}
521530

522531
#if NET451
523-
private static void FindTestAssembly()
524-
{
525-
var executingAssembly = Assembly.GetExecutingAssembly();
532+
private static void FindTestAssembly()
533+
{
534+
var executingAssembly = Assembly.GetExecutingAssembly();
526535

527-
var stackTrace = new StackTrace(false);
536+
var stackTrace = new StackTrace(false);
528537

529-
foreach (var frame in stackTrace.GetFrames())
530-
{
531-
var method = frame.GetMethod();
532-
var methodAssembly = method?.DeclaringType?.Assembly;
538+
foreach (var frame in stackTrace.GetFrames())
539+
{
540+
var method = frame.GetMethod();
541+
var methodAssembly = method?.DeclaringType?.Assembly;
533542

534-
if (methodAssembly != null
535-
&& methodAssembly != executingAssembly
536-
&& !methodAssembly.FullName.StartsWith(TestFrameworkName))
537-
{
538-
TestAssembly = methodAssembly;
539-
return;
540-
}
543+
if (methodAssembly != null
544+
&& methodAssembly != executingAssembly
545+
&& !methodAssembly.FullName.StartsWith(TestFrameworkName))
546+
{
547+
TestAssembly = methodAssembly;
548+
return;
541549
}
542550
}
543-
#endif
544551
}
552+
#endif
553+
}
545554
}

src/MyTested.AspNetCore.Mvc.Abstractions/MyApplication.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ public MyApplication(Type startupType)
2121
: base(startupType)
2222
{
2323
}
24-
25-
public static IApplicationConfigurationBuilder IsUsingDefaultConfiguration()
26-
{
27-
return new MyApplication();
28-
}
29-
24+
3025
public static IApplicationConfigurationBuilder StartsFrom<TStartup>()
3126
where TStartup : class
3227
{

src/MyTested.AspNetCore.Mvc/MyMvc.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,7 @@ static MyMvc()
1616
{
1717
TestApplication.TryInitialize();
1818
}
19-
20-
/// <summary>
21-
/// Sets default configuration on the tested application. Calls 'AddMvc' on the services collection and 'UseMvcWithDefaultRoute' on the application builder.
22-
/// </summary>
23-
/// <returns>Builder of <see cref="IApplicationConfigurationBuilder"/> type.</returns>
24-
public static IApplicationConfigurationBuilder IsUsingDefaultConfiguration()
25-
{
26-
return new MyApplication();
27-
}
28-
19+
2920
/// <summary>
3021
/// Configures the tested application with the provided startup class.
3122
/// </summary>

0 commit comments

Comments
 (0)