Bug in EventBroker.UnitTestFactory?

6 views
Skip to first unread message

Philipp Dolder

unread,
Feb 21, 2011, 3:28:47 AM2/21/11
to bbvcommon
Hello guys,

When using the UnitTestFactory for the EventBroker I ran into the
following issue this morning:
I defined a HandlerRestriction.Asynchronous on my EventPublication.
When I register the subscriber on the EventBroker I get an
EventTopicException saying that I'm not allowed to subscribe. Though I
have set the subscription to Background
([EventSubscription(DistributedTopics.RequestDiscovery,
typeof(Background))]).

In my opinion it looks like the UnitTestFactory is not doing its job
properly.

Can somebody confirm if this is a bug or it's me expecting too much
from the UnitTestFactory?

Thanks
Phil

Urs Enzler

unread,
Feb 21, 2011, 3:36:40 AM2/21/11
to bbvcommon
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

Philipp Dolder

unread,
Feb 21, 2011, 8:00:30 AM2/21/11
to bbvcommon
Hi Urs

Thanks for your fast reply. It is working now. Should I open a bug in
the issue tracker?

Regards,
Phil
Reply all
Reply to author
Forward
0 new messages