Table of Contents

Class TestAgent

Namespace
Xping.Sdk.Core
Assembly
Xping.Sdk.Core.dll

The TestAgent class is the main class that performs the testing logic of the Xping SDK. It runs test components, for example action or validation steps, such as DnsLookup, IPAddressAccessibilityCheck etc., using the HTTP client and the headless browser. It also creates a test session object that summarizes the outcome of the test operations.

public class TestAgent : IDisposable
Inheritance
TestAgent
Implements
Inherited Members
Extension Methods

Remarks

The TestAgent class performs the core testing logic of the Xping SDK. It has two methods that can execute test components that have been added to a container: RunAsync(Uri, TestSettings?, CancellationToken) and ProbeAsync(Uri, TestSettings, CancellationToken). The former executes the test components and creates a test session that summarizes the test operations. The latter serves as a quick check to ensure that the test components are properly configured and do not cause any errors. The TestAgent class collects various data related to the test execution. It constructs a TestSession object that represents the outcome of the test operations, which can be serialized, analyzed, or compared. The TestAgent class can be configured with various settings, such as the timeout, using the TestSettings class.

important

Please note that the TestAgent class is designed to be used with a dependency injection system and should not be instantiated by the user directly. Instead, the user should register the TestAgent class in the dependency injection container using one of the supported methods, such as the AddTestAgent(IServiceCollection) extension method for the IServiceCollection interface. This way, the TestAgent class can be resolved and injected into other classes that depend on it.

Host.CreateDefaultBuilder(args)
                       .ConfigureServices((services) =>
                       {
                           services.AddHttpClientFactory();
                           services.AddTestAgent(agent =>
                           {
                               agent.UploadToken = "--- Your Upload Token ---";
                           });
                       });

Properties

Container

Retrieves the Pipeline instance that serves as the execution container.

public Pipeline Container { get; }

Property Value

Pipeline

Remarks

This property provides access to the appropriate Pipeline instance based on the current configuration. If configured for per-thread instantiation, it returns a thread-specific Pipeline instance, ensuring thread safety. In a shared configuration, it provides a common Pipeline instance for all threads.

Exceptions

InvalidOperationException

This exception is thrown if a per-thread Pipeline instance is not available, which could indicate an issue with its construction or an attempt to access it post-disposal.

InstantiatePerThread

Controls whether the TestAgent's pipeline container object should be instantiated for each thread separately. When set to true, each thread will have its own instance of the pipeline container. Default is true.

public bool InstantiatePerThread { get; set; }

Property Value

bool

UploadToken

Gets or sets the upload token that links the TestAgent's results to the project configured on the server. This token facilitates the upload of testing sessions to the server for further analysis. If set to null, no uploads will occur. Default is null.

public string? UploadToken { get; set; }

Property Value

string

Methods

Cleanup()

Clean up tests components from the container.

public void Cleanup()

Remarks

This method is called to clean up the test components. It ensures that the components collection is emptied, preventing cross-contamination of state between tests.

CreateTestContext(IInstrumentation)

Creates a new TestContext instance using the provided instrumentation and services from the service provider.

protected virtual TestContext CreateTestContext(IInstrumentation instrumentation)

Parameters

instrumentation IInstrumentation

An IInstrumentation object that provides mechanisms for monitoring and interacting with the test execution process.

Returns

TestContext

A TestContext object configured with the necessary services and instrumentation for test execution.

Remarks

This method initializes a TestContext object, which encapsulates the environment in which a test runs, providing access to services such as session building and progress reporting.

Dispose()

Releases the resources used by the TestAgent.

public void Dispose()

Dispose(bool)

Releases the resources used by the TestAgent.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

A flag indicating whether to release the managed resources.

ProbeAsync(Uri, TestSettings, CancellationToken)

Asynchronously probes a test components registered in the current instance of the Container using the specified URL and settings.

public Task<bool> ProbeAsync(Uri url, TestSettings settings, CancellationToken cancellationToken = default)

Parameters

url Uri

A Uri object that represents the URL of the page being validated.

settings TestSettings

A TestSettings object that contains the settings for the test.

cancellationToken CancellationToken

An optional CancellationToken object that can be used to cancel the validation process.

Returns

Task<bool>

A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the probe was successful or not.

RunAsync(Uri, TestSettings?, CancellationToken)

This method executes the tests. After the tests operations are executed, it constructs a test session that represents the outcome of the tests operations.

public Task<TestSession> RunAsync(Uri url, TestSettings? settings = null, CancellationToken cancellationToken = default)

Parameters

url Uri

A Uri object that represents the URL of the page being validated.

settings TestSettings

Optional TestSettings object that contains the settings for the tests.

cancellationToken CancellationToken

An optional CancellationToken object that can be used to cancel the validation process.

Returns

Task<TestSession>

Returns a Task<TestSession> object that represents the asynchronous outcome of testing operation.