This guide helps you set up Markop Test in a new or existing solution.
- .NET SDK 8.0 or newer
- An ASP.NET application project to test
- xUnit test infrastructure
dotnet new classlib -n IntegrationTest
dotnet sln add IntegrationTestYou can also start with dotnet new xunit -n IntegrationTest if you prefer an xUnit template.
From the test project directory:
dotnet add reference ../src/WebAPI/WebAPI.csprojUse the correct project path for your solution.
dotnet add package MarkopTestChoose a factory based on the test type. Example for integration tests:
using System;
using System.Net.Http;
using System.Threading.Tasks;
using MarkopTest.IntegrationTest;
using Microsoft.Extensions.DependencyInjection;
using WebAPI;
using Xunit.Abstractions;
public class AppFactory : IntegrationTestFactory<Startup, dynamic>
{
public AppFactory(ITestOutputHelper outputHelper, HttpClient defaultClient = null)
: base(outputHelper, defaultClient)
{
}
protected override string GetUrl(string url, string controllerName, string testMethodName)
{
return "/api/v1/" + url;
}
protected override Task Initializer(IServiceProvider hostServices)
{
return Task.CompletedTask;
}
protected override void ConfigureTestServices(IServiceCollection services)
{
// Replace services for test environment (DB, cache, auth, etc.)
}
protected override Task<bool> ValidateResponse(HttpResponseMessage response, dynamic options)
{
return Task.FromResult(response.IsSuccessStatusCode);
}
}using MarkopTest.Attributes;
using Xunit;
using Xunit.Abstractions;
[Endpoint("[controller]/[action]")]
public class AccountTests : AppFactory
{
public AccountTests(ITestOutputHelper outputHelper) : base(outputHelper)
{
}
[MarkopTest.Attributes.Theory]
[InlineData("user@example.com", "password")]
public void SignIn(string login, string password)
{
PostJson(new { Login = login, Password = password });
}
}dotnet testOr run a specific project:
dotnet test sample/test/IntegrationTest/IntegrationTest.csproj