Leave it up to the user.  I resolved my own issue.   Instead of using:

controller.Expect(c => c.Context).Return(context);

switch it to

controller.Stub(c => c.Context).Return(context);

and the perceived problem goes away. More reading of the docs for me.
Hope this helps anyone else that may have experienced the same
problem.

Phil

On Oct 7, 6:01 pm, Phil <[EMAIL PROTECTED]> wrote:
> I have determine that the value is cleared after the first access.
> Below is a complete example. In OrderPresenter.OnViewLoaded(), on the
> second query string access, the Controller.Context is null.  I assume
> I have to use some kind of Repeat(), however, I do not care how many
> times the property is accessed.  Suggestions?
>
> using System.Collections.Specialized;
> using System.Web;
> using NUnit.Framework;
> using Rhino.Mocks;
>
> [TestFixture]
> public class OrderPresenterTests
> {
>     [Test]
>     public void Foo()
>     {
>         // Assemble
>         NameValueCollection query = new NameValueCollection { { "id",
> "1" } };
>         HttpRequestBase request =
> MockRepository.GenerateStub<HttpRequestBase>();
>         request.Expect(r => r.QueryString).Return(query);   // setup
> the query string
>
>         HttpContextBase context =
> MockRepository.GenerateStub<HttpContextBase>();
>         context.Expect(c => c.Request).Return(request);     // setup
> the request
>
>         IOrderController controller =
> MockRepository.GenerateStub<IOrderController>();
>         controller.Expect(c => c.Context).Return(context);  // setup
> the context
>
>         OrderPresenter presenter = new OrderPresenter(controller);
>
>         // Act
>         presenter.OnViewLoaded();
>
>         // Assert
>         Assert.IsNotNull(controller);
>         Assert.IsNotNull(controller.Context); // this throws
> AssertionException
>     }
>
> }
>
> public interface IOrderController { HttpContextBase Context { get; } }
>
> public class OrderPresenter
> {
>     private IOrderController Controller { get; set; }
>
>     public OrderPresenter(IOrderController controller)
>     {
>         Controller = controller;
>     }
>
>     public void OnViewLoaded()
>     {
>         string id = Controller.Context.Request.QueryString["id"];
>         string mode = Controller.Context.Request.QueryString["mode"];
>     }
>
> }
>
> On Oct 7, 4:11 pm, Phil <[EMAIL PROTECTED]> wrote:
>
> > Have a odd problem where values are being lost from my mock/stub
> > objects.  I can see the property value is initially set, however after
> > it is passed to a constructor the property is reset to null.  An
> > approximation of the code I am using is shown below.  When I set a
> > break point on the line marked with '** 1 **', I can see the property
> > is set. I can reproduce the situation if I use the 'Make Object ID' in
> > the watch window. Before making the object id, the property has a
> > value. After selecting 'Make Object ID', the property is reset to
> > null.  If I do not use the 'Make Object ID' and step into the
> > constructor, the Context property of the IUserController is set to
> > null as well.  HttpContextBase is from System.Web.Abstractions.dll
> > v3.5.0.0. Both GenerateStub and GenerateMock appear to be behaving the
> > same.
>
> > Am I doing something wrong?
>
> > public interface IUserController { HttpContextBase Context { get; } }
>
> > [Test]
> > public void Test() {
> >     // Arrange
> >     IUserController userController  =
> > MockRepository.GenerateStub<IUserController>();
> >     HttpContextBase httpContextBase =
> > MockRepository.GenerateStub<HttpContextBase>();
>
> >     userController.Expect(uc => uc.Context).Return(httpContextBase);
>
> >     EncounterDetailsPresenter presenter = new
> > EncounterDetailsPresenter(userController); // ** 1 **
>
> >     // Act
> >     presenter.OnViewLoaded();
>
> >     // Assert
>
> > }
>
> > VS.NET Version: Visual Studio 2008 Pro SP1
> > Target Framework: 3.5
> > Rhino-Mocks Version: Rhino-Mocks-net-3.5-v3.5 (3.5.0.1337)
> > ReSharper: 4.1.937.1
> > NUnit: 2.4.6.0
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" 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/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to