ClassInitialize and ClassCleanup when using Helper objects for action steps

Apr 5, 2013 at 7:47 PM
I've been using the Fluent Interfaces for nbehave to create integration tests for a few weeks now and for the most part this works really nicely.

However when using a helper object to execute the action steps, the way I'm currently dealing with dependencies that need to be initialised before any of the action steps is executed and cleaned up after all of the action steps have been executed is somewhat messy.

I see in the ScenarioDrivenSpecStepRunner.cs class that there are a couple of methods which look suspiciously like they might provide the plumbing I need to do this more cleanly:
        public void BeforeScenario()
        {
            var beforeAction = resolvers
                .Select(resolver => resolver.ResolveOnBeforeScenario())
                .FirstOrDefault(action => action != null);
            if (beforeAction != null)
                beforeAction();
        }

        public void AfterScenario()
        {
            var afterAction = resolvers
                .Select(resolver => resolver.ResolveOnAfterScenario())
                .FirstOrDefault(action => action != null);
            if (afterAction != null)
                afterAction();
        }
However as I'm new to nbehave I'm not sure how I would configure the appropriate "resolvers" to get the step runner to call my initialization and cleanup code before/after the scenario gets executed... and this isn't immediately apparent gazing at the code.

Has anyone ever used these OnBeforeScenario and OnAfterScenario events and, if so, how is this done?

Cheers,
James
Apr 5, 2013 at 8:19 PM
So scratch that... finally found what I was after in the docs :)

Cheers,
James