I am currently using FakeItEasy for unit testing. I'm faking NServiceBus .Send method call was made in a method.
The problem I'm running across is I'm sending out two message on the bus in the method:
bus.Send(new CommandOne(Id = [something]));
bus.Send(new CommandTwo(Id = [something]));
both commands are sent on the faked bus in the same method call (I removed the real command names and params for the sake of simplicity).
Here is what my NUnit code/FakeItEasy code looks like:
bus = A.Fake<IBus>;
var sut = new Sut(bus);
sut.MethodCall();
A.CallTo(() => bus.Send(A<CommandOne>.That.Matches(co => co.Id == [someId]).MustHaveHappened(Repeated.Exactly.Once);
A.CallTo(() => bus.Send(A<CommandTwo>.That.Matches(co => co.Id == [someId]).MustHaveHappened(Repeated.Exactly.Once);
But, when I run this test, I get a test failed result, stating:
System.InvalidCastException : Unable to cast object of type 'CommandTwo' to type 'CommandOne'.
When I send two different commands suing the same fake, I'm specifying the specific object type and a match on the properties of the command, but FakeItEasy is trying to cast the first command being sent (CommandOne), two the second command sent (CommandTwo)...
is there a way to use FakeItEasy to test the same method being called twice of a faked object with different values for each call?
Thanks, Mike