Skip to content

Unit test your application

Antoine Blanchet edited this page May 26, 2014 · 10 revisions

Along with the core Zebus assembly, we provide a library called "Abc.Zebus.Testing" that contains a toolkit for Testing.

It ranges from object comparison utilities to classes specific to Zebus testing.

Testing a Handler

Just create an instance of your handler in the Setup, and inject it with a TestBus (if used) along with your own dependencies.

You will then be able to write simple test methods of this kind:

public void should_send_an_event_after_the_stuff_is_done()
{
    var command = new DoStuffCommand { Id = 3 };

    _handler.Handle(command);

    _bus.ExpectExactly(new StuffDone { Id = 3 });
}

And if you publish something wrong in your message handler, your test output will look like this:

Missing: StuffDone {
  Id: 3
} 
Not Expected: StuffDone {
  Id: 7
} 

Clone this wiki locally