Try using the ControllerFactory:
public class MyWizard : Controller, IWizardController
{
IWizardStepPage[] pages;
public IWizardStepPage[] GetSteps(IEngineContext context)
{
if (pages == null)
{
pages = new[]
{
typeof (Step1),
typeof (Step2),
typeof (CompletedStep)
}.Select(x =>
context.Services.ControllerFactory.CreateController(x))
.Cast<IWizardStepPage>()
.ToArray();
}
return pages;
}
The only problem with this is if your wizard step pages have
dependencies... the default ControllerFactory only accepts controllers
with parameterless constructors. Actually I just ran into this
problem... looks like I have to come up with a custom
ControllerFactory to test my wizard steps.
On Sep 22, 2:56 pm, "Kristofer Goss" <[EMAIL PROTECTED]> wrote:
> Sorry... I meant to say GetSteps on last post. It looks like Reset is not
> the appropriate place to do some initialization as I was thinking, since as
> the context is not available. By the time Initialize is invoked, the engine
> context and controller context is in place as expected. Still not sure of
> best practices in terms of testing, however; thinks are running nicely.
>
> On Mon, Sep 22, 2008 at 4:51 PM, Kristofer Goss <[EMAIL PROTECTED]> wrote:
> > Yeah, I *think* i could trick it into running assuming I know a bunch of
> > details around what it stores in the session and corresponding keys. I was
> > hoping to avoid this, as now I'm testing MR as much as my own code.
>
> > Here's another puzzler. I've enabled Windsor integration for all my
> > controllers and services which works great. I followed the the docs with
> > regards to implementing the GetPages() factory method for the wizard
> > controller (inject the kernel and call Kernel[typeof(MyPageType)] when
> > returning...
>
> > When I do this, my services are injected, however; the underlying MR
> > context is not in place... so if I try and touch the flash, session, etc. in
> > my page, I'm deref'ing a null value. It seems like I need to propagate the
> > context through, but I'm not sure of best practice here.
>
> > On Mon, Sep 22, 2008 at 4:21 PM, Ken Egozi <[EMAIL PROTECTED]> wrote:
>
> >> hmm.
> >> line 327 is:
> >> int currentIndex = (int) Context.Session[wizardName +
> >> "currentstepindex"];
>
> >> so RedirectToNextStep is depending on a session variable
> >> you can setup that session var on your
> >> mocked/stubbed/faked/jizzed/whadever Context instance.
>
> >> btw people. why is this thing in the Session? shouldn't Context.Items be a
> >> better place for it?
>
> >> On Mon, Sep 22, 2008 at 11:09 PM, Kristofer Goss <[EMAIL PROTECTED]>wrote:
>
> >>> Hi Ken, I'm running from trunk build (build 1.1.948). I'm getting:
>
> >>> System.NullReferenceException: Object reference not set to an instance of
> >>> an object.
> >>> at
> >>> Castle.MonoRail.Framework.WizardStepPage.RedirectToNextStep(IDictionary
> >>> queryStringParameters) in WizardStepPage.cs: line 327
> >>> at Castle.MonoRail.Framework.WizardStepPage.RedirectToNextStep() in
> >>> WizardStepPage.cs: line 307
>
> >>> I'm assuming that since the action provider isn't involved within my
> >>> test, it's failing to setup the expected session details used internally.
> >>> Thanks again.
>
> >>> On Mon, Sep 22, 2008 at 2:48 PM, Ken Egozi <[EMAIL PROTECTED]> wrote:
>
> >>>> what's the stack trace on the null-ref that you get?
> >>>> also, are you using trunk?
>
> >>>> On Mon, Sep 22, 2008 at 8:53 PM, Kristofer Goss <[EMAIL PROTECTED]>wrote:
>
> >>>>> Hi, I'm wondering if anyone can recommend some sample code which
> >>>>> demonstrates testing wizard steps? I've read the the following:
>
> >>>>>http://using.castleproject.org/display/MR/TDDing+WizardSteps
>
> >>>>> However, there is little documentation around the sample code and I'm
> >>>>> encountering issues with invoking ProcessNextStep on my wizard step from
> >>>>> within a fixture. It appears that some state in the session (I believe
> >>>>> setup by the WizardActionProvider) is not present, resulting in null
> >>>>> reference exceptions within the MR wizard step.
>
> >>>>> I was hoping to find some additional sample code which might
> >>>>> demonstrate testing wizard pages. Any help/links are greatly
> >>>>> appreciated.
>
> >>>>> Thanks,
>
> >>>>> Kris
>
> >>>> --
> >>>> Ken Egozi.
> >>>>http://www.kenegozi.com/blog
> >>>>http://www.musicglue.com
> >>>>http://www.castleproject.org
> >>>>http://www.gotfriends.co.il
>
> >> --
> >> Ken Egozi.
> >>http://www.kenegozi.com/blog
> >>http://www.musicglue.com
> >>http://www.castleproject.org
> >>http://www.gotfriends.co.il
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---