Skip to content
Mogens Heller Grabe edited this page Mar 14, 2016 · 6 revisions

When you are developing software, you probably want to ensure that you can bend and flex your code and refactor it to your heart's desire without breaking anything.

You probably do that by writing automated tests that test units of your system at various levels.

This page will describe three different levels of testing with Rebus.

Full in-memory bus

Since Rebus can be configured with an in-memory transport and in-memory persistence, you can get away with testing many things by starting a full Rebus instance to participate in your tests without risking tests interfering with each other, or risking that the environment somehow affects the outcome of your tests.

This approach can be very useful to verify that messages flow like you expect them to, since you can easily spin up multiple endpoints that communicate using the in-mem transport - you just need to pass the same Network instance to them so that they can reach each other - e.g. like so:

var network = new InMemNetwork();

var containerAdapter1 = GetContainerAdapter1();
var containerAdapter2 = GetContainerAdapter2();

using (var bus1 = CreateBus("b1", network, containerAdapter1))
using (var bus2 = CreateBus("b2", network, containerAdapter2))
{
	// do stuff in here
}

// further down

public IBus CreateBus(string inputQueueName, InMemNetwork network, IContaineAdapter containerAdapter)
{
	return Configure.With(containerAdapter)
		.Transport(t => t.UseInMemoryTransport(network, inputQueueName))
		.Start();
}

Unit testing a handler

Clone this wiki locally