Table of Contents

Quick Start

Write your first module test in minutes.

Your First Test

Create RandomNumberModuleTests.cs:

using Xunit;
using Crosser.EdgeNode.Modules.Testing;
using Crosser.EdgeNode.Flows.Models.Abstractions.Models;

namespace MyOrg.FlowModule.RandomNumberModule.Tests;

public class RandomNumberModuleTests
{
    [Fact]
    public async Task GeneratesRandomNumberInRange()
    {
        // Arrange
        var module = new RandomNumberModule();
        module.Settings.TargetMin = 10;
        module.Settings.TargetMax = 20;
        module.Settings.TargetName = "randomValue";
        
        var flow = module.SetupFlow();

        // Act
        await flow.Start();
        await flow.Receive(new FlowMessage());
        var result = await flow.GetNextResult();
        await flow.Stop();

        // Assert
        Assert.True(result.Has("randomValue"));
        var value = result.Get<int>("randomValue");
        Assert.InRange(value, 10, 19);
    }
}

Run the Test

dotnet test

Expected output:

Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1

Understanding the Test

  1. Arrange - Create and configure your module, setup test flow
  2. Act - Start flow, send message, retrieve result, stop flow
  3. Assert - Verify the module behaved correctly

Key Methods

  • SetupFlow() - Wraps module in test harness
  • Start() - Initializes and starts the module
  • Receive(message) - Sends message to module
  • GetNextResult() - Retrieves processed message
  • Stop() - Stops the module

Next Steps

>> Core Concepts