Skip to content
This repository has been archived by the owner on Apr 20, 2019. It is now read-only.

CyAScott/Ants

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ants Asp.Net Test Server (ANTS)

Build status NuGet Badge

ANTS is a framework for running an Asp.Net application in process instead of IIS. The target Asp.Net application will accept http requests from a custom HttpClient created by ANTS. This will allow you to test your application without the need to open up access to sockets.

Simple Exmaple

The first thing you will need to do is to install the Ants NuGet package. Run the command below in the Package Manager Console.

Install-Package Ants

After the package is installed you can run the code below to see a working example:

using System.Threading.Tasks;
using Ants;
using Ants.Web;

public static class AntsExample
{
    public static async Task Run()
    {
        //Global is my Asp.Net Http Application class
        AspNetTestServer.Start<Global>(new StartApplicationArgs
        {
            PhysicalDirectory = @"C:\MySolutionFolder\MyWebProjFolder"
        });

        using (var client = AspNetTestServer.GetHttpClient<Global>())
        using (var response = await client.GetAsync("/SomeRoute").ConfigureAwait(false))
        {
            response.EnsureSuccessStatusCode();
        }
        
        await AspNetTestServer.Stop<Global>().ConfigureAwait(false);
    }
}

The example above creates an App Domain for your http application to run in, using the same method that IIS does. Once the application is started, you can get an HttpClient for making http calls to the Asp.Net application.

Icon Created By

Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 B