CommonApiTestLib 1.2.1

dotnet add package CommonApiTestLib --version 1.2.1
                    
NuGet\Install-Package CommonApiTestLib -Version 1.2.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="CommonApiTestLib" Version="1.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CommonApiTestLib" Version="1.2.1" />
                    
Directory.Packages.props
<PackageReference Include="CommonApiTestLib" />
                    
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 CommonApiTestLib --version 1.2.1
                    
#r "nuget: CommonApiTestLib, 1.2.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 CommonApiTestLib@1.2.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=CommonApiTestLib&version=1.2.1
                    
Install as a Cake Addin
#tool nuget:?package=CommonApiTestLib&version=1.2.1
                    
Install as a Cake Tool

API Test Standard Library

This package helps set up API test standards for your project. It provides a structured approach to API testing, ensuring consistency and reliability across your project.

Features

  1. Handle HTTP Request Methods using RestSharp
  2. Auto-structure Endpoint API Headers, Authentication, and Base URL
  3. Smart logging for easy debugging and tracking of API requests and responses
  4. Good support for data-driven testing:
    • Helpers to generate data
    • Helpers to fetch data from the database
  5. Support for multiple environments (e.g., development, staging, production)
  6. Deserialization of responses to strongly typed objects
  7. Async/Await modernization
  8. Auto pick up different environment when running on CI/CD pipeline

Example Usage

Set up Endpoint

Inherit the class EndpointCommon by passing HTTP Method, Resource, and JSON Schema file:

public class AuthEndpoint : EndpointCommon
{
    private const Method method = Method.Post;
    private const string resource = "/auth";
    // private const string schema = "GetAuth.json";
    protected override string Schema { get; set; } = "GetAuth.json";

    public AuthEndpoint() : base(method, resource)
    {
    }

    public void SetRequest(object? requestBody)
    {
        // add headers, auth token, query parameters

        // add json
        if (requestBody != null) AddJsonBody(requestBody);
    }
}

Make API Call in a Safer Way

Smart logging and error handling make it easy to debug: endpoint.SetRequest(jsonBody);

Standard Output
[09:57:15 INF] adding header: Content-Type
[09:57:15 INF]  - adding json: "{ username = admin, password = password123 }" to Request
[09:57:15 INF]  - setting up RestClient to https://restful-booker.herokuapp.com
[09:57:16 INF]  - response is OK {"token":"1060da51499abd5"}```
[09:57:16 INF] Validating response schema: format, required fields, type etc

Deserialize Response to Strongly Typed Object

//Also uses Async/Await for better performance:
var responseBody = await endpoint.ExecuteAsync<Token>();
Assert.That(responseBody.Data.token, Is.EqualTo("8d39ee85d901265"));

Auto Pick Up Different Environment Configuration

Set up in test.runsettings file:


<EnvironmentVariables>
    
    <EnvironmentName>qa</EnvironmentName>
</EnvironmentVariables>
And in `appsettings.{EnvironmentName}.json`:
{
  "booking": {
    "BaseUrl": "https://restful-booker.herokuapp.com"
  },
  "todo": {
    "BaseUrl": "https://jsonplaceholder.typicode.com"
  },
  "ConnectionStrings": {
    "dsn": "qa-db-connection-url"
  }
}```
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
1.2.1 104 7/23/2025
1.2.0 97 7/13/2025
1.1.0 170 3/7/2024
1.0.6 129 3/6/2024
1.0.5 145 3/3/2024
1.0.4 140 3/2/2024
1.0.3 131 2/29/2024 1.0.3 is deprecated because it is no longer maintained.
1.0.2 120 2/29/2024
1.0.1 139 2/26/2024
1.0.0 157 2/22/2024