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:
usingSystem;usingSystem.Net.Http;usingSystem.Threading.Tasks;usingMarkopTest.IntegrationTest;usingMicrosoft.Extensions.DependencyInjection;usingWebAPI;usingXunit.Abstractions;publicclassAppFactory:IntegrationTestFactory<Startup,dynamic>{publicAppFactory(ITestOutputHelperoutputHelper,HttpClientdefaultClient=null):base(outputHelper,defaultClient){}protectedoverridestringGetUrl(stringurl,stringcontrollerName,stringtestMethodName){return"/api/v1/"+url;}protectedoverrideTaskInitializer(IServiceProviderhostServices){returnTask.CompletedTask;}protectedoverridevoidConfigureTestServices(IServiceCollectionservices){// Replace services for test environment (DB, cache, auth, etc.)}protectedoverrideTask<bool>ValidateResponse(HttpResponseMessageresponse,dynamicoptions){returnTask.FromResult(response.IsSuccessStatusCode);}}usingMarkopTest.Attributes;usingXunit;usingXunit.Abstractions;[Endpoint("[controller]/[action]")]publicclassAccountTests:AppFactory{publicAccountTests(ITestOutputHelperoutputHelper):base(outputHelper){}[MarkopTest.Attributes.Theory][InlineData("user@example.com","password")]publicvoidSignIn(stringlogin,stringpassword){PostJson(new{Login=login,Password=password});}}dotnet testOr run a specific project:
dotnet test sample/test/IntegrationTest/IntegrationTest.csproj