Add integration test

This commit is contained in:
Ryan Nowak 2017-09-27 16:12:45 -07:00
parent 5fed462123
commit 44d08dcb2b
9 changed files with 287 additions and 2 deletions

View File

@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26824.3000
VisualStudioVersion = 15.0.26927.0
MinimumVisualStudioVersion = 15.0.26730.03
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0E966C37-7334-4D96-AAF6-9F49FBD166E3}"
ProjectSection(SolutionItems) = preProject
@ -53,10 +53,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Dispat
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Dispatcher.Abstractions.Test", "test\Microsoft.AspNetCore.Dispatcher.Abstractions.Test\Microsoft.AspNetCore.Dispatcher.Abstractions.Test.csproj", "{14ACBCB4-3B99-425F-A5E2-07E228DEBF63}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DispatcherSample", "samples\DispatcherSample\DispatcherSample.csproj", "{6EBC8AE2-CFF7-46E1-8427-9111FD4F3E85}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DispatcherSample", "samples\DispatcherSample\DispatcherSample.csproj", "{6EBC8AE2-CFF7-46E1-8427-9111FD4F3E85}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Dispatcher.Performance", "benchmarks\Microsoft.AspNetCore.Dispatcher.Performance\Microsoft.AspNetCore.Dispatcher.Performance.csproj", "{30AF355D-E3AB-4FF5-8A59-A253AFEBA26A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Dispatcher.FunctionalTest", "test\Microsoft.AspNetCore.Dispatcher.FunctionalTest\Microsoft.AspNetCore.Dispatcher.FunctionalTest.csproj", "{32107601-C9BE-467B-894C-C9F2E35F03E4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -229,6 +231,18 @@ Global
{30AF355D-E3AB-4FF5-8A59-A253AFEBA26A}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{30AF355D-E3AB-4FF5-8A59-A253AFEBA26A}.Release|x86.ActiveCfg = Release|Any CPU
{30AF355D-E3AB-4FF5-8A59-A253AFEBA26A}.Release|x86.Build.0 = Release|Any CPU
{32107601-C9BE-467B-894C-C9F2E35F03E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32107601-C9BE-467B-894C-C9F2E35F03E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32107601-C9BE-467B-894C-C9F2E35F03E4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{32107601-C9BE-467B-894C-C9F2E35F03E4}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{32107601-C9BE-467B-894C-C9F2E35F03E4}.Debug|x86.ActiveCfg = Debug|Any CPU
{32107601-C9BE-467B-894C-C9F2E35F03E4}.Debug|x86.Build.0 = Debug|Any CPU
{32107601-C9BE-467B-894C-C9F2E35F03E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32107601-C9BE-467B-894C-C9F2E35F03E4}.Release|Any CPU.Build.0 = Release|Any CPU
{32107601-C9BE-467B-894C-C9F2E35F03E4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{32107601-C9BE-467B-894C-C9F2E35F03E4}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{32107601-C9BE-467B-894C-C9F2E35F03E4}.Release|x86.ActiveCfg = Release|Any CPU
{32107601-C9BE-467B-894C-C9F2E35F03E4}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -248,6 +262,7 @@ Global
{14ACBCB4-3B99-425F-A5E2-07E228DEBF63} = {95359B4B-4C85-4B44-A75B-0621905C4CF6}
{6EBC8AE2-CFF7-46E1-8427-9111FD4F3E85} = {C3ADD55B-B9C7-4061-8AD4-6A70D1AE3B2E}
{30AF355D-E3AB-4FF5-8A59-A253AFEBA26A} = {D5F39F59-5725-4127-82E7-67028D006185}
{32107601-C9BE-467B-894C-C9F2E35F03E4} = {95359B4B-4C85-4B44-A75B-0621905C4CF6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {36C8D815-B7F1-479D-894B-E606FB8DECDA}

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Microsoft.AspNetCore.Routing.DecisionTree.Sources</id>
<version>2.1.0-preview1-t000</version>
<authors>sharedsources</authors>
<owners>sharedsources</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Microsoft.AspNetCore.Routing.DecisionTree.Sources</description>
<repository type="git" url="https://github.com/aspnet/Routing" />
<dependencies>
<group targetFramework=".NETStandard1.0" />
</dependencies>
<contentFiles>
<files include="cs/netstandard1.0/DecisionCriterion.cs" buildAction="Compile" />
<files include="cs/netstandard1.0/DecisionCriterionValue.cs" buildAction="Compile" />
<files include="cs/netstandard1.0/DecisionCriterionValueEqualityComparer.cs" buildAction="Compile" />
<files include="cs/netstandard1.0/DecisionTreeBuilder.cs" buildAction="Compile" />
<files include="cs/netstandard1.0/DecisionTreeNode.cs" buildAction="Compile" />
<files include="cs/netstandard1.0/IClassifier.cs" buildAction="Compile" />
<files include="cs/netstandard1.0/ItemDescriptor.cs" buildAction="Compile" />
</contentFiles>
</metadata>
<files>
<file src="D:\k\Routing\shared\Microsoft.AspNetCore.Routing.DecisionTree.Sources\DecisionCriterion.cs" target="contentFiles\cs\netstandard1.0\DecisionCriterion.cs" />
<file src="D:\k\Routing\shared\Microsoft.AspNetCore.Routing.DecisionTree.Sources\DecisionCriterionValue.cs" target="contentFiles\cs\netstandard1.0\DecisionCriterionValue.cs" />
<file src="D:\k\Routing\shared\Microsoft.AspNetCore.Routing.DecisionTree.Sources\DecisionCriterionValueEqualityComparer.cs" target="contentFiles\cs\netstandard1.0\DecisionCriterionValueEqualityComparer.cs" />
<file src="D:\k\Routing\shared\Microsoft.AspNetCore.Routing.DecisionTree.Sources\DecisionTreeBuilder.cs" target="contentFiles\cs\netstandard1.0\DecisionTreeBuilder.cs" />
<file src="D:\k\Routing\shared\Microsoft.AspNetCore.Routing.DecisionTree.Sources\DecisionTreeNode.cs" target="contentFiles\cs\netstandard1.0\DecisionTreeNode.cs" />
<file src="D:\k\Routing\shared\Microsoft.AspNetCore.Routing.DecisionTree.Sources\IClassifier.cs" target="contentFiles\cs\netstandard1.0\IClassifier.cs" />
<file src="D:\k\Routing\shared\Microsoft.AspNetCore.Routing.DecisionTree.Sources\ItemDescriptor.cs" target="contentFiles\cs\netstandard1.0\ItemDescriptor.cs" />
</files>
</package>

View File

@ -0,0 +1,52 @@
{
"version": 3,
"targets": {
".NETStandard,Version=v1.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
".NETStandard,Version=v1.0": []
},
"packageFolders": {
"C:\\Users\\rynowak\\.nuget\\packages\\": {}
},
"project": {
"version": "2.1.0-preview1-t000",
"restore": {
"projectUniqueName": "C:\\Users\\rynowak\\.dotnet\\buildtools\\korebuild\\2.1.0-preview1-15509\\modules\\sharedsources\\sharedsources.csproj",
"projectName": "Microsoft.AspNetCore.Routing.DecisionTree.Sources",
"projectPath": "C:\\Users\\rynowak\\.dotnet\\buildtools\\korebuild\\2.1.0-preview1-15509\\modules\\sharedsources\\sharedsources.csproj",
"packagesPath": "C:\\Users\\rynowak\\.nuget\\packages\\",
"outputPath": "D:\\k\\Routing/shared/Microsoft.AspNetCore.Routing.DecisionTree.Sourcesobj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\rynowak\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"netstandard1.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"C:\\Users\\rynowak\\.dotnet\\NuGetFallbackFolder": {},
"C:\\Users\\rynowak\\.dotnet\\x64\\sdk\\NuGetFallbackFolder": {},
"C:\\Users\\rynowak\\private_nuget": {},
"https://www.nuget.org/api/v2/": {}
},
"frameworks": {
"netstandard1.0": {
"projectReferences": {}
}
},
"warningProperties": {
"allWarningsAsErrors": true,
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"netstandard1.0": {}
}
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">D:\k\Routing\shared\Microsoft.AspNetCore.Routing.DecisionTree.Sourcesobj\project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\rynowak\.nuget\packages\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">4.4.0</NuGetToolVersion>
</PropertyGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,34 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Net.Http;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
namespace Microsoft.AspNetCore.Dispatcher.FunctionalTest
{
public class ApiAppFixture : IDisposable
{
public ApiAppFixture()
{
var builder = new WebHostBuilder();
builder.UseStartup<ApiAppStartup>();
Server = new TestServer(builder);
Client = Server.CreateClient();
Client.BaseAddress = new Uri("http://locahost");
}
public HttpClient Client { get; }
public TestServer Server { get; }
public void Dispose()
{
Client.Dispose();
Server.Dispose();
}
}
}

View File

@ -0,0 +1,80 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing.Dispatcher;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Dispatcher.FunctionalTest
{
public class ApiAppStartup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging();
services.AddDispatcher();
services.AddRouting();
services.Configure<DispatcherOptions>(ConfigureDispatcher);
}
public void Configure(IApplicationBuilder app, ILogger<ApiAppStartup> logger)
{
app.UseDispatcher();
app.Use(next => async (context) =>
{
logger.LogInformation("Executing fake CORS middleware");
var feature = context.Features.Get<IDispatcherFeature>();
var policy = feature.Endpoint?.Metadata.OfType<CorsPolicyMetadata>().LastOrDefault();
logger.LogInformation("using CORS policy {PolicyName}", policy?.Name ?? "default");
await next(context);
});
app.Use(next => async (context) =>
{
logger.LogInformation("Executing fake AuthZ middleware");
var feature = context.Features.Get<IDispatcherFeature>();
var policy = feature.Endpoint?.Metadata.OfType<AuthorizationPolicyMetadata>().LastOrDefault();
if (policy != null)
{
logger.LogInformation("using Auth policy {PolicyName}", policy.Name);
}
await next(context);
});
}
public void ConfigureDispatcher(DispatcherOptions options)
{
options.Dispatchers.Add(new TreeDispatcher()
{
Endpoints =
{
new SimpleEndpoint(Products_Get, new object[]{ new RouteTemplateMetadata("api/products"), }),
},
});
options.HandlerFactories.Add(endpoint => (endpoint as SimpleEndpoint)?.HandlerFactory);
}
private Task Products_Get(HttpContext httpContext) => httpContext.Response.WriteAsync("Hello, Products_Get");
private class CorsPolicyMetadata
{
public string Name { get; set; }
}
private class AuthorizationPolicyMetadata
{
public string Name { get; set; }
}
}
}

View File

@ -0,0 +1,34 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.AspNetCore.Dispatcher.FunctionalTest
{
public class ApiAppTest : IClassFixture<ApiAppFixture>
{
public ApiAppTest(ApiAppFixture app)
{
Client = app.Client;
}
public HttpClient Client { get; }
[Fact]
public async Task ApiApp_CanRouteTo_LiteralEndpoint()
{
// Arrange
var request = new HttpRequestMessage(HttpMethod.Get, "/api/products");
// Act
var response = await Client.SendAsync(request);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("Hello, Products_Get", await response.Content.ReadAsStringAsync());
}
}
}

View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Routing\Microsoft.AspNetCore.Routing.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
</ItemGroup>
</Project>