I see two issues with your test code:
- The expression you use for setting up the
Where()
call onIMessageRouters
is too explicit. It should not care about what exact function is passed. - You are verifying whether
Route()
has been called on theSubject
. Instead you should verify whether theMessage
has been passed to theIMessageRouter
.
As an additional improvement, you can omit the Router
field and use The<IMessageRouter>()
directly.
[Subject(typeof(RoutingEngine))]
public class when_routing_a_message_with_fakes : WithSubject<RoutingEngine>
{
Establish that = () =>
{
Message = new MyMessage { SomeValue = 1, SomeOtherValue = 11010 };
The<IMessageRouter>().WhenToldTo(x => x.CanRoute(Message)).Return(true);
The<IMessageRouters>().WhenToldTo(x => x.Where(Param<Func<IMessageRouter, bool>>.IsAnything))
.Return(new List<IMessageRouter> { The<IMessageRouter>() });
};
Because of = () => Subject.Route(Message);
It should_route_the_message = () =>
The<IMessageRouter>().WasToldTo(x => x.Route(Message));
static MyMessage Message;
}