Table of Contents

Class RecordingSessionRequests

Namespace
Typhon.Engine
Assembly
Typhon.Engine.dll

A fake ISessionRequests for unit tests: session events are raised by hand, and every request the code under test makes is recorded, in call order, through the same SessionRequest builder — and so the same argument checks — a running engine uses.

public sealed class RecordingSessionRequests : ISessionRequests
Inheritance
RecordingSessionRequests
Implements
Inherited Members

Examples

var subs = new RecordingSessionRequests();
var s = new SessionId(1, 1);
subs.Raise(SessionEvent.Create(SessionEventKind.Opened, s));
lifecycle.Run(subs);                                 // the application's code, written against ISessionRequests
Assert.That(subs.ControlledOf(s), Is.Not.EqualTo(EntityId.Null));
subs.NextTick();
subs.Raise(SessionEvent.Create(SessionEventKind.Closed, s, resumable: true, reason: SessionCloseReason.LinkLost));

Remarks

Nothing is applied: a request for a session that never opened is recorded like any other. ControlledOf(SessionId) answers from the Control requests recorded so far, the latest per session, as the engine's apply pass would leave it. Single-threaded, as a test is.

Constructors

RecordingSessionRequests(params string[])

A recorder.

public RecordingSessionRequests(params string[] explicitSets)

Parameters

explicitSets string[]

The explicit group sets SetSources(string, params long[]) accepts, as subs.Groups(...) would declare them.

Properties

Requests

Every request recorded, in call order, across ticks.

public IReadOnlyList<RecordedSessionRequest> Requests { get; }

Property Value

IReadOnlyList<RecordedSessionRequest>

SessionEvents

What happened to sessions since the last tick, in order (SessionEvents).

public ReadOnlySpan<SessionEvent> SessionEvents { get; }

Property Value

ReadOnlySpan<SessionEvent>

Methods

ClearRequests()

Forgets every recorded request and the controlled entities; the events of this tick are kept.

public void ClearRequests()

ControlledOf(SessionId)

The entity a session controls, or Null (ControlledOf(SessionId)).

public EntityId ControlledOf(SessionId session)

Parameters

session SessionId

The session.

Returns

EntityId

The controlled entity.

NextTick()

Starts the next tick: the events raised so far are no longer delivered. The recorded requests are kept.

public void NextTick()

ProfileOf(SessionId)

The profile last requested for a session, or null.

public string ProfileOf(SessionId session)

Parameters

session SessionId

The session.

Returns

string

The profile's name.

Raise(in SessionEvent)

Adds an event to this tick's batch.

public void Raise(in SessionEvent sessionEvent)

Parameters

sessionEvent SessionEvent

The event, from Create(SessionEventKind, SessionId, object, SessionId, bool, SessionCloseReason, SessionRole, string, ushort, RealmId, int).

RequestsOf(SessionId)

The requests recorded for one session, in call order.

public List<RecordedSessionRequest> RequestsOf(SessionId session)

Parameters

session SessionId

The session.

Returns

List<RecordedSessionRequest>

Its requests.

Session(SessionId)

Asks something of a session; applied by the next tick's prologue (Session(SessionId)).

public SessionRequest Session(SessionId session)

Parameters

session SessionId

The session.

Returns

SessionRequest

A builder whose calls are recorded.

WasKicked(SessionId)

Whether a session was kicked.

public bool WasKicked(SessionId session)

Parameters

session SessionId

The session.

Returns

bool

True when a kick was requested.