Search Results for

    Show / Hide Table of Contents

    Class TestModeTransport

    In-memory transport for debugging and unit tests. No real I/O. Features: artificial latency, jitter, inbound chunking, and drop simulation. Default auto-responder validates checksum, flips sender/target, and echoes or replaces payload.

    Inheritance
    object
    TestModeTransport
    Implements
    ITransport
    Namespace: Wss.CoreModule
    Assembly: WSS_Core_Interface.dll
    Syntax
    public sealed class TestModeTransport : ITransport

    Constructors

    TestModeTransport(TestModeTransportOptions)

    Initializes a new TestModeTransport with a single options object.

    Declaration
    public TestModeTransport(TestModeTransportOptions options)
    Parameters
    Type Name Description
    TestModeTransportOptions options

    In-memory transport behavior settings.

    Remarks

    Null Rng and FallbackPayload values are replaced with safe defaults.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown when options is null.

    Properties

    AutoResponderAsync

    Optional override auto-responder. If null, the built-in default responder is used.

    Declaration
    public Func<byte[], Task<byte[]>> AutoResponderAsync { get; set; }
    Property Value
    Type Description
    Func<byte[], Task<byte[]>>

    BaseLatency

    Artificial latency applied to inbound delivery.

    Declaration
    public TimeSpan BaseLatency { get; set; }
    Property Value
    Type Description
    TimeSpan

    FallbackPayload

    Payload used when incoming checksum is invalid.

    Declaration
    public byte[] FallbackPayload { get; set; }
    Property Value
    Type Description
    byte[]

    InboundDropProbability

    Probability [0..1] of randomly dropping an inbound chunk.

    Declaration
    public double InboundDropProbability { get; set; }
    Property Value
    Type Description
    double

    IsConnected

    Gets whether the transport is currently connected/open.

    Declaration
    public bool IsConnected { get; }
    Property Value
    Type Description
    bool

    JitterMs

    Random jitter added to BaseLatency, in milliseconds.

    Declaration
    public int JitterMs { get; set; }
    Property Value
    Type Description
    int

    MaxInboundChunkSize

    If >0, splits inbound payloads into chunks of up to this size.

    Declaration
    public int MaxInboundChunkSize { get; set; }
    Property Value
    Type Description
    int

    Rng

    Random generator used for jitter, chunk sizing, drops, and synthetic replies.

    Declaration
    public Random Rng { get; set; }
    Property Value
    Type Description
    Random

    Methods

    ConnectAsync(CancellationToken)

    Opens/initializes the transport connection (e.g., open a serial port, connect a socket, start BLE session).

    Declaration
    public Task ConnectAsync(CancellationToken ct = default)
    Parameters
    Type Name Description
    CancellationToken ct

    Optional cancellation token to abort the connect attempt.

    Returns
    Type Description
    Task

    A task that completes when the transport is connected.

    Exceptions
    Type Condition
    ObjectDisposedException

    If the instance has been disposed.

    OperationCanceledException

    If ct is canceled.

    Exception

    Implementations may throw transport-specific exceptions (e.g., unauthorized port access, device not found).

    DisconnectAsync(CancellationToken)

    Closes the transport connection and stops any background receive loop.

    Declaration
    public Task DisconnectAsync(CancellationToken ct = default)
    Parameters
    Type Name Description
    CancellationToken ct

    Optional cancellation token to abort a long-running disconnect.

    Returns
    Type Description
    Task

    A task that completes when the transport is fully disconnected.

    Exceptions
    Type Condition
    ObjectDisposedException

    If the instance has been disposed.

    OperationCanceledException

    If ct is canceled.

    Dispose()

    Disposes the transport, cancels background operations, and releases resources.

    Declaration
    public void Dispose()

    EnqueueIncoming(byte[], CancellationToken)

    Injects inbound bytes as if received from a physical device. They are subject to latency, jitter, chunking, and drop settings before being delivered.

    Declaration
    public Task EnqueueIncoming(byte[] payload, CancellationToken ct = default)
    Parameters
    Type Name Description
    byte[] payload

    Raw inbound payload.

    CancellationToken ct

    Optional cancellation token.

    Returns
    Type Description
    Task

    SendAsync(byte[], CancellationToken)

    Sends a block of bytes over the transport.

    Declaration
    public Task SendAsync(byte[] data, CancellationToken ct = default)
    Parameters
    Type Name Description
    byte[] data

    The bytes to write. Callers should provide a buffer that will not be mutated during send.

    CancellationToken ct

    Optional cancellation token to cancel the send before it is written. For some transports (e.g., synchronous serial writes), cancellation may only be observed before the write starts.

    Returns
    Type Description
    Task

    A task that completes when the bytes have been handed off to the transport.

    Remarks

    The default auto-responder will generate a reply based on checksum validation and invoke BytesReceived.

    Exceptions
    Type Condition
    ObjectDisposedException

    If the instance has been disposed.

    InvalidOperationException

    If the transport is not connected.

    OperationCanceledException

    If ct is canceled.

    Events

    BytesReceived

    Raised whenever raw bytes arrive from the underlying transport. Each invocation may represent any number of bytes (including zero, depending on implementation), and may contain partial or multiple protocol frames.

    Declaration
    public event Action<byte[]> BytesReceived
    Event Type
    Type Description
    Action<byte[]>
    Remarks

    Implementations should invoke this event promptly as data becomes available. Callers should treat the provided buffer as read-only and copy it if they need to retain it.

    This event is typically raised on a background thread. Consumers should marshal to the main thread if required by their environment.

    Implements

    ITransport
    In this article
    Back to top Generated by DocFX