Skip to content

Commit 8d9d5e7

Browse files
authored
http agent setup, net 6 update
1 parent 8ec75d6 commit 8d9d5e7

File tree

10 files changed

+109
-16
lines changed

10 files changed

+109
-16
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ jobs:
2222
uses: actions/setup-dotnet@v1
2323
with:
2424
dotnet-version: '3.1.x'
25-
- name: Setup .NET Core 5.0
26-
uses: actions/setup-dotnet@v1
27-
with:
28-
dotnet-version: '5.0.x'
2925
- name: Setup .NET Core 6.0
3026
uses: actions/setup-dotnet@v1
3127
with:

.github/workflows/dotnet-core.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ jobs:
5454
uses: actions/setup-dotnet@v1
5555
with:
5656
dotnet-version: '3.1.x'
57-
- name: Setup .NET Core 5.0
57+
- name: Setup .NET Core 6.0
5858
uses: actions/setup-dotnet@v1
5959
with:
60-
dotnet-version: '5.0.x'
60+
dotnet-version: '6.0.x'
6161
- name: Pack NuGet
6262
uses: brandedoutcast/publish-nuget@v2.5.5
6363
with:

.github/workflows/sonarqube-analysis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ jobs:
1616
uses: actions/setup-dotnet@v1
1717
with:
1818
dotnet-version: '3.1.x'
19-
- name: Setup .NET Core 5.0
20-
uses: actions/setup-dotnet@v1
21-
with:
22-
dotnet-version: '5.0.x'
2319
- name: Setup .NET Core 6.0
2420
uses: actions/setup-dotnet@v1
2521
with:

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.3.5</Version>
3+
<Version>0.3.6</Version>
44
</PropertyGroup>
55
</Project>

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020-2021 Miha Jakovac
3+
Copyright (c) 2020-2022 Miha Jakovac
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/QAToolKit.Engine.HttpTester.Test/HttpTesterClientTests.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,5 +787,69 @@ public async Task HttpTesterMultipleHeadersAlreadyExist_Success()
787787
Assert.True(client.GetRequestHeaders().Count == 1);
788788
}
789789
}
790+
791+
[Fact]
792+
public async Task HttpAgentHeaders_Success()
793+
{
794+
using (var client = new HttpTesterClient())
795+
{
796+
client
797+
.CreateHttpRequest(new Uri("http://swagger-demo.qatoolkit.io/"), true)
798+
.WithQueryParams(new Dictionary<string, string>() { { "api-version", "1" } })
799+
.WithMethod(HttpMethod.Get)
800+
.WithHttpAgent("testapp", "1.0", "https://myapp.com")
801+
.WithPath("/api/bicycles/1");
802+
803+
Assert.True(client.HttpClient.DefaultRequestHeaders.Count() == 1);
804+
}
805+
}
806+
807+
[Theory]
808+
[InlineData("")]
809+
public async Task HttpAgentHeadersNameNull_Fails(string name)
810+
{
811+
using (var client = new HttpTesterClient())
812+
{
813+
client
814+
.CreateHttpRequest(new Uri("http://swagger-demo.qatoolkit.io/"), true)
815+
.WithQueryParams(new Dictionary<string, string>() { { "api-version", "1" } })
816+
.WithMethod(HttpMethod.Get)
817+
.WithPath("/api/bicycles/1");
818+
819+
Assert.Throws<ArgumentNullException>(() => client.WithHttpAgent(name, "1.0", "https://myapp.com"));
820+
}
821+
}
822+
823+
[Theory]
824+
[InlineData("")]
825+
public async Task HttpAgentHeadersVersionNull_Fails(string version)
826+
{
827+
using (var client = new HttpTesterClient())
828+
{
829+
client
830+
.CreateHttpRequest(new Uri("http://swagger-demo.qatoolkit.io/"), true)
831+
.WithQueryParams(new Dictionary<string, string>() { { "api-version", "1" } })
832+
.WithMethod(HttpMethod.Get)
833+
.WithPath("/api/bicycles/1");
834+
835+
Assert.Throws<ArgumentNullException>(() => client.WithHttpAgent("testapp", version, "https://myapp.com"));
836+
}
837+
}
838+
839+
[Theory]
840+
[InlineData("")]
841+
public async Task HttpAgentHeadersUrlNull_Fails(string url)
842+
{
843+
using (var client = new HttpTesterClient())
844+
{
845+
client
846+
.CreateHttpRequest(new Uri("http://swagger-demo.qatoolkit.io/"), true)
847+
.WithQueryParams(new Dictionary<string, string>() { { "api-version", "1" } })
848+
.WithMethod(HttpMethod.Get)
849+
.WithPath("/api/bicycles/1");
850+
851+
Assert.Throws<ArgumentNullException>(() => client.WithHttpAgent("testapp", "1.0", url));
852+
}
853+
}
790854
}
791855
}

