E13.Common.Nunit.Api
2025.106.12
See the version list below for details.
dotnet add package E13.Common.Nunit.Api --version 2025.106.12
NuGet\Install-Package E13.Common.Nunit.Api -Version 2025.106.12
<PackageReference Include="E13.Common.Nunit.Api" Version="2025.106.12" />
<PackageVersion Include="E13.Common.Nunit.Api" Version="2025.106.12" />
<PackageReference Include="E13.Common.Nunit.Api" />
paket add E13.Common.Nunit.Api --version 2025.106.12
#r "nuget: E13.Common.Nunit.Api, 2025.106.12"
#addin nuget:?package=E13.Common.Nunit.Api&version=2025.106.12
#tool nuget:?package=E13.Common.Nunit.Api&version=2025.106.12
E13.Common.Nunit.Api
Overview
E13.Common.Nunit.Api is a specialized package within the E13.Common collection designed for testing Web API projects with NUnit. It extends E13.Common.Nunit with API-specific testing utilities, including test server integration, HTTP client extensions, and authentication helpers.
Features
- API Test Fixtures: Base classes for API testing with TestServer integration
- Launch Settings Integration: Automatic loading of launchSettings.json for test configuration
- HTTP Client Extensions: Helper methods for working with HttpClient in tests
- Azure AD Authentication: Utilities for authenticating with Azure AD in tests
- Test Environment Management: Tools for managing test environments and configurations
Installation
dotnet add package E13.Common.Nunit.Api
Usage
Creating an API Test Fixture
using E13.Common.Nunit.Api;
using Microsoft.AspNetCore.Hosting;
using NUnit.Framework;
using System.Net.Http;
// Create a test fixture for your API
public class MyApiTests : BaseApiFixture
{
public MyApiTests()
: base("MyApi.Project", () => new WebHostBuilder().UseStartup<TestStartup>())
{
}
[Test]
public async Task GetEndpoint_ReturnsSuccessStatusCode()
{
// Get the configured HttpClient
var client = GetHttpClient();
// Make a request to your API
var response = await client.GetAsync("/api/values");
// Assert the response
response.EnsureSuccessStatusCode();
}
}
Using Authentication in Tests
using E13.Common.Nunit.Api;
using NUnit.Framework;
using System.Net.Http;
public class AuthenticatedApiTests
{
private HttpClient _client;
[SetUp]
public void Setup()
{
_client = new HttpClient();
}
[Test]
public async Task SecureEndpoint_WithAuthentication_ReturnsSuccessStatusCode()
{
// Authenticate with Azure AD using environment variables
_client.TokenForAAD_TestEnabled(new[] { "api://my-api/access" });
// Make a request to a secure endpoint
var response = await _client.GetAsync("https://my-api.example.com/secure");
// Assert the response
response.EnsureSuccessStatusCode();
}
}
Required Environment Variables
For Azure AD authentication tests, set these environment variables in your launchSettings.json:
{
"profiles": {
"MyTests": {
"commandName": "Project",
"environmentVariables": {
"TokenForAAD_PublicClientId": "your-client-id",
"TokenForAAD_TenantId": "your-tenant-id",
"TokenForAAD_TestUser": "test.user@example.com",
"TokenForAAD_TestPass": "your-test-password"
}
}
}
}
Dependencies
- .NET 9.0
- Microsoft.AspNetCore.TestHost
- Microsoft.Extensions.Hosting
- PuppeteerSharp (for UI testing integration)
- E13.Common.Api
- E13.Common.Nunit
Related Packages
E13.Common.Nunit.Api is part of the E13.Common collection, which includes:
- E13.Common.Core - Core utilities and base classes
- E13.Common.Nunit - Base NUnit testing utilities
- E13.Common.Nunit.UI - NUnit utilities for UI testing
- E13.Common.Api - Web API layer components
- E13.Common.AspNet - ASP.NET shared components
Contributing
Contributions to E13.Common.Nunit.Api are welcome. If you have suggestions or improvements, please submit an issue or create a pull request in the GitHub repository.
License
This project is licensed under the MIT License. For more details, see the LICENSE file in the repository.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- E13.Common.Api (>= 2025.97.11)
- E13.Common.Nunit (>= 2025.97.11)
- Microsoft.AspNetCore.Hosting.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.TestHost (>= 9.0.3)
- Microsoft.Extensions.Hosting (>= 9.0.3)
- PuppeteerSharp (>= 20.1.3)
- PuppeteerSharp.Contrib.Extensions (>= 7.0.0)
- PuppeteerSharp.Contrib.Should (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2025.117.22 | 69 | 4/27/2025 |
2025.114.21 | 138 | 4/24/2025 |
2025.114.20 | 132 | 4/24/2025 |
2025.114.18 | 139 | 4/24/2025 |
2025.112.17 | 145 | 4/22/2025 |
2025.112.16 | 141 | 4/22/2025 |
2025.111.15 | 147 | 4/21/2025 |
2025.106.14 | 159 | 4/16/2025 |
2025.106.12 | 197 | 4/16/2025 |
2025.97.11 | 145 | 4/7/2025 |
2025.96.9 | 154 | 4/6/2025 |
2025.96.8 | 150 | 4/6/2025 |
2025.91.7 | 142 | 4/1/2025 |
2025.91.6 | 137 | 4/1/2025 |
2025.90.4 | 139 | 3/31/2025 |
2023.30.1 | 336 | 1/30/2023 |
2023.18.1 | 291 | 1/18/2023 |
2021.324.4 | 1,586 | 11/20/2021 |
2021.124.2 | 610 | 5/4/2021 |
2021.84.1 | 820 | 3/25/2021 |
2021.56.3 | 681 | 2/25/2021 |
2021.42.18 | 833 | 2/11/2021 |
2021.42.17 | 843 | 2/11/2021 |
2021.40.24 | 714 | 2/9/2021 |
2021.40.22 | 859 | 2/9/2021 |
2021.40.21 | 628 | 2/9/2021 |
1.0.0 | 144 | 4/1/2025 |