tags:

views:

28

answers:

1

I would like to specify a Behaves_like on a base specification to ensure that a particular method is marked as virtual. Something like this:

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

However the test runner does not pick this up. I think it would be a major PITA to specify ehaves_like on every single spec for a command handler. Is this possible? If not, is this a desired behavior?

Update: Sorry about the late response, here is the failing spec:

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

Behaviors are currently only supported on context classes, not base classes. Would it be feasable to factor the Its of the ExecuteMethodOverridableBehavior behavior right into the base class? (Its in base classes will be executed when derived contexts execute.)

Sorry, I must have been out of my mind when writing the answer above. It fields are not supported on base classes, only Establish and Because. While there can be only one Because, there might be multiple Establish clauses in the hierarchy.

I fear putting the behavior (Behaves_like) on all derived classes is the only way to go.

Alexander Groß
I would prefer to do it that way. However it doesn't work. It doesn't show up in the resharper test runner, and it doesn't run from the command line.
João Bragança
Just to make sure I get this right: `It` fields in base classes do not work for you? Can you please post the complete code (including the behavior's specifications) somewhere?
Alexander Groß
My post has been updated, please take a look. Thanks.
João Bragança