Skip to content

Commit 7302499

Browse files
committed
1 parent eaab03b commit 7302499

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

Q133689/Program.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.Http;
4+
using Microsoft.AspNetCore.Routing;
5+
using Microsoft.AspNetCore.Routing.Patterns;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Logging;
8+
using Microsoft.Extensions.Logging.Abstractions;
9+
using Microsoft.Extensions.Options;
10+
using Moq;
11+
12+
namespace Q133689
13+
{
14+
class Program
15+
{
16+
static async Task Main(string[] args)
17+
{
18+
var requestPath = "/cmt/p/14408628.html";
19+
20+
var routeTemplate = "/{blogApp}/{postType}/{idOrSlug}.html";
21+
var routeHandler = new RouteHandler((context) => null);
22+
23+
IServiceCollection services = new ServiceCollection();
24+
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
25+
services.AddOptions<RouteOptions>();
26+
var sp = services.BuildServiceProvider();
27+
28+
var routeOptions = sp.GetRequiredService<IOptions<RouteOptions>>();
29+
var inlineConstraintResolver = new DefaultInlineConstraintResolver(routeOptions, sp);
30+
var route = new Route(
31+
routeHandler,
32+
routeTemplate,
33+
defaults: null,
34+
constraints: new RouteValueDictionary(),
35+
dataTokens: null,
36+
inlineConstraintResolver: inlineConstraintResolver);
37+
38+
var httpContext = new DefaultHttpContext();
39+
httpContext.Request.Path = new PathString(requestPath);
40+
httpContext.RequestServices = sp;
41+
42+
var routeContext = new RouteContext(httpContext);
43+
await route.RouteAsync(routeContext);
44+
45+
Console.WriteLine("blogApp: " + routeContext.RouteData.Values["blogApp"]);
46+
Console.WriteLine("postType:" + routeContext.RouteData.Values["postType"]);
47+
Console.WriteLine("idOrSlug:" + routeContext.RouteData.Values["idOrSlug"]);
48+
}
49+
}
50+
}

Q133689/Q133689.csproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<FrameworkReference Include="Microsoft.AspNetCore.App"></FrameworkReference>
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Moq" Version="4.16.1" />
14+
</ItemGroup>
15+
16+
17+
</Project>

Q133689/Q133689.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31019.35
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Q133689", "Q133689.csproj", "{8D6FAF8C-153A-48C7-BA94-37C3928BA462}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{8D6FAF8C-153A-48C7-BA94-37C3928BA462}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8D6FAF8C-153A-48C7-BA94-37C3928BA462}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8D6FAF8C-153A-48C7-BA94-37C3928BA462}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8D6FAF8C-153A-48C7-BA94-37C3928BA462}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {8FDB8807-4FBB-4A35-A737-82A5C18B07C4}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)