Skip to main content

SessionTape class

Namespace: Arlecchino.Testing · Assembly: Arlecchino.Testing

A session written down: the events that go in, the waits between them, and where a frame is worth looking at. A tape is written by hand rather than recorded.

var frames = new SessionTape()
.Type(":")
.Shot()
.Type("copy")
.Wait(200)
.Shot()
.Play(host);

Assert.Contains("Copy files", frames[^1], StringComparison.Ordinal);

public sealed class SessionTape

Constructors

MemberSummary
SessionTape()Starts an empty tape, for one written by hand.
SessionTape(TimeProvider)Starts an empty tape that measures the gaps between events itself, for one captured from an application as it runs.

Properties

MemberSummary
CountHow many steps are on the tape.

Methods

MemberSummary
Click(int, int, MouseButton)Writes down a click.
Key(ConsoleKey, KeyModifiers)Writes down a key press as the terminal would report it.
Paste(string)Writes down a paste.
Play(ArlecchinoTestHost)Plays the tape into a host, waiting what it waited and doing what it did, and hands back a frame for every mark on it.
Read(string)Reads a tape back from what SessionTape.ToString wrote.
RecordKey(KeyPress)Writes down a key exactly as a terminal reports one — character and key together — for a test that drives the tape from events it built itself rather than from the members above.
RecordMouse(MouseEvent)Writes down a mouse event exactly as a terminal reports one.
Scroll(int, int, bool)Writes down a turn of the wheel.
Shot()Marks that a frame is worth looking at here. Playing the tape hands one back for every mark, so a tape says not only what happened but where to look.
ToString()The tape as text, one step to a line, ready to be written to a file.
Type(string)Writes down text typed one character at a time.
Wait(int)Writes down a wait, which is what makes timeouts and work on a clock replayable.

Constructors in detail

SessionTape()

public SessionTape();

Starts an empty tape, for one written by hand.

SessionTape(TimeProvider)

public SessionTape(TimeProvider clock);

Starts an empty tape that measures the gaps between events itself, for one captured from an application as it runs.

Parameters

NameTypeDescription
clockTimeProviderWhere the gaps are measured from. It is read as GetUtcNow rather than as a timestamp, because that is the face the application itself lives by — a tape measured off the high-frequency timer cannot be replayed against a clock a test moves by hand.

Properties in detail

Count

public int Count { get; }

How many steps are on the tape.

Type int

Methods in detail

Click(int, int, MouseButton)

public SessionTape Click(int row, int column, MouseButton button = Left);

Writes down a click.

Parameters

NameTypeDescription
rowintRow, counted from the top of the terminal.
columnintColumn, counted from its left edge.
buttonMouseButtonWhich button.

Returns SessionTape — The tape, so steps chain.

Key(ConsoleKey, KeyModifiers)

public SessionTape Key(ConsoleKey key, KeyModifiers modifiers = None);

Writes down a key press as the terminal would report it.

Parameters

NameTypeDescription
keyConsoleKeyThe key.
modifiersKeyModifiersWhat was held with it.

Returns SessionTape — The tape, so steps chain.

Paste(string)

public SessionTape Paste(string text);

Writes down a paste.

Parameters

NameTypeDescription
textstringWhat was pasted.

Returns SessionTape — The tape, so steps chain.

Play(ArlecchinoTestHost)

public List<string> Play(ArlecchinoTestHost host);

Plays the tape into a host, waiting what it waited and doing what it did, and hands back a frame for every mark on it.

Parameters

NameTypeDescription
hostArlecchinoTestHostThe application to play into.

Returns List<T><string> — One frame per mark, in order.

Read(string)

public static SessionTape Read(string text);

Reads a tape back from what SessionTape.ToString wrote.

Parameters

NameTypeDescription
textstringThe tape as text.

Returns SessionTape — The tape.

RecordKey(KeyPress)

public SessionTape RecordKey(KeyPress key);

Writes down a key exactly as a terminal reports one — character and key together — for a test that drives the tape from events it built itself rather than from the members above.

Parameters

NameTypeDescription
keyKeyPressThe key.

Returns SessionTape — The tape, so steps chain.

RecordMouse(MouseEvent)

public SessionTape RecordMouse(MouseEvent mouse);

Writes down a mouse event exactly as a terminal reports one.

Parameters

NameTypeDescription
mouseMouseEventThe event.

Returns SessionTape — The tape, so steps chain.

Scroll(int, int, bool)

public SessionTape Scroll(int row, int column, bool down);

Writes down a turn of the wheel.

Parameters

NameTypeDescription
rowintRow the pointer was over.
columnintColumn the pointer was over.
downboolWhether it turned down.

Returns SessionTape — The tape, so steps chain.

Shot()

public SessionTape Shot();

Marks that a frame is worth looking at here. Playing the tape hands one back for every mark, so a tape says not only what happened but where to look.

Returns SessionTape — The tape, so steps chain.

ToString()

public override string ToString();

The tape as text, one step to a line, ready to be written to a file.

Returns string — The tape.

Type(string)

public SessionTape Type(string text);

Writes down text typed one character at a time.

Parameters

NameTypeDescription
textstringWhat was typed.

Returns SessionTape — The tape, so steps chain.

Wait(int)

public SessionTape Wait(int milliseconds);

Writes down a wait, which is what makes timeouts and work on a clock replayable.

Parameters

NameTypeDescription
millisecondsintHow long was waited.

Returns SessionTape — The tape, so steps chain.