Skip to content

Commit e8904da

Browse files
committed
Changed some of the tests to use the new MyController and MyApplication classes
1 parent 5903acf commit e8904da

File tree

7 files changed

+152
-95
lines changed

7 files changed

+152
-95
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
public static class TestApplication
3737
{
3838
private const string TestFrameworkName = "MyTested.AspNetCore.Mvc";
39+
private const string ReleaseDate = "2016-06-01";
3940

4041
private static readonly RequestDelegate NullHandler = c => TaskCache.CompletedTask;
4142
private static readonly ISet<IDefaultRegistrationPlugin> DefaultRegistrationPlugins = new HashSet<IDefaultRegistrationPlugin>();
@@ -161,6 +162,19 @@ internal static TestConfiguration TestConfiguration
161162
TestConfiguration.ApplicationName
162163
?? TestAssemblyName
163164
?? PlatformServices.Default.Application.ApplicationName;
165+
166+
public static void TryInitialize()
167+
{
168+
if (!initialiazed && TestConfiguration.AutomaticStartup)
169+
{
170+
startupType = TryFindDefaultStartupType();
171+
172+
if (startupType != null)
173+
{
174+
Initialize();
175+
}
176+
}
177+
}
164178

165179
internal static void LoadPlugins()
166180
{
@@ -194,19 +208,6 @@ internal static void LoadPlugins()
194208
});
195209
}
196210

197-
internal static void TryInitialize()
198-
{
199-
if (!initialiazed && TestConfiguration.AutomaticStartup)
200-
{
201-
startupType = TryFindDefaultStartupType();
202-
203-
if (startupType != null)
204-
{
205-
Initialize();
206-
}
207-
}
208-
}
209-
210211
internal static Type TryFindDefaultStartupType()
211212
{
212213
var applicationAssembly = Assembly.Load(new AssemblyName(testAssemblyName));
@@ -256,7 +257,7 @@ private static void PrepareLicensing()
256257
{
257258
TestCounter.SetLicenseData(
258259
TestConfiguration.Licenses,
259-
DateTime.ParseExact(MyMvc.ReleaseDate, "yyyy-MM-dd", CultureInfo.InvariantCulture),
260+
DateTime.ParseExact(ReleaseDate, "yyyy-MM-dd", CultureInfo.InvariantCulture),
260261
TestAssemblyName);
261262
}
262263

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace MyTested.AspNetCore.Mvc
2+
{
3+
using Builders;
4+
using Builders.Contracts.Application;
5+
using Internal.Application;
6+
using System;
7+
8+
public class MyApplication : ApplicationConfigurationBuilder
9+
{
10+
static MyApplication()
11+
{
12+
TestApplication.TryInitialize();
13+
}
14+
15+
public MyApplication()
16+
: this(null)
17+
{
18+
}
19+
20+
public MyApplication(Type startupType)
21+
: base(startupType)
22+
{
23+
}
24+
25+
public static IApplicationConfigurationBuilder IsUsingDefaultConfiguration()
26+
{
27+
return new MyApplication();
28+
}
29+
30+
public static IApplicationConfigurationBuilder StartsFrom<TStartup>()
31+
where TStartup : class
32+
{
33+
return new MyApplication(typeof(TStartup));
34+
}
35+
}
36+
}

src/MyTested.AspNetCore.Mvc.Core/MyController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static IControllerBuilder<TController> Instance(TController controller)
4141

4242
public static IControllerBuilder<TController> Instance(Func<TController> construction)
4343
{
44-
return new ControllerBuilder<TController>(new ControllerTestContext { ControllerConstruction = construction });
44+
return new MyController<TController>(construction);
4545
}
4646
}
4747
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace MyTested.AspNetCore.Mvc
2+
{
3+
using Builders.Contracts.Routes;
4+
using Builders.Routes;
5+
using Internal.Application;
6+
using Internal.TestContexts;
7+
8+
public class MyRoutes : RouteTestBuilder
9+
{
10+
static MyRoutes()
11+
{
12+
TestApplication.TryInitialize();
13+
}
14+
15+
public MyRoutes()
16+
: base(new RouteTestContext
17+
{
18+
Router = TestApplication.Router,
19+
Services = TestApplication.RouteServices
20+
})
21+
{
22+
}
23+
24+
public static IRouteTestBuilder Configuration()
25+
{
26+
return new MyRoutes();
27+
}
28+
}
29+
}

src/MyTested.AspNetCore.Mvc.Core/MyMvc.cs renamed to src/MyTested.AspNetCore.Mvc/MyMvc.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
namespace MyTested.AspNetCore.Mvc
22
{
33
using System;
4-
using Builders;
54
using Builders.Contracts.Application;
65
using Builders.Contracts.Controllers;
76
using Builders.Contracts.Routes;
8-
using Builders.Routes;
97
using Internal.Application;
10-
using Internal.TestContexts;
118

129
/// <summary>
1310
/// Starting point of the ASP.NET Core MVC testing framework. Provides methods to specify a test case.
1411
/// </summary>
1512
public static class MyMvc
1613
{
17-
internal const string ReleaseDate = "2016-06-01";
18-
1914
static MyMvc()
2015
{
2116
TestApplication.TryInitialize();
@@ -27,7 +22,7 @@ static MyMvc()
2722
/// <returns>Builder of <see cref="IApplicationConfigurationBuilder"/> type.</returns>
2823
public static IApplicationConfigurationBuilder IsUsingDefaultConfiguration()
2924
{
30-
return new ApplicationConfigurationBuilder(null);
25+
return new MyApplication();
3126
}
3227

3328
/// <summary>
@@ -36,9 +31,9 @@ public static IApplicationConfigurationBuilder IsUsingDefaultConfiguration()
3631
/// <typeparam name="TStartup">Type of startup class.</typeparam>
3732
/// <returns>Builder of <see cref="IApplicationConfigurationBuilder"/> type.</returns>
3833
public static IApplicationConfigurationBuilder StartsFrom<TStartup>()
39-
where TStartup : class, new()
34+
where TStartup : class
4035
{
41-
return new ApplicationConfigurationBuilder(typeof(TStartup));
36+
return new MyApplication(typeof(TStartup));
4237
}
4338

4439
/// <summary>
@@ -47,11 +42,7 @@ public static IApplicationConfigurationBuilder StartsFrom<TStartup>()
4742
/// <returns>Test builder of <see cref="IRouteTestBuilder"/> type.</returns>
4843
public static IRouteTestBuilder Routes()
4944
{
50-
return new RouteTestBuilder(new RouteTestContext
51-
{
52-
Router = TestApplication.Router,
53-
Services = TestApplication.RouteServices
54-
});
45+
return new MyRoutes();
5546
}
5647

5748
/// <summary>

0 commit comments

Comments
 (0)