Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用行为类似于<;TBehavior>;在基类上_C#_Bdd_Mspec - Fatal编程技术网

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();
}