C# Client

The C# client is compatible with .NET Framework version 4.0 and above.

To use our C# API to start or stop tests onto NeoLoad, use our DLLs as explained in Create the C# Runtime API client.

First instantiate a RuntimeAPIClient providing a URL and API key.

Then call the method available:

  • GetStatus() to get the current status of NeoLoad,

  • StartTest() to start a test,

  • StopTest() to stop a test,

  • AddVirtualUsers() to add Virtual Users instances,

  • StopVirtualUsers() to stop Virtual Users instances,

  • StartInfrastructures() to start infrastructures,

  • StopInfrastructures() to stop infrastructures,

  • GetInfrastructuresStatus() to get the current status of the infrastructures.

Configure the project

In a Visual Studio project, it is necessary to include the DLL files available in the NuGet website.

To configure the project with DLLs from NuGet, follow these steps:

  1. Open the project.

  2. Open the Solution Explorer.

  3. Find the References node in the project tree.

  4. Click right and choose Manage NuGet Packages....

  5. In the Search field, type: "neotys runtime".

  6. Select dependency name: "NeotysRestRuntimeAPI".

  7. Click the Install button.

Create the C# Runtime API client

Example 1

In this example,

  • we start a test with the scenario WANImpact Local and then we add Virtual Users to population MyPopulationSmallCities.

  • we override variable "name" with value "value"

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());
            }
        }
    }
}