Is it by design that the first test does not work (saying I need to
use property behavior, which is the second test which works)

Given this it seems it might be the same issue I am seeing in trying
to get this to work, proabbly a misunderstanding on how this is
supposed to work.

        [Test]
        public void NestedInterfaceCallWithExpect()
        {
            MockRepository mocks = new MockRepository();
            var mockService = mocks.Stub<IMyService>();
            var mockIdentity = mocks.Stub<ISomeInterface>();

            With.Mocks(mocks).Expecting(delegate
            {
 
Expect.Call(mockService.Identity).Return(mockIdentity);
                Expect.Call(mockService.Identity.Name).Return("foo");
            }).Verify(delegate
            {
                Assert.AreEqual("foo", mockService.Identity.Name);
            });
        }

        [Test]
        public void NestedInterfaceCall()
        {
            MockRepository mocks = new MockRepository();
            var mockService = mocks.Stub<IMyService>();
            var mockIdentity = mocks.Stub<ISomeInterface>();

            With.Mocks(mocks).Expecting(delegate
            {
                mockService.Identity = mockIdentity;
                mockService.Identity.Name = "foo";
            }).Verify(delegate
            {
                Assert.AreEqual("foo", mockService.Identity.Name);
            });
        }


On Oct 9, 7:33 pm, webpaul <[EMAIL PROTECTED]> wrote:
> Ok, not a big deal. Any tips you can give about the code I posted and
> where I might be going wrong?
>
> On Oct 9, 1:57 am, "Ayende Rahien" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Yes, I do.You need to build from nant the first time you get the code from
> > the repository. See how to build.txt for details
>
> > On Thu, Oct 9, 2008 at 6:01 AM, webpaul <[EMAIL PROTECTED]> wrote:
>
> > > Here is what I have so far, which gives me "This action is invalid
> > > when the mock object is in replay state" which seems to make sense
> > > since I am trying to setup expectation while in the replay state.
> > > Advice?
>
> > > MockRepository.cs
>
> > >        internal object MethodCall(IInvocation invocation, object
> > > proxy, MethodInfo method, object[] args)
> > >        {
> > > ....
> > >            return MethodCallWithDefault(state, invocation, proxy,
> > > method, args);
> > >        }
>
> > >        private object MethodCallWithDefault(IMockState state,
> > > IInvocation invocation, object proxy, MethodInfo method, object[]
> > > args)
> > >        {
> > >            object returnObject = state.MethodCall(invocation, method,
> > > args);
>
> > >            //if returned object is null and it is a property for an
> > > interface, auto mock it
> > >            if (
> > >                returnObject == null &&
> > >                AllowNewObjectForNullInterfaces &&
> > >                method.ReturnType != null &&
> > >                method.ReturnType.IsInterface &&
> > >                method.IsSpecialName &&
> > >                method.Name.StartsWith("get_")
> > >            )
> > >            {
> > >                //create new stub for return object
> > >                returnObject = this.Stub(method.ReturnType);
>
> > >                //setup up mock result for new instance
> > >                state.LastMethodOptions.Return(returnObject);
> > >            }
>
> > >            return returnObject;
> > >         }
>
> > > On Oct 8, 8:39 pm, webpaul <[EMAIL PROTECTED]> wrote:
> > > > Just so we are clear, you expect
> > > > Expect.Call(mockService.Identity.Interface1.Interface2.Interface3.Name
> > > ).Ret­urn("foo")
> > > > to work as well, right?
>
> > > > Also, every time I get source from the rhino trunk I have to go in and
> > > > add the missing assemblyinfo.cs files to all the projects to get it to
> > > > compile. Any good reason for that?
>
> > > > On Oct 8, 1:54 am, "Ayende Rahien" <[EMAIL PROTECTED]> wrote:
>
> > > > > No, you don't need to touch dynamic proxy.The behavior can be
> > > controlled
> > > > > from RecordMockState. Take a look at RhinoIntercepor, as an example of
> > > how
> > > > > we manage things.
> > > > > This is basically making rhino mocks return a mock for an interface
> > > method
> > > > > cal.
>
> > > > > On Wed, Oct 8, 2008 at 6:32 AM, webpaul <[EMAIL PROTECTED]> wrote:
>
> > > > > > Regarding
>
> > >http://ayende.com/Blog/archive/2008/10/08/rhino-mocks-challenge-imple...
> > > > > > :
>
> > > > > > Do you expect that Identity is not null in this test and should have
> > > > > > an implementation? If so, I'm curious whether you expect changes to
> > > > > > Castle.DynamicProxy.ProxyGenerator or not. In the below test
> > > > > > mockService.Identity is null and gives an exception as such. Do you
> > > > > > expect that and want that fixed or am I missing something?
>
> > > > > >    public interface ISomeInterface
> > > > > >    {
> > > > > >        string Name { get; set; }
> > > > > >    }
>
> > > > > >    public interface IMyService
> > > > > >    {
> > > > > >        ISomeInterface Identity { get; set;}
> > > > > >    }
>
> > > > > >    [TestFixture]
> > > > > >        public class FluentMocksTests
> > > > > >        {
> > > > > >                [Test]
> > > > > >                public void CanCallSomeRandomInterfaceProperty()
> > > > > >                {
> > > > > >            var mockService =
> > > > > > MockRepository.GenerateMock<IMyService>();
> > > > > >            Expect.Call(mockService.Identity.Name).Return("foo");
> > > > > >            Assert.AreEqual("foo", mockService.Identity.Name);
> > > > > >                }
> > > > > >        }- Hide quoted text -
>
> > > > > - Show quoted text -- Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino Tools Dev" 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/rhino-tools-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to