Core Concepts
Understand the key concepts behind the TestHelpers SDK.
TestFlow
The main testing orchestrator that wraps your module and provides testing capabilities.
Key Features
- Automatic flow management with start/stop lifecycle
- Message routing between test modules
- Timeout configuration for different testing scenarios
- Multiple output support for complex modules
Creating a TestFlow
var module = new MyModule();
var flow = module.SetupFlow(timeout: 10000, numberOfOutputs: 1);
Parameters:
timeout- Maximum time to wait for operations in milliseconds (default: 10,000ms)numberOfOutputs- Number of output channels to create (default: 1)
Fluent API
The SDK provides a fluent interface for configuring your test environment.
Dependency Injection
Add credentials and resources to your module:
var flow = module.SetupFlow()
.WithCredential(new MyCredential { Id = credentialId })
.WithResource(new MyResource { Id = resourceId });
Method Chaining
Build complex test scenarios with method chaining:
var flow = module.SetupFlow(timeout: 30000)
.WithCredential(credential)
.WithResource(resource);
await flow.Start();
await flow.Receive(message);
var result = await flow.GetNextResult();
await flow.Stop();
Test Lifecycle
Every test follows a consistent lifecycle:
- Setup - Create module and configure settings
- Arrange - Setup test flow with dependencies
- Start - Initialize and start the module
- Act - Send messages and retrieve results
- Stop - Clean shutdown of the module
- Assert - Verify expected behavior
Lifecycle Example
[Fact]
public async Task TestModuleLifecycle()
{
// 1. Setup
var module = new MyModule();
module.Settings.Property = "value";
// 2. Arrange
var flow = module.SetupFlow();
// 3. Start
var startResult = await flow.Start();
Assert.True(startResult.IsSuccess);
// 4. Act
await flow.Receive(new FlowMessage());
var result = await flow.GetNextResult();
// 5. Stop
var stopResult = await flow.Stop();
Assert.True(stopResult.IsSuccess);
// 6. Assert
Assert.NotNull(result);
}
Message Flow
Understanding how messages flow through your module during testing:
Test Code → Receive() → Module Processing → Output Queue → GetNextResult()
The TestFlow manages the output queue, allowing you to retrieve results asynchronously without dealing with internal module queues.