Skip to content

Communication debugging & testing

Claude edited this page Jul 13, 2026 · 6 revisions

Unit testing without a router (TikFakeConnection) ⚠️ Alpha API

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.

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());

Debugging communication under Visual Studio

When a debugger is attached, the complete communication is written to the Output window (ApiConnection.DebugEnabled defaults to Debugger.IsAttached).

Debugging communication

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.

API syntax testing

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.

Clone this wiki locally