Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move some shit around and add tests.
- Loading branch information
Showing
8 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7519C830-96CB-4D35-B7FC-8EC7240FBF15}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore.Proxy", "src\Core\AspNetCore.Proxy.csproj", "{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore.Proxy.Tests", "src\Test\AspNetCore.Proxy.Tests.csproj", "{81FBEDBA-21BB-4944-8302-926855B0AEE0}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}.Debug|x64.ActiveCfg = Debug|x64 | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}.Debug|x64.Build.0 = Debug|x64 | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}.Debug|x86.ActiveCfg = Debug|x86 | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}.Debug|x86.Build.0 = Debug|x86 | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}.Release|x64.ActiveCfg = Release|x64 | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}.Release|x64.Build.0 = Release|x64 | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}.Release|x86.ActiveCfg = Release|x86 | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A}.Release|x86.Build.0 = Release|x86 | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0}.Debug|x64.ActiveCfg = Debug|x64 | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0}.Debug|x64.Build.0 = Debug|x64 | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0}.Debug|x86.ActiveCfg = Debug|x86 | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0}.Debug|x86.Build.0 = Debug|x86 | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0}.Release|x64.ActiveCfg = Release|x64 | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0}.Release|x64.Build.0 = Release|x64 | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0}.Release|x86.ActiveCfg = Release|x86 | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{5717E64A-9EBC-409C-8AF6-71F2A93EB71A} = {7519C830-96CB-4D35-B7FC-8EC7240FBF15} | ||
{81FBEDBA-21BB-4944-8302-926855B0AEE0} = {7519C830-96CB-4D35-B7FC-8EC7240FBF15} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" /> | ||
<PackageReference Include="xunit" Version="2.2.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Core\AspNetCore.Proxy.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Newtonsoft.Json.Linq; | ||
using Xunit; | ||
|
||
namespace AspNetCore.Proxy.Tests | ||
{ | ||
public class UnitTests | ||
{ | ||
private readonly TestServer _server; | ||
private readonly HttpClient _client; | ||
|
||
public UnitTests() | ||
{ | ||
_server = new TestServer(new WebHostBuilder().UseStartup<Startup>()); | ||
_client = _server.CreateClient(); | ||
} | ||
|
||
[Fact] | ||
public async Task ProxyAttribute() | ||
{ | ||
var response = await _client.GetAsync("api/posts/1"); | ||
response.EnsureSuccessStatusCode(); | ||
|
||
var responseString = await response.Content.ReadAsStringAsync(); | ||
Assert.Contains("sunt aut facere repellat provident occaecati excepturi optio reprehenderit", JObject.Parse(responseString).Value<string>("title")); | ||
} | ||
|
||
[Fact] | ||
public async Task ProxyMiddleware() | ||
{ | ||
var response = await _client.GetAsync("api/comments/1"); | ||
response.EnsureSuccessStatusCode(); | ||
|
||
var responseString = await response.Content.ReadAsStringAsync(); | ||
Console.WriteLine(responseString); | ||
Assert.Contains("id labore ex et quam laborum", JObject.Parse(responseString).Value<string>("name")); | ||
} | ||
} | ||
|
||
public class Startup | ||
{ | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddRouting(); | ||
} | ||
|
||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | ||
{ | ||
app.UseProxies(); | ||
|
||
app.UseProxy("api/comments/{postId}", (args) => { | ||
return Task.FromResult($"https://jsonplaceholder.typicode.com/comments/{args["postId"]}"); | ||
}); | ||
} | ||
} | ||
|
||
public static class UseProxies | ||
{ | ||
[ProxyRoute("api/posts/{postId}")] | ||
public static Task<string> ProxyGoogle(int postId) | ||
{ | ||
return Task.FromResult($"https://jsonplaceholder.typicode.com/posts/{postId}"); | ||
} | ||
} | ||
} |