-
Notifications
You must be signed in to change notification settings - Fork 99
Communication debugging & testing
Add the tik4net.testing NuGet package to your test project and use TikFakeConnection instead
of a real ITikConnection. It intercepts at CallCommandSync so the full call stack — including
the O/R mapper — runs through real code.
-
Testing low-level API —
CallCommandSync, raw sentences -
Testing mid-level API —
ITikCommand.ExecuteList,ExecuteScalar,ExecuteAsync, … -
Testing high-level API —
LoadAll,Save,Delete,SaveListDifferences, …
Quick example:
var conn = new TikFakeConnection()
.WithEntities(new IpAddress { Address = "10.0.0.1/24", Interface = "ether1" }.WithId("*1"))
.WithScalarResponse(rows => rows.First() == "/ip/address/add", "*2")
.WithNonQuery(rows => rows.First() == "/ip/address/set");
var list = conn.LoadAll<IpAddress>();
Assert.AreEqual(1, list.Count());When a debugger is attached, the complete communication is written to the Output window (ApiConnection.DebugEnabled defaults to Debugger.IsAttached).
If you want to see what is going to the router or see router response, you can hook OnWriteRow and OnReadRow on ITikConnection object.
// ....
connection.OnWriteRow += Connection_OnWriteRow;
// ....
private void Connection_OnWriteRow(object sender, TikConnectionCommCallbackEventArgs e)
{
Console.WriteLine(e.Word);
}The same OnReadRow / OnWriteRow events back the MCP server's includeRawTrace option,
which renders the raw words for every transport (API words, REST HTTP, CLI text, or WinBox M2). See
the MCP server page for the per-transport trace format — it is the easiest way to compare a
transport against the API baseline and spot a mis-mapped field.
If you are not sure about API syntax and you want to test it, you can use sample project SampleConsole to test your commands and see response.
Alternatively, the MCP server (Tools/tik4net.mcp) lets you run any command over any
transport and see the response (and, optionally, the raw protocol trace) from an MCP client such as
Claude Code.