-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create get request when it has an object with some list * DateTime as a primitive type but using custom formatter (#81) * Fixing codeQL alerts (#82) * feature: Get url (#83) * In IncludeContentAsFormUrlEncoded and PrimitiveParameterActionTokenizer explicit conversion for floats (#84) Create random ParamWithSeveralTypes More tests * Add new CreateHttpApiRequest with TActionResponse (#85) Fix CodeQL alerts Test * Add net7.0 Target Version (#86) * Add net7.0 Target Version Update nugets * add net 7 in workflows * update global.json * remove extra builds ci.yml * ReadContentAsAsync allows string type (#87) Tests for HttpResponseMessageExtensions * Allow send a IFormFile (#88) * Allow IFormFile Refactor IncludeContentAsFormUrlEncoded Remove Newtonsoft.Json dependecy * Update documentation * Refactor GivenFile * Update version to 3.5.0 (#89) * Add DateTimeOffset to IsDateTime function (#91) Move TypeExtensions
- Loading branch information
1 parent
b000e95
commit fde4f8e
Showing
38 changed files
with
2,949 additions
and
2,402 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ jobs: | |
3.1.417 | ||
5.0.101 | ||
6.0.300 | ||
7.0.302 | ||
- name: Build | ||
run: dotnet build -c $BUILD_CONFIG | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,32 @@ | ||
<Project> | ||
<PropertyGroup Label=".Net version" Condition=" '$(TargetFramework)' == 'netcoreapp3.1' "> | ||
<NetCoreVersion>3.1.25</NetCoreVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Label=".Net version" Condition=" '$(TargetFramework)' == 'net5.0' "> | ||
<NetCoreVersion>5.0.17</NetCoreVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Label=".Net version" Condition=" '$(TargetFramework)' == 'net6.0' "> | ||
<NetCoreVersion>6.0.5</NetCoreVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Label="General Dependencies"> | ||
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="$(NetCoreVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Label="Sample Dependencies"> | ||
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(NetCoreVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Label="Testing Dependencies"> | ||
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(NetCoreVersion)" /> | ||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.2.0" /> | ||
<PackageVersion Include="FluentAssertions" Version="6.7.0" /> | ||
<PackageVersion Include="xunit" Version="2.4.1" /> | ||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" /> | ||
<PackageVersion Include="coverlet.collector" Version="3.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Label="Github Dependencies"> | ||
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" /> | ||
</ItemGroup> | ||
<PropertyGroup Label=".Net version" Condition=" '$(TargetFramework)' == 'netcoreapp3.1' "> | ||
<NetCoreVersion>3.1.32</NetCoreVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Label=".Net version" Condition=" '$(TargetFramework)' == 'net5.0' "> | ||
<NetCoreVersion>5.0.17</NetCoreVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Label=".Net version" Condition=" '$(TargetFramework)' == 'net6.0' "> | ||
<NetCoreVersion>6.0.16</NetCoreVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Label=".Net version" Condition=" '$(TargetFramework)' == 'net7.0' "> | ||
<NetCoreVersion>7.0.5</NetCoreVersion> | ||
</PropertyGroup> | ||
<ItemGroup Label="General Dependencies"> | ||
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" /> | ||
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="$(NetCoreVersion)" /> | ||
</ItemGroup> | ||
<ItemGroup Label="Sample Dependencies"> | ||
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(NetCoreVersion)" /> | ||
</ItemGroup> | ||
<ItemGroup Label="Testing Dependencies"> | ||
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(NetCoreVersion)" /> | ||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageVersion Include="FluentAssertions" Version="6.11.0" /> | ||
<PackageVersion Include="xunit" Version="2.4.2" /> | ||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" /> | ||
<PackageVersion Include="coverlet.collector" Version="3.2.0" /> | ||
</ItemGroup> | ||
<ItemGroup Label="Github Dependencies"> | ||
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" /> | ||
</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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"projects": [ "src", "test", "samples" ], | ||
"projects": ["src", "test", "samples"], | ||
"sdk": { | ||
"version": "6.0.300", | ||
"version": "6.0.000", | ||
"rollForward": "latestMajor" | ||
} | ||
} | ||
} |
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.
47 changes: 47 additions & 0 deletions
47
src/Acheve.TestHost/Extensions/HttpResponseMessageExtensions.cs
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,47 @@ | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace System.Net.Http; | ||
|
||
public static class HttpResponseMessageExtensions | ||
{ | ||
/// <summary> | ||
/// Try to extract the error message in the response content in case the response status code is not success. | ||
/// </summary> | ||
/// <param name="response">The HttpResponseMessage instance</param> | ||
/// <returns></returns> | ||
public static async Task IsSuccessStatusCodeOrThrow(this HttpResponseMessage response) | ||
{ | ||
if (response.IsSuccessStatusCode) | ||
{ | ||
return; | ||
} | ||
|
||
var content = await response.Content.ReadAsStringAsync(); | ||
|
||
throw new Exception($"Response status does not indicate success: {response.StatusCode:D} ({response.StatusCode}); \r\n{content}"); | ||
} | ||
|
||
/// <summary> | ||
/// Read HttpResponseMessage and convert to T Class | ||
/// </summary> | ||
/// <typeparam name="T">Class type or primitive type</typeparam> | ||
/// <param name="responseMessage">The HttpResponseMessage instance</param> | ||
/// <returns>T class object</returns> | ||
public static async Task<T> ReadContentAsAsync<T>(this HttpResponseMessage responseMessage) | ||
{ | ||
var content = await responseMessage.Content.ReadAsStringAsync(); | ||
|
||
if (typeof(T) == typeof(string)) | ||
{ | ||
content = $"\"{content}\""; | ||
} | ||
|
||
var json = JsonSerializer.Deserialize<T>(content, new JsonSerializerOptions() | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}); | ||
|
||
return json; | ||
} | ||
} |
Oops, something went wrong.