Skip to content

Commit

Permalink
Move some shit around and add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
twitchax committed Oct 17, 2017
1 parent c8e2e61 commit 8651383
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 1 deletion.
54 changes: 54 additions & 0 deletions AspNetCore.Proxy.sln
@@ -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
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -10,6 +10,15 @@ ASP.NET Core Proxies made easy.
dotnet add package AspNetCore.Proxy
```

### Test

Download the source and run.

```bash
dotnet restore
dotnet test src/Test/AspNetCore.Proxy.Tests.csproj
```

### Compatibility

Latest .NET Standard 2.0.
Expand Down
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
<AssemblyName>AspNetCore.Proxy</AssemblyName>
<PackageId>AspNetCore.Proxy</PackageId>
<DocumentationFile>bin\AspNetCore.Proxy.xml</DocumentationFile>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions src/Test/AspNetCore.Proxy.Tests.csproj
@@ -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>
72 changes: 72 additions & 0 deletions src/Test/UnitTests.cs
@@ -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}");
}
}
}

0 comments on commit 8651383

Please sign in to comment.