Skip to content

Commit

Permalink
Start of open source prep (#1)
Browse files Browse the repository at this point in the history
* Move results.Clear() into Dispose(), test for one fail not failing the whole set

* Change to HotPotatoClient, HotPotatoRequest, HotPotatoResponse

* Cleaning up some HotPotatoClient calls

* Version and readme update

* Trying ci action

* Commenting out RestoreSources

* Multiple Setup .NET Core version steps

* Specify sln

* Accidentally removed checkout step

* v1 setup-dotnet

* Separate 2.2 and 3.1 E2E tests

* Trying just 3.1 for the E2E tests

* Commenting out E2E tests for now

* Try to set Action to run on every branch

* GitVersion test 1

* yml not yaml

* Capitalization?

* Seeing how a cut-down yml acts

* Test fetch-depth

* Re-adding Mainline to yml

* Release test 1

* Possible spacing issue

* See if a step env sets global

* Colon syntax

* Syntax for IMAGE_VERSION

* Dump outputs

* Trying export for global

* Release test 2

* Test release bools

* Create pre-release package

* See how Newman action is working

* Forgot extension - didn't cause fail

* Try Start Server step

* Commenting out Newman for now, checking ref output

* Master condition for release

* Testing archiving artifacts

* Testing archiving artifacts 2

* Testing archiving artifacts 3

* Testing archiving artifacts 4

* Testing archiving artifacts 4 6cf6247

Whole code coverage dir since the extensions were being problematic

* Testing archiving artifacts 5

$GITHUB_WORKSPACE for cov

* Uncomment master condition for Create Release

* Update readme with try-finally option

* bump to 2.0.0, remove ref log
  • Loading branch information
davidmbillie authored Jul 9, 2021
1 parent af040f4 commit 04917e8
Show file tree
Hide file tree
Showing 34 changed files with 308 additions and 157 deletions.
111 changes: 111 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Hot Potato CI

on:
push:
pull_request:
branches: [ master ]

env:
isMaster: ${{ github.ref == 'refs/heads/master' }}

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.x'

- name: Generate Version
id: gitversion
uses: gittools/actions/gitversion/[email protected]
with:
useConfigFile: true
configFilePath: './GitVersion.yml'

- name: Display GitVersion outputs
run: |
echo "MajorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }}"
echo "NuGetVersionV2: ${{ steps.gitversion.outputs.nuGetVersionV2 }}"
- name: Setup .NET Core 2.2
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.2.x

- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x

- name: Build
run: |
dotnet build --configuration Release -p:Version=${{ steps.gitversion.outputs.majorMinorPatch }}
- name: Run Unit Tests .NET 2.2
run: |
dotnet test ./test/HotPotato.Core.Test/HotPotato.Core.Test.csproj -f "netcoreapp2.2" -c Release -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=$GITHUB_WORKSPACE/test/coverage/coreCoverage.xml -p:Exclude="[xunit.*]*" -l:"JUnit;LogFilePath=$GITHUB_WORKSPACE/test/results/coreResults.xml" --no-restore --no-build
dotnet test ./test/HotPotato.AspNetCore.Middleware.Test/HotPotato.AspNetCore.Middleware.Test.csproj -f "netcoreapp2.2" -c Release -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=$GITHUB_WORKSPACE/test/coverage/middlewareCoverage.xml -p:Include="[*.Middleware]*" -l:"JUnit;LogFilePath=$GITHUB_WORKSPACE/test/results/middlewareResults.xml" --no-restore --no-build
dotnet test ./test/HotPotato.OpenApi.Test/HotPotato.OpenApi.Test.csproj -f "netcoreapp2.2" -c Release -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=$GITHUB_WORKSPACE/test/coverage/openApiCoverage.xml -p:Include="[*.OpenApi]*" -l:"JUnit;LogFilePath=$GITHUB_WORKSPACE/test/results/openapiResults.xml" --no-restore --no-build
- name: Run Unit Tests .NET 3.1
run: |
dotnet test ./test/HotPotato.Core.Test/HotPotato.Core.Test.csproj -f "netcoreapp3.1" -c Release -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=$GITHUB_WORKSPACE/test/coverage/coreCoverage.xml -p:Exclude="[xunit.*]*" -l:"JUnit;LogFilePath=$GITHUB_WORKSPACE/test/results/coreResults.xml" --no-restore --no-build
dotnet test ./test/HotPotato.AspNetCore.Middleware.Test/HotPotato.AspNetCore.Middleware.Test.csproj -f "netcoreapp3.1" -c Release -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=$GITHUB_WORKSPACE/test/coverage/middlewareCoverage.xml -p:Include="[*.Middleware]*" -l:"JUnit;LogFilePath=$GITHUB_WORKSPACE/test/results/middlewareResults.xml" --no-restore --no-build
dotnet test ./test/HotPotato.OpenApi.Test/HotPotato.OpenApi.Test.csproj -f "netcoreapp3.1" -c Release -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=$GITHUB_WORKSPACE/test/coverage/openApiCoverage.xml -p:Include="[*.OpenApi]*" -l:"JUnit;LogFilePath=$GITHUB_WORKSPACE/test/results/openapiResults.xml" --no-restore --no-build
- name: Run Integration Tests
run: |
dotnet test ./test/HotPotato.Integration.Test/HotPotato.Integration.Test.csproj -f "netcoreapp2.2" -c Release -l:"JUnit;LogFilePath=$GITHUB_WORKSPACE/test/results/integrationResults.xml" --no-restore --no-build
dotnet test ./test/HotPotato.Integration.Test/HotPotato.Integration.Test.csproj -f "netcoreapp3.1" -c Release -l:"JUnit;LogFilePath=$GITHUB_WORKSPACE/test/results/integrationResults.xml" --no-restore --no-build
# Commenting out until we figure out the best way to deal with the hosted spec for these tests
# - name: Run E2E Tests .NET 2.2
# run: |
# dotnet test ./test/HotPotato.E2E.Test/HotPotato.E2E.Test.csproj -f "netcoreapp2.2" -c Release -l:"JUnit;LogFilePath=$GITHUB_WORKSPACE/test/results/E2EResults.xml" --no-restore --no-build
# - name: Run E2E Tests .NET 3.1
# run: |
# dotnet test ./test/HotPotato.TestServer.Test/HotPotato.TestServ.Test.csproj -c Release -l:"JUnit;LogFilePath=$GITHUB_WORKSPACE/test/results/testServerResults.xml" --no-restore --no-build
# dotnet test ./test/HotPotato.E2E.Test/HotPotato.E2E.Test.csproj -f "netcoreapp3.1" -c Release -l:"JUnit;LogFilePath=$GITHUB_WORKSPACE/test/results/E2EResults.xml" --no-restore --no-build

# - name: Start Hot Potato For Postman Tests
# run: |
# dotnet $GITHUB_WORKSPACE/src/HotPotato.AspNetCore.Host/bin/Release/netcoreapp3.1/HotPotato.AspNetCore.Host.dll &
# dotnet $GITHUB_WORKSPACE/test/HotPotato.Api/bin/Release/netcoreapp3.1/HotPotato.Api.dll &

# - name: Run Postman Tests
# uses: anthonyvscode/newman-action@v1
# with:
# collection: ./test/HappyPathTests.postman_collection.json
# reporters: cli

- name: Archive code coverage results
uses: actions/upload-artifact@v2
with:
name: code-coverage-reports
path: ./test/coverage/*.xml

- name: Archive test results
uses: actions/upload-artifact@v2
with:
name: test-results
path: ./test/results/*.xml

- name: Create Release
uses: actions/create-release@v1
if: ${{ success() && env.isMaster == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ steps.gitversion.outputs.nuGetVersionV2 }}
release_name: ${{ steps.gitversion.outputs.nuGetVersionV2 }}
draft: false
prerelease: false
6 changes: 2 additions & 4 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
next-version: 0.1.2
next-version: 2.0.0
mode: Mainline
branches:
master:
regex: (^master$|^origin\/master$)
develop:
regex: (^dev(elop)?(ment)?$|^origin\/dev(elop)?(ment)?$)
regex: (^master$|^origin\/master$)
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ var apiBuilder = new WebHostBuilder()
apiServer = new TestServer(apiBuilder);
apiServer.BaseAddress = new Uri(TestServerAddress);

//versions below 1.1.0
Core.Http.Default.HttpClient apiClient = new Core.Http.Default.HttpClient(apiServer.CreateClient());
//1.1.0+
HotPotatoClient apiClient = new HotPotatoClient(apiServer.CreateClient());
```

Now that we have a client created for the API Under Test, we can build our web host and inject it into the Test Server.
Expand Down Expand Up @@ -218,7 +221,10 @@ These services are `IProxy`, `ISpecificationProivder`, `IResultCollector`, and `
We set the fixture's public members of Results to the List<Result> member of the IResultCollector and Client to the client created with the Hot Potato TestServer:
```csharp
Results = hotPotatoServer.Host.Services.GetService<IResultCollector>().Results;
//versions below 1.1.0
Client = new Core.Http.Default.HttpClient(hotPotatoServer.CreateClient());
//1.1.0+
Client = new HotPotatoClient(hotPotatoServer.CreateClient());
```

Then we use them like so in a test to send requests and verify the validation results:
Expand All @@ -230,6 +236,8 @@ Result result = results.ElementAt(0);
Assert.Equal(State.Pass, result.State);
```

Make sure to call `results.Clear()` in a `Dispose()` method in XUnit or a `[Teardown]` method in NUnit. Another option is to call `results.Clear` in the `finally` block of a try-finally statement containing the test fixture.

The full example test can be found at [RawPotatoTest.cs](https://bitbucket.hyland.com/projects/TATO/repos/hot-potato/browse/test/HotPotato.TestServer.Test/RawPotatoTest.cs).

#### Using Middleware/TestServer with Startups in separate test projects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.2;netcoreapp3.1</TargetFrameworks>
<RestoreSources>
<!-- <RestoreSources>
https://proget.onbase.net/nuget/NuGet/;
</RestoreSources>
</RestoreSources> -->
<PackAsTool>true</PackAsTool>
<ToolCommandName>HotPotato</ToolCommandName>
<PackageVersion></PackageVersion>
Expand Down
5 changes: 3 additions & 2 deletions src/HotPotato.AspNetCore.Host/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using HotPotato.Core;
using HotPotato.Core.Cookies;
using HotPotato.Core.Http;
using HotPotato.Core.Http.Default;
using HotPotato.Core.Http.ForwardProxy;
using HotPotato.Core.Processor;
using HotPotato.Core.Proxy;
Expand Down Expand Up @@ -45,12 +46,12 @@ public void ConfigureServices(IServiceCollection services)
LogTlsValidationSetting(ignoreClientCertificateValidationErrors);

services.AddScoped<IProxy, HotPotato.Core.Proxy.Default.Proxy>();
services.AddScoped<IHttpClient, HotPotato.Core.Http.Default.HttpClient>();
services.AddScoped<IHotPotatoClient, HotPotatoClient>();
services.AddMvcCore().AddJsonFormatters();
services.AddSingleton<IWebProxy, Core.Http.ForwardProxy.Default.HttpForwardProxy>();
services.AddSingleton(Configuration.GetSection("ForwardProxy").Get<HttpForwardProxyConfig>());
services.AddSingleton<ICookieJar, CookieJar>();
services.AddHttpClient<IHttpClient, HotPotato.Core.Http.Default.HttpClient>()
services.AddHttpClient<IHotPotatoClient, HotPotatoClient>()
.ConfigurePrimaryHttpMessageHandler(sp => new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
Expand Down
9 changes: 5 additions & 4 deletions src/HotPotato.AspNetCore.Middleware/HostExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HotPotato.Core.Cookies;
using HotPotato.Core.Http;
using HotPotato.Core.Http.Default;
using HotPotato.Core.Processor;
using HotPotato.Core.Proxy;
using HotPotato.OpenApi.Results;
Expand All @@ -16,17 +17,17 @@ public static class HostExtensions
/// </summary>
/// <param name="services">The client from the external host to be injected into the service collection</param>
/// <returns></returns>
public static IServiceCollection ConfigureMiddlewareServices(this IServiceCollection services, Core.Http.Default.HttpClient client = null)
public static IServiceCollection ConfigureMiddlewareServices(this IServiceCollection services, HotPotatoClient client = null)
{
services.AddScoped<IProxy, HotPotato.Core.Proxy.Default.Proxy>();
if (client != null)
{
services.AddSingleton<IHttpClient>(client);
services.AddSingleton<IHotPotatoClient>(client);
}
else
{
services.AddScoped<IHttpClient, HotPotato.Core.Http.Default.HttpClient>();
services.AddHttpClient<IHttpClient, HotPotato.Core.Http.Default.HttpClient>();
services.AddScoped<IHotPotatoClient, HotPotatoClient>();
services.AddHttpClient<IHotPotatoClient, HotPotatoClient>();
}
services.AddSingleton<ICookieJar, CookieJar>();
services.AddSingleton<ISpecificationProvider, SpecificationProvider>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>netcoreapp2.2;netcoreapp3.1</TargetFrameworks>
<RestoreSources>
<!-- <RestoreSources>
https://proget.onbase.net/nuget/NuGet/;
</RestoreSources>
</RestoreSources> -->
<ApplicationIcon />
<StartupObject />
<PackageVersion></PackageVersion>
Expand Down
4 changes: 2 additions & 2 deletions src/HotPotato.Core/HotPotato.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<TargetFrameworks>netcoreapp2.2;netcoreapp3.1</TargetFrameworks>
<RestoreSources>
<!-- <RestoreSources>
https://proget.onbase.net/nuget/NuGet/;
</RestoreSources>
</RestoreSources> -->
<PackageVersion></PackageVersion>
<Title>HotPotato.Core</Title>
<Authors>Test Automation Team | [email protected]</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

namespace HotPotato.Core.Http.Default
{
public class HttpClient : IHttpClient
public class HotPotatoClient : IHotPotatoClient
{
private readonly System.Net.Http.HttpClient client;

public HttpClient(System.Net.Http.HttpClient client)
public HotPotatoClient(System.Net.Http.HttpClient client)
{
_ = client ?? throw Exceptions.ArgumentNull(nameof(client));
this.client = client;
}

public async Task<IHttpResponse> SendAsync(IHttpRequest request)
public async Task<IHotPotatoResponse> SendAsync(IHotPotatoRequest request)
{
using (HttpResponseMessage response = await client.SendAsync(request.ToClientRequestMessage()))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace HotPotato.Core.Http.Default
{
public class HttpRequest : IHttpRequest, IDisposable
public class HotPotatoRequest : IHotPotatoRequest, IDisposable
{
private readonly Encoding DefaultEncoding = Encoding.UTF8;
private readonly string DefaultMediaType = "application/json";
Expand All @@ -25,7 +25,7 @@ public class HttpRequest : IHttpRequest, IDisposable
public MediaTypeHeaderValue ContentType { get; private set; }
public HttpContent Content => this.requestContent.Content;

public HttpRequest(Uri uri)
public HotPotatoRequest(Uri uri)
: this(HttpMethod.Get, uri)
{
this.Uri = uri;
Expand All @@ -39,7 +39,7 @@ public HttpRequest(Uri uri)
}
}

public HttpRequest(HttpMethod method, Uri uri)
public HotPotatoRequest(HttpMethod method, Uri uri)
{
this.Method = method;
this.Uri = uri;
Expand All @@ -56,28 +56,28 @@ public HttpRequest(HttpMethod method, Uri uri)
this.requestContent = new HttpRequestMessage();
}

public IHttpRequest SetContent(string content)
public IHotPotatoRequest SetContent(string content)
{
return SetContent(content, DefaultEncoding);
}

public IHttpRequest SetContent(string content, Encoding encoding)
public IHotPotatoRequest SetContent(string content, Encoding encoding)
{
return SetContent(content, encoding, DefaultMediaType);
}

public IHttpRequest SetContent(string content, Encoding encoding, string mediaType)
public IHotPotatoRequest SetContent(string content, Encoding encoding, string mediaType)
{
return SetContent(content, encoding, new MediaTypeHeaderValue(mediaType));
}

public IHttpRequest SetContent(string content, Encoding encoding, MediaTypeHeaderValue mediaType)
public IHotPotatoRequest SetContent(string content, Encoding encoding, MediaTypeHeaderValue mediaType)
{
this.requestContent.Content = new StringContent(content, encoding, mediaType.MediaType);
return this;
}

public IHttpRequest SetContent(byte[] content, string mediaType)
public IHotPotatoRequest SetContent(byte[] content, string mediaType)
{
this.requestContent.Content = new ByteArrayContent(content);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace HotPotato.Core.Http.Default
{
public class HttpResponse : IHttpResponse
public class HotPotatoResponse : IHotPotatoResponse
{
public HttpResponse(HttpStatusCode statusCode, HttpHeaders headers)
public HotPotatoResponse(HttpStatusCode statusCode, HttpHeaders headers)
{
this.StatusCode = statusCode;
this.Headers = headers;
}
public HttpResponse(HttpStatusCode statusCode, HttpHeaders headers, byte[] content, MediaTypeHeaderValue contentType)
public HotPotatoResponse(HttpStatusCode statusCode, HttpHeaders headers, byte[] content, MediaTypeHeaderValue contentType)
: this(statusCode, headers)
{
this.Content = content;
Expand Down
Loading

0 comments on commit 04917e8

Please sign in to comment.