src/QAToolKit.Engine.HttpTester.Test/QAToolKit.Engine.HttpTester.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
1717
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
1818
<PackageReference Include="ExpectedObjects" Version="3.5.4" />
19-
<PackageReference Include="QAToolKit.Source.Swagger" Version="0.3.9" />
19+
<PackageReference Include="QAToolKit.Source.Swagger" Version="0.4.0" />
2020
<PackageReference Include="xunit" Version="2.4.1" />
2121
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
2222
<PrivateAssets>all</PrivateAssets>

src/QAToolKit.Engine.HttpTester/HttpTesterClient.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,35 @@ public IHttpTesterClient WithMultipart(string httpContentName, string value)
384384
return this;
385385
}
386386

387+
/// <summary>
388+
/// Specify the HTTP client agent data. It's useful for serverside to identify your HTTP calls.
389+
/// </summary>
390+
/// <param name="productName"></param>
391+
/// <param name="productVersion"></param>
392+
/// <param name="productUrl"></param>
393+
/// <returns></returns>
394+
/// <exception cref="ArgumentNullException"></exception>
395+
/// <exception cref="QAToolKitEngineHttpTesterException"></exception>
396+
public IHttpTesterClient WithHttpAgent(string productName, string productVersion, string productUrl)
397+
{
398+
if (string.IsNullOrEmpty(productName))
399+
throw new ArgumentNullException($"{nameof(productName)} is null.");
400+
if (string.IsNullOrEmpty(productVersion))
401+
throw new ArgumentNullException($"{nameof(productVersion)} is null.");
402+
if (string.IsNullOrEmpty(productUrl))
403+
throw new ArgumentNullException($"{nameof(productUrl)} is null.");
404+
if (HttpClient == null)
405+
throw new QAToolKitEngineHttpTesterException("HttpClient is not instantiated. Create new 'HttpTesterClient'.");
406+
407+
var productValue = new ProductInfoHeaderValue(productName, productVersion);
408+
var commentValue = new ProductInfoHeaderValue($"(+{productUrl})");
409+
410+
HttpClient.DefaultRequestHeaders.UserAgent.Add(productValue);
411+
HttpClient.DefaultRequestHeaders.UserAgent.Add(commentValue);
412+
413+
return this;
414+
}
415+
387416
/// <summary>
388417
/// Start the HTTP request
389418
/// </summary>

src/QAToolKit.Engine.HttpTester/Interfaces/IHttpTesterClient.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ public interface IHttpTesterClient
109109
/// <returns></returns>
110110
IHttpTesterClient WithMultipart(string httpContentName, string value);
111111
/// <summary>
112+
/// Specify the HTTP client agent data. It's useful for serverside to identify your HTTP calls.
113+
/// </summary>
114+
/// <param name="productName"></param>
115+
/// <param name="productVersion"></param>
116+
/// <param name="productUrl"></param>
117+
/// <returns></returns>
118+
IHttpTesterClient WithHttpAgent(string productName, string productVersion, string productUrl);
119+
/// <summary>
112120
/// Start the HTTP request
113121
/// </summary>
114122
/// <returns></returns>

src/QAToolKit.Engine.HttpTester/QAToolKit.Engine.HttpTester.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0</TargetFrameworks>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
<LangVersion>latest</LangVersion>
77
<ProjectGuid>23f0cf6e-9a0a-4be5-8f51-51daf799a0bf</ProjectGuid>
@@ -19,7 +19,7 @@
1919
<PackageProjectUrl>https://github.com/qatoolkit/qatoolkit-engine-httptester-net</PackageProjectUrl>
2020
<PackageIcon>qatoolkit-64x64.png</PackageIcon>
2121
<RepositoryUrl>https://github.com/qatoolkit/qatoolkit-core-net</RepositoryUrl>
22-
<PackageTags>qatoolkit-engine-httptester-net;.net;c#;f#;dotnet;netstandard;net5</PackageTags>
22+
<PackageTags>qatoolkit-engine-httptester-net;.net;c#;f#;dotnet;netstandard;net6</PackageTags>
2323
<Configurations>Debug;Release</Configurations>
2424
</PropertyGroup>
2525

@@ -35,6 +35,6 @@
3535

3636
<ItemGroup>
3737
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
38-
<PackageReference Include="QAToolKit.Core" Version="0.3.9" />
38+
<PackageReference Include="QAToolKit.Core" Version="0.3.13" />
3939
</ItemGroup>
4040
</Project>

0 commit comments

Comments
 (0)