CommonApiTestLib 1.1.0

dotnet add package CommonApiTestLib --version 1.1.0                
NuGet\Install-Package CommonApiTestLib -Version 1.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="CommonApiTestLib" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CommonApiTestLib --version 1.1.0                
#r "nuget: CommonApiTestLib, 1.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 CommonApiTestLib as a Cake Addin
#addin nuget:?package=CommonApiTestLib&version=1.1.0

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

Getting started

Follow these steps to successfully integrate the abstract class into your project.

Installation

Here, you'll find instructions for installing the NuGet package and handling any dependencies or configuration requirements.

Steps

  1. Create NUnit Test project
  2. Search and download the lastest NuGet package CommonApiTestLib NugetPackage
  3. Add dependencies files test.runsettings and envrionment config file appsetting.{env}.json example see below
  4. Create an endpoint file by inheriting from the EndpointCommon abstract class.
    • HTTP Method and Resource: It defines a constant HTTP method (Method.Post) and a resource path ("/auth") specific to the authentication endpoint.
    • 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.
  5. Create tests to consume core functions from the NuGet package.

Code Example

  public class AuthEndpoint : EndpointCommon
    {
        private const Method method = Method.Post;

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

        public void SetRequest(object jsonBody)
        {
            AddJsonBody(jsonBody);
        }
[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);
        }
// 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"
  }
}

ApiBase

Instructions

Learn how to:

  • Create and publish a NuGet package using Visual Studio.
  • Generate a NuGet package on build.
  • Set up dependencies and configuration requirements.

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

Feedback

Your feedback is very important to me. If you experience any issue using this package or have ideas for improvements, please feel free to contact me.

  • ✉️ chloezeng310@gmail.com
  • LinkedIn
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