I'm wondering why he's struggling with the challenge you proposed if he
doesn't even know RhinoMocks.
On Fri, Oct 10, 2008 at 8:30 AM, Ayende Rahien <[EMAIL PROTECTED]> wrote:
> The main issue that you have is understanding the current behavior, I
> think.Right now, for any method call done in the record stage, Rhino Mocks
> will return null. Expectations and setup return values are ignored until we
> get to the replay phase.
>
>
> On Fri, Oct 10, 2008 at 5:14 AM, webpaul <[EMAIL PROTECTED]> wrote:
>
>>
>> Ok, I think I've gotten somewhere.. The first one passes which makes
>> me think I can get the second one passing. The syntax is slightly
>> different than your initial request but I haven't looked into the
>> reason for that just yet.
>>
>> [Test]
>> public void CanCallPropertyAlternateSyntax()
>> {
>> var mockIdentity =
>> MockRepository.GenerateFluentMock<ISomeInterface>();
>>
>> mockIdentity.Expect(x => x.Name).Return("foo");
>>
>> Assert.AreEqual("foo", mockIdentity.Name);
>> }
>>
>> [Test]
>> public void CanCallSomeRandomInterfaceProperty()
>> {
>> var mockService =
>> MockRepository.GenerateFluentMock<IMyService>();
>>
>> mockService.Expect( x => x.Identity.Name).Return("foo");
>>
>> Assert.AreEqual("foo", mockService.Identity.Name);
>> }
>>
>>
>>
>> On Oct 9, 9:50 pm, webpaul <[EMAIL PROTECTED]> wrote:
>> > So here's another pair of tests, first not working (but I thought it
>> > would) and second not. So I'm guessing this is more than I originally
>> > thought it involved? Sorry for all the noobitude, I just don't have a
>> > strong grasp of exactly what is expected to already work since I don't
>> > use Rhino Mocks in any way except the expect-verify syntax.
>> >
>> > [Test]
>> > public void CanCallProperty()
>> > {
>> > var mockIdentity =
>> > MockRepository.GenerateMock<ISomeInterface>();
>> >
>> > Expect.Call(mockIdentity.Name).Return("foo");
>> > Assert.AreEqual("foo", mockIdentity.Name);
>> > }
>> >
>> > [Test]
>> > public void NormalInterfaceCall()
>> > {
>> > MockRepository mocks = new MockRepository();
>> > var mockIdentity = mocks.DynamicMock<ISomeInterface>();
>> >
>> > With.Mocks(mocks).Expecting(delegate
>> > {
>> > Expect.Call(mockIdentity.Name).Return("foo");
>> > }).Verify(delegate
>> > {
>> > Assert.AreEqual("foo", mockIdentity.Name);
>> > });
>> > }
>> >
>> > On Oct 9, 8:49 pm, webpaul <[EMAIL PROTECTED]> wrote:
>> >
>> >
>> >
>> > > 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 -- 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
-~----------~----~----~----~------~----~------~--~---