CommonApiTestLib 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package CommonApiTestLib --version 1.0.3                
NuGet\Install-Package CommonApiTestLib -Version 1.0.3                
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.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CommonApiTestLib --version 1.0.3                
#r "nuget: CommonApiTestLib, 1.0.3"                
#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 CommonApiTestLib as a Cake Addin
#addin nuget:?package=CommonApiTestLib&version=1.0.3

// Install CommonApiTestLib as a Cake Tool
#tool nuget:?package=CommonApiTestLib&version=1.0.3                

Steps to use NuGet package CommonApiTestLib

  1. Create NUnit Test project <br />
  2. Search and download the lastest NuGet package CommonApiTestLib<br /> Nuget Package
  3. Add dependencies files test.runsettings and envrionment config file appsetting.{env}.json example see below<br />
  4. Create endpoint by inheriting from the EndpointCommon abstract class. <br />
    • HTTP Method and Resource: It defines a constant HTTP method (Method.Post) and a resource path ("/auth") specific to the authentication endpoint.<br />
    • Constructor: The constructor initializes the AuthEndpoint instance by calling the protected constructor of the base EndpointCommon class with the specified HTTP method and resource path. This constructor ensures that the AuthEndpoint adheres to the structure defined by the abstract class.
  public class AuthEndpoint : EndpointCommon
    {
        private const Method method = Method.Post;

        private const string Resource = "/auth";
        protected override string? Schema { get; set; } = "auth.json";
        public AuthEndpoint() : base(method, Resource)
        {
        }

        public void SetRequest(object jsonBody)
        {
            AddJsonBody(jsonBody);
        }
  1. Create Tests after defining endpoint, you can use instances in your Test Class and also consume core function from NuGet Package ApiBase
[Test]
        public async Task AuthTests()
        {
            // Step 1: Define API Endpoint and Request Body
            var endpoint = new AuthEndpoint();
            var jsonBody = new
            {
                username = "admin",
                password = "password123"
            };

            // Step 2: Send Request
            endpoint.SetRequest(jsonBody);
            var responseBody = await endpoint.ExecuteAsync<Auth>();

            // Step 3 : Assertion
            Assert.That(endpoint.AssertSuccessResponse(responseBody),"Response Code is not success ");
            Assert.That(endpoint.ValidateResponseWithJsonSchema(responseBody), "Response body schema check has failed");
            Assert.That(responseBody.Data.token,Is.Not.Empty);
        }

Create a NuGet Package

Create and publish a NuGet package by using Visual Studio
  • step1: update .csproj metadata
<Project Sdk="Microsoft.NET.Sdk">
 <PropertyGroup>
   <TargetFramework>netstandard2.0</TargetFramework>
   <PackageId>MyNuGetPackage</PackageId>
   <Version>1.0.0</Version>
   <Authors>Your Name</Authors>
   <Company>Your Company</Company>
 </PropertyGroup>
</Project> 
  • step2: Select Build > Configuration Manager, and then set the Active solution configuration to Release.

  • step3: Visual Studio builds the project and creates the .nupkg file under Release folder

Generate NuGet package on build

Expand the Package node, select General, and then select Generate NuGet package on build.

dependencies or configuration requirements example

// test.runsettings

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <TestRunParameters>
      <Parameter name="someParameterName" value="someExampleValue" />
  </TestRunParameters>
	<RunConfiguration>
		<EnvironmentVariables>
			
			<EnvironmentName>qa</EnvironmentName>
		</EnvironmentVariables>
	</RunConfiguration>
</RunSettings>
//appsettings.qa.json
{
  "Api": {
    "BaseUrl": "https://restful-booker.herokuapp.com",
    "Username":"abc",
    "Password": "password"
  },
  "ConnectionStrings": {
    "DefaultConnection": "Server=YOURSERVERNAME; Database=YOURDATABASENAME; Trusted_Connection=True; MultipleActiveResultSets=true"
  }
}
Summary

By following these steps, you should be able to successfully consume the abstract class from the NuGet package in your project. Remember to handle any dependencies or configuration requirements specified by the package documentation.

Todo: Tell difference between two test methods async Task and void

  • tests are involving asynchronous operations (todo) eg: api response using async method
  • tradtionaly can use void for simplicity
Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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.

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.1.0 140 3/7/2024
1.0.6 109 3/6/2024
1.0.5 123 3/3/2024
1.0.4 114 3/2/2024
1.0.3 107 2/29/2024 1.0.3 is deprecated because it is no longer maintained.
1.0.2 97 2/29/2024
1.0.1 116 2/26/2024
1.0.0 133 2/22/2024