CommonApiTestLib 1.0.6
See the version list below for details.
dotnet add package CommonApiTestLib --version 1.0.6
NuGet\Install-Package CommonApiTestLib -Version 1.0.6
<PackageReference Include="CommonApiTestLib" Version="1.0.6" />
paket add CommonApiTestLib --version 1.0.6
#r "nuget: CommonApiTestLib, 1.0.6"
// Install CommonApiTestLib as a Cake Addin #addin nuget:?package=CommonApiTestLib&version=1.0.6 // Install CommonApiTestLib as a Cake Tool #tool nuget:?package=CommonApiTestLib&version=1.0.6
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
- Create NUnit Test project
- Search and download the lastest NuGet package
CommonApiTestLib
- Add dependencies files
test.runsettings
and envrionment config fileappsetting.{env}.json
example see below - 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.
- 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"
}
}
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.
Product | Versions 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. |
-
net7.0
- coverlet.collector (>= 3.2.0)
- Microsoft.Extensions.Configuration (>= 7.0.0)
- Microsoft.Extensions.Configuration.Json (>= 7.0.0)
- Microsoft.NET.Test.Sdk (>= 17.5.0)
- Newtonsoft.Json.Schema (>= 3.0.15)
- NUnit (>= 3.13.3)
- NUnit.Analyzers (>= 3.6.1)
- NUnit3TestAdapter (>= 4.4.2)
- RestSharp (>= 110.2.0)
- RichardSzalay.MockHttp (>= 7.0.0)
- Serilog (>= 3.0.1)
- Serilog.Sinks.Console (>= 4.1.0)
- Serilog.Sinks.Debug (>= 2.0.0)
- Serilog.Sinks.File (>= 5.0.0)
- System.Data.SqlClient (>= 4.8.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.