GodelTech.XUnit.Auth
8.1.0
dotnet add package GodelTech.XUnit.Auth --version 8.1.0
NuGet\Install-Package GodelTech.XUnit.Auth -Version 8.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GodelTech.XUnit.Auth" Version="8.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GodelTech.XUnit.Auth --version 8.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: GodelTech.XUnit.Auth, 8.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GodelTech.XUnit.Auth as a Cake Addin #addin nuget:?package=GodelTech.XUnit.Auth&version=8.1.0 // Install GodelTech.XUnit.Auth as a Cake Tool #tool nuget:?package=GodelTech.XUnit.Auth&version=8.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
GodelTech.XUnit.Auth
Overview
GodelTech.XUnit.Auth
contains helpers to assert routes in project.
Example of usage Test JSON Web Token
AppTestFixture.cs
public class AppTestFixture : WebApplicationFactory<Startup>
{
protected override void ConfigureWebHost([NotNull] IWebHostBuilder builder)
{
builder
.UseSetting("https_port", "8080")
.ConfigureTestJwtToken(); // Configures Test JSON Web Token
}
}
ControllerTests.cs
public sealed class FakeControllerTests : IDisposable
{
private readonly AppTestFixture _fixture;
private readonly HttpClient _client;
public FakeControllerTests(ITestOutputHelper output)
{
_fixture = new AppTestFixture
{
Output = output
};
_client = _fixture.CreateClient(
new WebApplicationFactoryClientOptions
{
BaseAddress = new Uri("https://localhost:8080")
}
);
}
public void Dispose()
{
_client.Dispose();
_fixture.Dispose();
}
[Fact]
public async Task GetListAsync_ReturnsOkWithList()
{
// Arrange
var expectedResult = FakeController.Items;
// Act
var result = await _client
.WithJwtBearerToken() // Adds Test JSON Web Token to HttpClient
.GetAsync(new Uri("/fakes", UriKind.Relative));
// Assert
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
var resultValue = await result.Content.ReadFromJsonAsync<IList<FakeModel>>();
Assert.NotNull(resultValue);
Assert.Equal(2, resultValue.Count);
resultValue.Should().BeEquivalentTo(expectedResult);
}
}
You can check example of usage in Integration Tests for this library here: https://github.com/GodelTech/GodelTech.XUnit.Auth/tree/main/test/GodelTech.XUnit.Auth.IntegrationTests.
Exmaple of usage RouteTests
public sealed class RouteTests : IDisposable
{
private readonly AppTestFixture _fixture;
private readonly HttpClient _client;
public RouteTests(ITestOutputHelper output)
{
_fixture = new AppTestFixture
{
Output = output
};
_client = _fixture.CreateClient(
new WebApplicationFactoryClientOptions
{
BaseAddress = new Uri("https://localhost:8080"),
AllowAutoRedirect = false
}
);
}
public void Dispose()
{
_client.Dispose();
_fixture.Dispose();
}
private static readonly IList<Routes.RouteBase> Routes = new List<Routes.RouteBase>
{
// fakes
new AuthorizedRoute("/fakes", HttpMethod.Get),
new AuthorizedRoute(
"/fakes/{id}",
HttpMethod.Get,
new RouteValueDictionary
{
{ "id", 1 }
}
),
new AuthorizedRoute("/fakes", HttpMethod.Post),
new AuthorizedRoute(
"/fakes/{id}",
HttpMethod.Put,
new RouteValueDictionary
{
{ "id", 1 }
}
),
new AuthorizedRoute(
"/fakes/{id}",
HttpMethod.Delete,
new RouteValueDictionary
{
{ "id", 1 }
}
),
// openFakes
new AllowAnonymousRoute(
"/openFakes",
HttpMethod.Get
)
};
public static IEnumerable<object[]> CheckRoutesMemberData => Routes
.Select(
route => new object[]
{
route
}
);
[Theory]
[MemberData(nameof(CheckRoutesMemberData))]
public async Task CheckRoutes(Routes.RouteBase route)
{
// Arrange & Act & Assert
await AssertRoute.CheckAsync(
route,
_fixture.GetEndpoints(),
_fixture.GeTemplateBinderFactory(),
_client
);
}
[Fact]
public void CheckEndpoints()
{
// Arrange & Act & Assert
AssertEndpoint.Check(
_fixture.GetEndpoints(),
Routes
);
}
}
You can check example of usage in Integration Tests for this library here: https://github.com/GodelTech/GodelTech.XUnit.Auth/tree/main/test/GodelTech.XUnit.Auth.IntegrationTests.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- IdentityModel (>= 7.0.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 6.0.31)
- Microsoft.AspNetCore.Mvc.Testing (>= 6.0.31)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 7.6.2)
- System.IdentityModel.Tokens.Jwt (>= 7.6.2)
- xunit.assert (>= 2.8.1)
-
net7.0
- IdentityModel (>= 7.0.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 7.0.20)
- Microsoft.AspNetCore.Mvc.Testing (>= 7.0.20)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 7.6.2)
- System.IdentityModel.Tokens.Jwt (>= 7.6.2)
- xunit.assert (>= 2.8.1)
-
net8.0
- IdentityModel (>= 7.0.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.6)
- Microsoft.AspNetCore.Mvc.Testing (>= 8.0.6)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 7.6.2)
- System.IdentityModel.Tokens.Jwt (>= 7.6.2)
- xunit.assert (>= 2.8.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.