Thanks Mike, that helped me out loads. I'm getting the reference via the EngineContext now.
On Apr 9, 7:08 am, Mike Nichols <[email protected]> wrote: > John > 1. I usually get references to Helpers using this: > EngineContext.CurrentControllerContext.Helpers["Form"] (or something > like that)...this is getting the same instance as found in your > controller and you won't need to contextualize your helper. > 2. I don't use the BaseViewComponentTest for testing components, but I > believe you need to call something like "ContextualizeComponent" to > initialize the EngineContext, ControllerContext, and so on. I find it > easier just providing these manually on my own. > > If you must 'new' a Helper of any kind you should call SetController() > and pass in the controller and controller context. I do this while > testing against helpers. > > mike > > On Apr 8, 7:19 am, "[email protected]" > > <[email protected]> wrote: > > Ok, I've made a little progress. The problem is that the > > ControllerContext is null in the AbstractFormRelatedHelper. > > What I've done is stub the Context.CurrentControllerContext and create > > an empty propertybag within that. The formhelper is now a happy > > bunny. > > > On Apr 8, 11:07 am, "[email protected]" > > > <[email protected]> wrote: > > > Hi Ken, > > > > In answer to your questions. > > > > a. I'm new-ing the helper as I need an instance of it within the > > > ViewComponent. I see that the CaptchaComponent from the Castle Contrib > > > project does the same > > > thing.http://svn.castleproject.org:8080/svn/castlecontrib/viewcomponents/tr.... > > > Am I doing this completely wrong? > > > > b. I don't have a propertybag at all in the test environment as I'm > > > currently try to test a "New" action. Likewise in my Controller I > > > don't have a PropertyBag value for the New action. The strange thing > > > is that the ViewComponent works fine when not in the test environment. > > > > To try and make it a bit clearer what I'm trying to do please look at > > > the viewcomponent > > > >http://membranecms.googlecode.com/svn/trunk/Membrane/ViewComponents/A... > > > > and it's test > > > >http://membranecms.googlecode.com/svn/trunk/Membrane.Tests/Unit/Web/M... > > > > Please be gentle as this is the first time I've tried to TDD a > > > ViewComponent :-) > > > > Thanks > > > > John > > > > On Apr 8, 10:41 am, Ken Egozi <[email protected]> wrote: > > > > > a. why are you new-ing the helper? they are all being created anyway by > > > > the > > > > framework. > > > > b. it appear that the failing call is ObtainRootInstance, with the > > > > target Id > > > > you supply to the TextField method. > > > > is there something in the PropertyBag that corresponds to fieldId in the > > > > test environment? > > > > > On Wed, Apr 8, 2009 at 12:36 PM, [email protected] < > > > > > [email protected]> wrote: > > > > > > I'm currently working on a ViewComponent however I'm struggling the > > > > > testing side of things. > > > > > > The ViewComponent uses the FormHelper within it. > > > > > > formHelper = new FormHelper(EngineContext); > > > > > > and is creating a series of TextFields dynamically > > > > > > formHelper.TextField(fieldId) > > > > > > This works fine when running the view. However when running the test > > > > > which inherits from BaseViewComponentTest I'm getting the following > > > > > error message when the formHelper.TextField(fieldId) code is run. > > > > > > System.NullReferenceException: Object reference not set to an instance > > > > > of an object. > > > > > at > > > > > > Castle.MonoRail.Framework.Helpers.AbstractFormRelatedHelper.ObtainRootInstance > > > > > (RequestContext context, String target) > > > > > at > > > > > > Castle.MonoRail.Framework.Helpers.AbstractFormRelatedHelper.ObtainRootInstance > > > > > (RequestContext context, String target, String[]& pieces) > > > > > at > > > > > Castle.MonoRail.Framework.Helpers.AbstractFormRelatedHelper.ObtainValue > > > > > (RequestContext context, String target) > > > > > at > > > > > Castle.MonoRail.Framework.Helpers.AbstractFormRelatedHelper.ObtainValue > > > > > (String target) > > > > > at > > > > > Castle.MonoRail.Framework.Helpers.AbstractFormRelatedHelper.ObtainValue > > > > > (String target, IDictionary attributes) > > > > > at Castle.MonoRail.Framework.Helpers.FormHelper.TextField(String > > > > > target, IDictionary attributes) > > > > > at Castle.MonoRail.Framework.Helpers.FormHelper.TextField(String > > > > > target) > > > > > > Is there something I'm missing? I've seen this discussion about the > > > > > lack of PropertyBaghttp://markmail.org/message/xremym6hthsudx4obut > > > > > as I said the same code works fine when running the viewcomponent in > > > > > the view. > > > > > > Hope this makes sense > > > > > > John > > > > > -- > > > > Ken > > > > Egozi.http://www.kenegozi.com/bloghttp://www.delver.comhttp://www.musicglue... > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
