Skip to content

Commit b24bb41

Browse files
committed
Extracted RouteHandlerMock (#326)
1 parent d635298 commit b24bb41

File tree

10 files changed

+31
-37
lines changed

10 files changed

+31
-37
lines changed

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/Actions/ActionContextAccessorMock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Microsoft.AspNetCore.Mvc;
44
using Microsoft.AspNetCore.Mvc.Infrastructure;
55

6-
public class ActionContextAccessorMock : ActionContextAccessor
6+
public class ActionContextAccessorMock
77
{
88
internal static readonly IActionContextAccessor Null = new NullActionContextAccessor();
99

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/Actions/ActionDescriptorMock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Microsoft.AspNetCore.Mvc.Abstractions;
88
using Microsoft.AspNetCore.Mvc.Filters;
99

10-
public class ActionDescriptorMock : ActionDescriptor
10+
public class ActionDescriptorMock
1111
{
1212
public static ActionDescriptor Default
1313
=> new ControllerActionDescriptor

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Threading.Tasks;
7+
using Internal.Routing;
78
using Microsoft.AspNetCore.Builder;
89
using Microsoft.AspNetCore.Http;
910
using Microsoft.AspNetCore.Http.Features;
@@ -88,6 +89,7 @@ public IApplicationBuilder Use(Func<RequestDelegate, RequestDelegate> middleware
8889
this.ExtractLegacyRoutes(middleware);
8990

9091
this.components.Add(middleware);
92+
9193
return this;
9294
}
9395

@@ -148,7 +150,7 @@ private void ExtractEndpointRoutes(Func<RequestDelegate, RequestDelegate> middle
148150

149151
var routeBuilder = new RouteBuilder(this)
150152
{
151-
DefaultHandler = new RouteHandler(c => Task.CompletedTask)
153+
DefaultHandler = RouteHandlerMock.Null
152154
};
153155

154156
var endpointDataSources = routeOptions.Exposed().EndpointDataSources;
@@ -165,6 +167,7 @@ private void ExtractEndpointRoutes(Func<RequestDelegate, RequestDelegate> middle
165167
{
166168
var routeNameMetadata = route.Metadata.GetMetadata<IRouteNameMetadata>();
167169
var routeName = routeNameMetadata?.RouteName;
170+
168171
if (routeName != null && !routeEndpoints.ContainsKey(routeName))
169172
{
170173
routeEndpoints[routeName] = route;

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
namespace MyTested.AspNetCore.Mvc.Internal.Application
22
{
33
using System;
4+
using System.Globalization;
45
using Configuration;
56
using Licensing;
67
using Microsoft.AspNetCore.Builder;
7-
using Services;
8-
using System.Globalization;
9-
using System.Threading.Tasks;
108
using Server;
9+
using Services;
1110

1211
public static partial class TestApplication
1312
{
@@ -19,8 +18,6 @@ static TestApplication()
1918
{
2019
Sync = new object();
2120

22-
NullHandler = c => Task.CompletedTask;
23-
2421
TestWebServer.TryFindTestAssembly();
2522
}
2623

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
namespace MyTested.AspNetCore.Mvc.Internal.Application
22
{
33
using System;
4+
using Internal.Routing;
45
using Microsoft.AspNetCore.Builder;
5-
using Microsoft.AspNetCore.Http;
66
using Microsoft.AspNetCore.Routing;
77

88
public static partial class TestApplication
99
{
10-
private static readonly RequestDelegate NullHandler;
11-
1210
private static volatile IRouter router;
1311

1412
public static IRouter Router
@@ -32,7 +30,7 @@ private static void PrepareApplicationAndRouting()
3230

3331
var routeBuilder = new RouteBuilder(applicationBuilder)
3432
{
35-
DefaultHandler = new RouteHandler(NullHandler)
33+
DefaultHandler = RouteHandlerMock.Null
3634
};
3735

3836
for (int i = 0; i < applicationBuilder.Routes.Count; i++)

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/Logging/LoggerFactoryMock.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ public void AddProvider(ILoggerProvider provider)
3030
/// <param name="categoryName">Not used category name parameter. This method is used for testing with <see cref="ILogger"/> service.</param>
3131
/// <returns>Mock of <see cref="ILogger"/>.</returns>
3232
public ILogger CreateLogger(string categoryName)
33-
{
34-
return LoggerMock.Instance;
35-
}
33+
=> LoggerMock.Instance;
3634

3735
/// <summary>
3836
/// Does nothing. Used for testing with ILogger service.

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/Logging/LoggerMock.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,14 @@ public class LoggerMock : ILogger
1717
/// <param name="state">Not used parameter. Used for testing with <see cref="ILogger"/> service.</param>
1818
/// <returns>Disposable object.</returns>
1919
public IDisposable BeginScope<TState>(TState state)
20-
{
21-
return DisposableMock.Instance;
22-
}
20+
=> DisposableMock.Instance;
2321

2422
/// <summary>
2523
/// Does nothing. Always returns false.
2624
/// </summary>
2725
/// <param name="logLevel">Not used parameter. Used for testing with <see cref="ILogger"/> service.</param>
2826
/// <returns>Always false.</returns>
29-
public bool IsEnabled(LogLevel logLevel)
30-
{
31-
return false;
32-
}
27+
public bool IsEnabled(LogLevel logLevel) => false;
3328

3429
/// <summary>
3530
/// Does nothing. Used for testing purposes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace MyTested.AspNetCore.Mvc.Internal.Routing
2+
{
3+
using System.Threading.Tasks;
4+
using Microsoft.AspNetCore.Routing;
5+
6+
public class RouteHandlerMock
7+
{
8+
internal static readonly IRouter Null = new RouteHandler(c => Task.CompletedTask);
9+
}
10+
}

src/MyTested.AspNetCore.Mvc.Controllers/Internal/Controllers/ControllerContextMock.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
public class ControllerContextMock : ControllerContext
1212
{
1313
private ControllerContextMock(ActionContext actionContext)
14-
: base(actionContext)
15-
{
16-
this.PrepareControllerContext(actionContext);
17-
}
18-
14+
: base(actionContext)
15+
=> this.PrepareControllerContext(actionContext);
16+
1917
public static ControllerContext Default(HttpTestContext testContext)
2018
=> FromActionContext(testContext, new ActionContext());
2119

src/MyTested.AspNetCore.Mvc.ViewComponents/Internal/ViewComponents/ViewComponentContextMock.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@
1010
public class ViewComponentContextMock : ViewComponentContext
1111
{
1212
private HttpTestContext testContext;
13-
14-
private ViewComponentContextMock(HttpTestContext testContext, ViewComponentContext viewComponentContext)
15-
{
16-
this.PrepareViewComponentContext(testContext, viewComponentContext);
17-
}
18-
13+
14+
private ViewComponentContextMock(HttpTestContext testContext, ViewComponentContext viewComponentContext)
15+
=> this.PrepareViewComponentContext(testContext, viewComponentContext);
16+
1917
private HttpTestContext TestContext
2018
{
21-
get
22-
{
23-
return this.testContext;
24-
}
19+
get => this.testContext;
2520

2621
set
2722
{

0 commit comments

Comments
 (0)