C# 使用行为类似于<;TBehavior>;在基类上
我想指定一个类似于基本规范的行为,以确保将特定方法标记为虚拟方法。大概是这样的:C# 使用行为类似于<;TBehavior>;在基类上,c#,bdd,mspec,C#,Bdd,Mspec,我想指定一个类似于基本规范的行为,以确保将特定方法标记为虚拟方法。大概是这样的: public abstract class command_handler_context<TCommandHandler, TCommand> : abstract_context<TCommandHandler> where TCommandHandler : ICommandHandler<TCommand> where TCommand : IC
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;
}
当前仅在上下文类上支持行为,而不支持基类。是否可以将
ExecuteMethodOverridableBehavior
行为的it
s直接考虑到基类中?(It
s在执行派生上下文时将在基类中执行。)
对不起,我写上面的答案时一定是疯了<基类上不支持code>It字段,只支持build
和,因为
。因为,所以只能有一个,但层次结构中可能有多个建立
子句
我担心将行为(行为类似于
)放在所有派生类上是唯一的方法。我更愿意这样做。但是它不起作用。它不会出现在resharper测试运行程序中,也不会从命令行运行。只是为了确保我的回答正确:It
基类中的字段对您不起作用?你能把完整的代码(包括行为规范)贴在什么地方吗?
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();
}