Skip to content

Commit

Permalink
develop into master (#69)
Browse files Browse the repository at this point in the history
* Include Request with FromHeaderAttribute #32

* * added logic of apicontroller where the [frombody] attribute does not need to be added and fixed bug when i send a object with properties a null in the body

* * Update support for method patch

* Fix null reference exception when pass null properties in request model

* Simplify way of parameter extract

* Create a new model in Sample.Api to use it as a parameter
Two new endpoints with parameters (custom or primitive object)
Tests calling endpoints with a null parameter (custom or primitive object)
We check if the instance is null before AddTokken in PrimitiveParameterActionTokenizer and ComplexParameterActionTokenizer
We add null argument in TestServerAction instead of a null reference exception

* Bump Microsoft.AspNetCore.Authentication.JwtBearer

Bumps [Microsoft.AspNetCore.Authentication.JwtBearer](https://github.com/aspnet/AspNetCore) from 3.0.0 to 3.1.18.
- [Release notes](https://github.com/aspnet/AspNetCore/releases)
- [Commits](dotnet/aspnetcore@v3.0.0...v3.1.18)

---
updated-dependencies:
- dependency-name: Microsoft.AspNetCore.Authentication.JwtBearer
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update TestServerExtensionsTests.cs

fix test name

* Revert updated Microsoft.AspNetCore.Authentication.JwtBearer

* ?. removed in last merge

* * added tests

* Include dependencies.props in "Solution Items" folder
Update nugets and sdk version

* 42 use GitHub actions instead of appveyor (#45)

* Add github workflows

* remove appveyor files

Co-authored-by: Sergio <sergio.merino@plainconcepts.com>

* Move "Package information" from "build/dependencies.props" to "Directory.Build.props"
Add Source Link to Github
Minimun version 3.1.300 to avoid issue "dotnet/sourcelink#572"

* Feature/router paramas with underscores (#51)

* allow router params with _ and -

* Test for allow router params with _

Co-authored-by: Alexis Martin Peña <alexis.martin@barrabes.biz>

* Fix TestServerAction for methods parameters (#43)

* Fix TestServerAction for methods parameters

* Merge With VFA91 Fork

* Add Guid[] In QueryParams

* Avoid add parameter when Guid[] is empty

* Adding Test

* using GuidArrayExtension

* Remove unused method

* fix for .net5

* Fixing comments

* Enable any array from query params

* Avoid Array with not primitives types

* fix for .net 3.1

* comments fix

* Change namespace & Clear function for primitives

* remove dynamic

* rename variables

Co-authored-by: Alexis Martin Peña <alexis.martin@barrabes.biz>
Co-authored-by: Sergio <sergio11_92@hotmail.com>

* Set targets and versions to Net Core 3.1, Net 5 and Net 6

Application version 3.2.0 (#54)
Set targets and versions to Net Core 3.1, Net 5 and Net 6
Add Directory.Build.targets with version of nugets
Modify workflows to support Net 5 and Net 6
Clean ".csproj"s

* Feature/update to net6 (#55)

Change PackageLicenseUrl to PackageLicenseUrl
Remove SetCompatibilityVersion from the code
Update README

* Feature/nullable query params (#53)

* Add Test For try fix a Bug

* Allo Query Parameter Nullable

* allow .net 3.1 build

* add folder again

* fix indent

* fix indent

* indent

* indent

* fix merge

* Change class name and access

* Pr Comments

* better comment method

* comment

* improve performance

Co-authored-by: Alexis Martin Peña <alexis.martin@barrabes.biz>

* Tests using WebApplicationFactory (#58)

Documentation about GetStarted, WebApplicationFactory and ICollectionFixture (xunit)
Refactor ValuesTests and ValuesWithHttpClientTests to test also WebApplicationFactory

Co-authored-by: Sergio <sergio.merino@plainconcepts.com>

* Allow router params in post methods (#60)

Co-authored-by: Alexis Martin Peña <alexis.martin@barrabes.biz>

* regex_pattern include several colon (#61)

Co-authored-by: Sergio <sergio.merino@plainconcepts.com>

* Bug filtro isPrimitive y rutas con parametros strings (#64)

* * bug en el filtro isPrimitive

* * revert cambio para pasarlo a una rama

* * Corrección Bug en el filtro isPrimitive

* * Corrección bug isPrimitive
* Corrección bug endpoint con parametro string en la ruta

Co-authored-by: David Jiménez Hernández <david.jimenez@ezentis.com>

* AddQueryParameter extension in RequestBuilder (#65)

* feat(RequestBuilder): AddQueryParameter extension in RequestBuilder and their tests

* EscapeDataString the name and value

* Remove repeated tests

* Version 3.3.0 (#66)

* Add new sections in the doc: "About adding extra query parameters" and "Improving assertions in API responses" (#68)

* Change to central package management (#67)

* Change Directory.Build.targets to Directory.Packages.props
Minimun sdk version 6.0.300

* REmove PrivateAssets and IncludeAssets from Directory.Packages.props

* Update workflows

* Remove build\dependencies.props
Remove version in Microsoft.SourceLink.GitHub
Remove dependencies.props and move the content to Directory.Build.props and Directory.Packages.props
Add removed Microsoft.AspNetCore.Mvc.Testing nuget package to Sample.IntegrationTests.csproj

* PrivateAssets and IncludeAssets to xunit.runner.visualstudio

* tabs to spaces
Add PrivateAssets and IncludeAssets to coverlet.collector

* Update packages

* Refactor Directory.Packages.props to only repeat NetCoreVersion each .Net version

Co-authored-by: Vicente Fernández Antolín <fernandez.antolin.vicente@gmail.com>
Co-authored-by: David Jiménez <david.jimenez@altia.es>
Co-authored-by: Carlos Jiménez Delgado <mail@carlosjdelgado.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Jiménez Hernández <david.jimenez@ezentis.com>
Co-authored-by: serweck <serweck@gmail.com>
Co-authored-by: Alexis Martin Peña <alexis.martin@barrabes.biz>
Co-authored-by: David Jiménez Hernández <dadjh85@gmail.com>
  • Loading branch information
9 people committed Jun 7, 2022
1 parent 7216f60 commit 29fd1ca
Show file tree
Hide file tree
Showing 17 changed files with 375 additions and 187 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,22 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET SDK 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.200
- name: Setup .NET SDK 5.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.101
- name: Setup .NET Core SDK 3.1
uses: actions/setup-dotnet@v1
- uses: actions/checkout@v3

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
with:
dotnet-version: 3.1.417
dotnet-version: |
3.1.417
5.0.101
6.0.300
- name: Build .NET 3.1
run: dotnet build -c $BUILD_CONFIG --framework netcoreapp3.1
- name: Build .NET 5.0
run: dotnet build -c $BUILD_CONFIG --framework net5.0
- name: Build .NET 6.0
run: dotnet build -c $BUILD_CONFIG --framework net6.0

- name: Test
run: dotnet test -c $BUILD_CONFIG --no-build
30 changes: 13 additions & 17 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,24 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET SDK 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.200
- name: Setup .NET SDK 5.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.101
- name: Setup .NET Core SDK 3.1
uses: actions/setup-dotnet@v1
- uses: actions/checkout@v3

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
with:
dotnet-version: 3.1.417
dotnet-version: |
3.1.417
5.0.101
6.0.300
- name: Build
run: dotnet build -c $BUILD_CONFIG

- name: Test
run: dotnet test -c $BUILD_CONFIG --no-build

- name: Pack
run: dotnet pack -c $BUILD_CONFIG --no-build --include-source --include-symbols -o ./artifacts
- name: Nuget setup
uses: NuGet/setup-nuget@v1.0.5
with:
nuget-version: latest
- name: Nuget push

- name: Push
run: dotnet nuget push ./artifacts/*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
3 changes: 1 addition & 2 deletions Acheve.TestHost.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acheve.TestHost", "src\Ache
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{97C5D07D-D623-497A-9DA5-2B3376A4F0DC}"
ProjectSection(SolutionItems) = preProject
build\dependencies.props = build\dependencies.props
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
Directory.Packages.props = Directory.Packages.props
global.json = global.json
EndProjectSection
EndProject
Expand Down
58 changes: 32 additions & 26 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
<Project>
<Import Project="build/dependencies.props" />
<PropertyGroup Label="SDK Versions">
<NetCoreTargetVersion>netcoreapp3.1;net5.0;net6.0</NetCoreTargetVersion>
<LangVersion>latest</LangVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<PropertyGroup Label="Package information">
<Version>3.2.0</Version>
<PropertyGroup Label="Package information">
<Version>3.3.0</Version>

<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>http://github.com/xabaril/Acheve.TestHost</PackageProjectUrl>
<RepositoryUrl>http://github.com/xabaril/Acheve.TestHost</RepositoryUrl>
<Authors>Xabaril Contributors</Authors>
<Company>Xabaril</Company>
<Description>Achve.TestHost is a nuget package to improve TestServer experiences.
For more information see http://github.com/Xabaril/Acheve.TestHost</Description>
<PackageTags>TestHost;TestServer</PackageTags>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>http://github.com/xabaril/Acheve.TestHost</PackageProjectUrl>
<RepositoryUrl>http://github.com/xabaril/Acheve.TestHost</RepositoryUrl>
<Authors>Xabaril Contributors</Authors>
<Company>Xabaril</Company>
<Description>
Achve.TestHost is a nuget package to improve TestServer experiences.
For more information see http://github.com/Xabaril/Acheve.TestHost
</Description>
<PackageTags>TestHost;TestServer</PackageTags>

<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<SourceRoot Include="$(MSBuildThisFileDirectory)/"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="$(MicrosoftSourceLinkGithub)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<SourceRoot Include="$(MSBuildThisFileDirectory)/"/>
<PackageReference Include="Microsoft.SourceLink.GitHub">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
40 changes: 0 additions & 40 deletions Directory.Build.targets

This file was deleted.

35 changes: 35 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<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>
</Project>
43 changes: 34 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ the claims for authenticated calls to the WebApi.
In the TestServer startup class you shoud incude the authentication service and add the .Net Core new AUthentication middleware:

```csharp

public class TestStartup
{
public void ConfigureServices(IServiceCollection services)
Expand Down Expand Up @@ -96,7 +95,6 @@ And in your tests you can use an HttpClient with default credentials or build
the request with the server RequestBuilder and the desired claims:

```csharp

public class ValuesWithDefaultUserTests : IDisposable
{
private readonly TestServer _server;
Expand Down Expand Up @@ -154,7 +152,6 @@ the request with the server RequestBuilder and the desired claims:
Both methods (`WithDefaultIdentity` and `WithIdentity`) accept as the only parameter an IEnumerabe&lt;Claim&gt; that should include the desired user claims for the request.

```csharp

public static class Identities
{
public static readonly IEnumerable<Claim> User = new[]
Expand All @@ -165,7 +162,6 @@ Both methods (`WithDefaultIdentity` and `WithIdentity`) accept as the only param

public static readonly IEnumerable<Claim> Empty = new Claim[0];
}

```

You can find a complete example in the [samples](https://github.com/hbiarge/Acheve.AspNetCore.TestHost.Security/tree/master/Acheve.AspNet.TestHost.Security/samples) directory.
Expand All @@ -175,16 +171,13 @@ You can find a complete example in the [samples](https://github.com/hbiarge/Ache
Well, when you try to create any test using Test Server you need to know the uri of the action to be invoked.

```csharp

var response = await _server.CreateRequest("api/values/public")
.GetAsync();

```

In general, in our tests a new simple API class is created to hide this uri and improve the code.

```csharp

// some code on tests
var response = await _server.CreateRequest(Api.Values.Public)
Expand All @@ -199,7 +192,6 @@ public static class API
public static string Public = "api/values/public";
}
}

```

The main problems on this approach are:
Expand All @@ -210,10 +202,43 @@ The main problems on this approach are:
With *Acheve* you can create the uri dynamically using the attribute routing directly from your controllers.

```csharp

var response = await _server.CreateHttpApiRequest<ValuesController>(controller=>controller.PublicValues())
.GetAsync();
```

## About adding extra query parameters

The package has a *RequestBuilder* extension to add a new query parameter: *AddQueryParameter*.

```csharp
[Fact]
public async Task MyFirstTest()
{
...
var request = server.CreateHttpApiRequest<MyController>(controller => controller.MyMethod(myFirstParameter))
.AddQueryParameter(nameof(mySecondParameter), mySecondParameter);
...
}
```

## Improving assertions in API responses

The package has HttpResponseMessage extension to help us assert the response.

- *IsSuccessStatusCodeOrThrow*: Throw exception with the response content in the message.
- *ReadContentAsAsync*: Read the response content and cast it.

```csharp
[Fact]
public async Task MyFirstTest()
{
...
var responseMessage = await request.GetAsync();

await responseMessage.IsSuccessStatusCodeOrThrow();
var response = await responseMessage.ReadContentAsAsync<MyResponse>();
...
}
```

## Using xunit
Expand Down
14 changes: 0 additions & 14 deletions build/dependencies.props

This file was deleted.

2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"projects": [ "src", "test", "samples" ],
"sdk": {
"version": "6.0.100",
"version": "6.0.300",
"rollForward": "latestMajor"
}
}
11 changes: 9 additions & 2 deletions samples/Sample.IntegrationTests/Sample.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="xunit.runner.visualstudio" >
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 29fd1ca

Please sign in to comment.