Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Test APIs directly

Gustavo Denis edited this page Oct 31, 2019 · 1 revision
Main > Using Liquid for building your application > Test APIs directly

Test Web API locally using Liquid to check request and response during development.

Create a test project that uses xUnit as the test library, to run the tests. The .csproj must look like :

<ItemGroup>
  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
    <PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>

To test the API directly trought Light API connecting with the host, sending the generated token Send the json file to be read to the specific route.

/// <summary>
///  Recovery all bookings using an email account,
/// </summary>
/// <returns>List of bookings</returns>
[Theory]
//The input data to be tested
[InlineData("")]
[InlineData("www.Liquid.com")]
[InlineData("[email protected]")]
private void GetBookingsOfUser(string email)
{
//the host
 LightApi api = new LightApi("http://localhost:60948/", token: jwt);
//the .json file with mocked data
var mockdata = new MockData().GetSpecificData("MockDatabase", "Development");

//the route
var response = api.Get("api/v1/booking/" + email);

//using Xunit to test the return
Xunit.Assert.Equal(expectedResultCode, response.StatusCode);

}

Xunit will show is the tests passed or not.

Clone this wiki locally