Hi Phil
You're right.
The UnitTestFactory uses always a synchronous handler that does not do
any thread switching (like using handler "Publisher").
This results in unit tests that do not use multi-threading and are
therefore much easier to write.
However, there is a bug that the factory should distinguish between
handler requests (synchronous and asynchronous).
You can get around this issue by deriving your own factory from the
UnitTestFactory and overriding the method CreateHandler and return a
Publisher handler for synchronous cases and a FakeAsyncPublisher for
asynchronous cases.
The FakePublisher should look like this:
public class FakeAsyncPublisher : IHandler
{
/// <summary>
/// Gets the kind of the handler, whether it is a synchronous
or asynchronous handler.
/// </summary>
/// <value>The kind of the handler (synchronous or
asynchronous).</value>
public HandlerKind Kind
{
get { return HandlerKind.Asynchronous; }
}
/// <summary>
/// Initializes the handler.
/// </summary>
/// <param name="subscriber">The subscriber.</param>
/// <param name="handlerMethod">Name of the handler method on
the subscriber.</param>
public void Initialize(object subscriber, MethodInfo
handlerMethod)
{
// there is nothing to initialize
}
/// <summary>
/// Executes the subscription synchronously on the same thread
as the publisher is currently running.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/>
instance containing the event data.</param>
/// <param name="subscriptionHandler">The subscription
handler.</param>
/// <returns>
/// The exception that occurred during handling of the event.
Null if no exception occurred
/// </returns>
public Exception Handle(object sender, EventArgs e, Delegate
subscriptionHandler)
{
try
{
subscriptionHandler.DynamicInvoke(sender, e);
}
catch (TargetInvocationException ex)
{
return ex.InnerException;
}
return null;
}
Cheers,
Urs