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
| Member | Summary |
|---|---|
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
| Member | Summary |
|---|---|
Count | How many steps are on the tape. |
Methods
| Member | Summary |
|---|---|
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
| Name | Type | Description |
|---|---|---|
clock | TimeProvider | Where 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
| Name | Type | Description |
|---|---|---|
row | int | Row, counted from the top of the terminal. |
column | int | Column, counted from its left edge. |
button | MouseButton | Which 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
| Name | Type | Description |
|---|---|---|
key | ConsoleKey | The key. |
modifiers | KeyModifiers | What was held with it. |
Returns SessionTape — The tape, so steps chain.
Paste(string)
public SessionTape Paste(string text);
Writes down a paste.
Parameters
| Name | Type | Description |
|---|---|---|
text | string | What 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
| Name | Type | Description |
|---|---|---|
host | ArlecchinoTestHost | The 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
| Name | Type | Description |
|---|---|---|
text | string | The 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
| Name | Type | Description |
|---|---|---|
key | KeyPress | The 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
| Name | Type | Description |
|---|---|---|
mouse | MouseEvent | The 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
| Name | Type | Description |
|---|---|---|
row | int | Row the pointer was over. |
column | int | Column the pointer was over. |
down | bool | Whether 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
| Name | Type | Description |
|---|---|---|
text | string | What 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
| Name | Type | Description |
|---|---|---|
milliseconds | int | How long was waited. |
Returns SessionTape — The tape, so steps chain.