I am trying to assert that a method was called in MSpec while using NSubstitute as the mocking framework. The Subject
has an empty implementation of ExecuteAll()
. It should fail, but it passes!
public class When_told_to_execute_all_it_should_execute_all_commands
: WithSubject<CommandHandler>
{
static AddTaskCommand command1;
static AddTaskCommand command2;
Establish context = () =>
{
command1 = An<AddTaskCommand>();
command2 = An<AddTaskCommand>();
Subject.AcceptCommand(command1);
Subject.AcceptCommand(command2);
};
Because of = () => Subject.ExecuteAll();
It should_have_called_execute_on_command_1 = () => command1.Received().Execute();
It should_have_called_execute_on_command_2 = () => command2.Received().Execute();
}
I tried using a different assertion, but it passes, too! It seems that this is itself calling into Execute()
command1.WasToldTo(x => x.Execute());
I removed NSubstitute and replaced it with Moq. After fixing the error about making Execute()
virtual, it worked. Is NSubstitute bugged or not reporting errors correctly?