我想在基本规范上指定一个 Behaves_like 以确保将特定方法标记为虚拟。像这样的东西:
public abstract class command_handler_context<TCommandHandler, TCommand>
: abstract_context<TCommandHandler>
where TCommandHandler : ICommandHandler<TCommand>
where TCommand : ICommand, new()
{
protected static TCommand Command;
private Establish context = () =>
{
Command = new TCommand();
};
private Because of = () => SubjectUnderTest.Execute(Command);
private Behaves_like<ExecuteMethodOverridableBehavior<TCommandHandler>> an_overridable_execute_method;
}
然而,测试运行者并没有选择这个。我认为在命令处理程序的每个规范上指定 ehaves_like 将是一个主要的 PITA。这可能吗?如果不是,这是一种理想的行为吗?
更新:抱歉回复晚了,这是失败的规范:
public abstract class context_base
{
protected static bool Result;
protected static bool RanOnBaseClass;
private Because of = () => { Result = true; };
private It should_be_true = () =>
{
RanOnBaseClass = true;
Result.ShouldBeTrue();
};
}
public class when_using_behaviors_on_a_base_class
: context_base
{
private It should_run_specs_on_the_base_class = () => RanOnBaseClass.ShouldBeTrue();
}