Create the C# Runtime API client

Example 1

In this example,

using Neotys.RuntimeAPI.Client;
using Neotys.RuntimeAPI.Model;

namespace TestRuntimeAPI
{
    class StartTestExample
    {
        static void Main(string[] args)
        {
            IRuntimeAPIClient client = RuntimeAPIClientFactory.NewClient("http://localhost:7400/Runtime/v1/Service.svc/");
            if (Status.READY == client.getStatus())
            {
                // make sure that NeoLoad is ready before running a test
                client.StartTest(new StartTestParamsBuilder("WANImpact Local")
                     .executionContext(new ExecutionContextBuilder().variable("name", "value").Build())
                     .Build());
                do
                {
                    // wait that the test is launched
                    System.Threading.Thread.Sleep(1000);
                } while (Status.TEST_LOADING == client.getStatus());
                if (Status.TEST_RUNNING == client.getStatus())
                {
                    int addedUsers = client.AddVirtualUsers(new AddVirtualUsersParamsBuilder("MyPopulationSmallCities", 10).Build());
                    System.Console.WriteLine(addedUsers + " users added");
                }
            }
        }
    }
}

Example 2

In this example, we stop Virtual Users in population MyPopulationSmallCities and then we stop the test itself.

using Neotys.RuntimeAPI.Client;
using Neotys.RuntimeAPI.Model;
using System;

namespace TestRuntimeAPI
{
	class StopTestExample
	{
    	static void Main(string[] args)
    	{
        	IRuntimeAPIClient client = RuntimeAPIClientFactory.NewClient("http://localhost:7400/Runtime/v1/Service.svc/");

        	// make sure a test is running
        	if (Status.TEST_RUNNING == client.getStatus())
        	{
            	int stoppedUsers = client.StopVirtualUsers(new StopVirtualUsersParamsBuilder("MyPopulationSmallCities", 5).Build());
            	System.Console.WriteLine(stoppedUsers + " users stopped");

            	System.Threading.Thread.Sleep(10000);
            	client.StopTest(new StopTestParamsBuilder().Build());
        	}
    	}
	}
}