ApiTestFramework 0.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package ApiTestFramework --version 0.1.1
                    
NuGet\Install-Package ApiTestFramework -Version 0.1.1
                    
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="ApiTestFramework" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ApiTestFramework" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="ApiTestFramework" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ApiTestFramework --version 0.1.1
                    
#r "nuget: ApiTestFramework, 0.1.1"
                    
#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.
#:package ApiTestFramework@0.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ApiTestFramework&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=ApiTestFramework&version=0.1.1
                    
Install as a Cake Tool

ApiTestFramework & GeoAPI Integration Tests

This solution provides a lightweight API test framework plus in-process integration tests for the GeoAPI endpoints.

Projects

  • ApiTestFramework (class library): HTTP client, authentication helper, data readers (CSV/JSON/DB), loggers (file + AppInsights).
  • GeoAPI.IntegrationTests (xUnit): Integration tests hosted with WebApplicationFactory<Program> so no external server startup required.

Key Features

  • Enhanced ApiClient with optional JWT auth, configurable timeout, improved error handling, case-insensitive JSON.
  • Data-driven capability (CSV/JSON/DB readers) ready for future parameterized tests.
  • File logger capturing test run details (integration-tests.log).
  • In-memory hosting of GeoAPI for fast, isolated tests.

Running Tests

From repository root:

# Restore & run tests
dotnet test .\ApiTestFramework\GeoAPI.IntegrationTests\GeoAPI.IntegrationTests.csproj -c Debug

Configuration

testsettings.json in the test project controls base URL & timeout. With in-memory hosting the baseUrl is largely informational, but can be repurposed for external environment runs.

Adding New Endpoint Tests

  1. Create a new *.cs file in GeoAPI.IntegrationTests.
  2. Inject ApiTestFixture via IClassFixture<ApiTestFixture>.
  3. Use _fx.Client.GetAsync<T>("Endpoint") etc.
  4. Log with _fx.Logger.LogInfo(...).

Error Handling

Non-success HTTP responses throw HttpRequestException including status code & body. Assert 404 scenarios with try/catch blocks.

Next Steps

  • Add data-driven Theory tests sourcing from CSV using CsvDataReader<T>.
  • Integrate AppInsights logger once instrumentation key/config is available.
  • Extend ApiClient for PATCH support if needed.

NuGet Packaging

You can create a NuGet package of the framework for reuse across multiple API projects:

dotnet pack .\ApiTestFramework\ApiTestFramework.csproj -c Release -o .\nupkg

Key metadata (PackageId, Description, SourceLink, symbols) is already configured in ApiTestFramework.csproj. Publish by pushing the .nupkg & .snupkg to an internal feed (e.g., Azure Artifacts, GitHub Packages, NuGet.org):

dotnet nuget push .\nupkg\ApiTestFramework.*.nupkg --source "YourFeedUrl" --api-key "YOUR_KEY"

Consuming the Package

In a test project:

dotnet add package ApiTestFramework --version 0.1.0

Then instantiate an ApiClient (example):

var client = new ApiClient(baseUrl: "https://localhost", token: jwtToken);
var about = await client.GetAsync<About>("About");

Allure Reporting Integration

To enable rich test reports with Allure in your (external) test project:

  1. Add packages:
      <PackageReference Include="xunit" Version="2.6.2" />
      <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
      <PackageReference Include="Allure.Xunit" Version="3.0.0.10" />
      <PackageReference Include="Allure.Commons" Version="3.0.0.10" />
    
  2. Implement an Allure reporter in your test project (keep Allure dependencies out of the core package for lean installs). Create a class that wraps AllureLifecycle for steps/attachments.
  3. Annotate tests:
      using Allure.Xunit;
    
      [AllureSuite("About")]
      [AllureFeature("Metadata")]
      public class AboutTests : IClassFixture<ApiTestFixture> { /* ... */ }
    
  4. Run tests producing Allure results:
      $env:ALLURE_CONFIG="allureConfig.json"  # if you have a config file
      dotnet test .\GeoAPI.IntegrationTests\GeoAPI.IntegrationTests.csproj --logger "trx" --results-directory .\allure-results
    
  5. Generate report (after installing Allure CLI):
      allure generate .\allure-results --clean -o .\allure-report
      allure open .\allure-report
    

Minimal config file (allureConfig.json):

{
	"allure": { "directory": "allure-results" }
}

Sample Custom Allure Reporter (in test project)

public class AllureReporter
{
	private readonly AllureLifecycle _l = AllureLifecycle.Instance;
	public void Step(string name, Action action)
	{
		var uuid = Guid.NewGuid().ToString();
		_l.StartStep(uuid, new Allure.Commons.Model.StepResult { name = name });
		try { action(); _l.UpdateStep(uuid, s => s.status = Allure.Commons.Model.Status.passed); }
		catch { _l.UpdateStep(uuid, s => s.status = Allure.Commons.Model.Status.failed); throw; }
		finally { _l.StopStep(uuid); }
	}
	public void Attach(string name, string text)
	{
		var file = Path.GetTempFileName(); File.WriteAllText(file, text);
		_l.AddAttachment(name, "text/plain", file);
	}
}

Attachments Strategy

  • Use AttachText for small JSON payloads (< ~64KB).
  • For larger bodies, write to temp file then call reporter.AttachText("LargeResponse", path) (overload you can add).

CI Example (GitHub Actions Snippet)

jobs:
	test:
		runs-on: ubuntu-latest
		steps:
			- uses: actions/checkout@v4
			- uses: actions/setup-dotnet@v4
				with:
					dotnet-version: '8.0.x'
			- name: Restore
				run: dotnet restore ApiTestFramework/ApiTestFramework.csproj
			- name: Build
				run: dotnet build ApiTestFramework/ApiTestFramework.csproj -c Release --no-restore
			- name: Test (Allure)
				run: dotnet test GeoAPI.IntegrationTests/GeoAPI.IntegrationTests.csproj -c Release --results-directory allure-results --logger "trx"
			- name: Publish Allure Report
				uses: simple-elf/allure-report-action@v1
				with:
					allure_results: allure-results
					report_name: GeoAPI Test Report

Roadmap Suggestions

  • Add richer Allure step modeling (use lifecycle Start/Stop for granular timing).
  • Provide IApiClient retry & circuit-breaker via Polly.
  • Token caching in JwtAuthenticator with expiry tracking.
  • Data-driven Theory examples pulling from CsvDataReader and JsonDataReader.
  • Switch deprecated System.Data.SqlClient to Microsoft.Data.SqlClient.

Generating Documentation

XML docs are enabled; after packing you can host generated API docs or use DocFX.

License

MIT (placeholder – adjust as needed).

Troubleshooting

  • If tests fail due to missing models, ensure project references are intact.
  • For debugging responses, temporarily log raw JSON by adding a decorator around HandleResponse<T>.
Product Compatible and additional computed target framework versions.
.NET 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.  net9.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.1.3 498 11/19/2025
0.1.2 377 11/18/2025
0.1.1 207 11/14/2025