Skip to content

Communication debugging & testing

Daniel Frantík edited this page May 13, 2026 · 3 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 { Id = "*1", Address = "10.0.0.1/24", Interface = "ether1" })
    .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

Since v 3.5 - complete communication is written to the Output window.

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

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.

Clone this wiki locally