My question was  about support of indexer properties by Rhino. In
order to simplify my question I build a demo test.
My real test is much more complicated and I wasn't sure that I'm using
in a right way framework in order to mock the indexer properties.
The understanding how Rhino works with indexer properties helped me to
found other problem in my real test

On Jan 28, 6:01 pm, bill richards <[email protected]>
wrote:
> I also could not help noticing that you are not actually testing
> anything above and beyond the Mocking framework.
>
> Your test reads as follows ...
>
> 1. There is an interface called IInnerIndexer
> 2. There is an interface called IIndexer
> 3. RhinoMocks, create a mock of IIndexer
> 4. RhinoMocks, create a mock of IInnerIndexer
> 5. RhinoMocks, when I call mockedIIndexer["index1"] give me the mocked
> IInnerIndexer
> 5. RhinoMocks, when I call mockedIInnerIndexer["index2"] give me the
> string "indexValue"
> 6. RhinoMocks, here is my call to mockedIIndexer["index1"].
>
> There is no implementation under test here, you are just verifying
> that Rhino Mocks does what you tell it to ... is that your intent?
>
> On Jan 28, 12:40 pm, slavlenty <[email protected]> wrote:
>
>
>
> > I need to clarify something. I got the exception when I run the test
> > with debugger.
> > You are right, without debugger test succeeds.
> > So I added some more complexity to the tested class. Here is the code:
>
> >  public interface IInnerIndexer
> >     {
> >         string this[string index]
> >         {
> >             get;
> >         }
> >     }
> >     public interface IIndexer
> >     {
> >         IInnerIndexer this[string index]
> >         {
> >             get;
> >         }
> >     }
> >     [TestFixture]
> >     public class TestApplication
> >     {
> >         private MockRepository m_Mocks;
> >         [SetUp]
> >         public void Setup()
> >         {
> >             m_Mocks = new MockRepository();
> >         }
> >         [Test]
> >         public void CheckIndexer()
> >         {
> >             IIndexer indexerObj = m_Mocks.StrictMock<IIndexer>();
> >             IInnerIndexer innerIndexerObj =
> > m_Mocks.StrictMock<IInnerIndexer>();
>
> >             using (m_Mocks.Record())
> >             {
> >                 Expect.Call(indexerObj["index1"]).Return
> > (innerIndexerObj);
> >                 Expect.Call(innerIndexerObj["index2"]).Return
> > ("indexValue");
> >             }
> >             using (m_Mocks.Playback())
> >             {
> >                 Console.WriteLine(indexerObj["index1"]);
> >             }
> >         }
> >     }
>
> > I get the following exception with the debugger:
>
> > Previous method 'IInnerIndexer.get_Item("index2");' requires a return
> > value or an exception to throw.
> >         at Rhino.Mocks.Impl.RecordMockState.AssertPreviousMethodIsClose()
> >         at Rhino.Mocks.Impl.RecordMockState.MethodCall(IInvocation
> > invocation, MethodInfo method, Object[] args)
> >         at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation,
> > Object proxy, MethodInfo method, Object[] args)
> >         at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation
> > invocation)
> >         at Castle.DynamicProxy.AbstractInvocation.Proceed()
> >         at 
> > IInnerIndexerProxybdd79bbf3db24cfcb0ede5cd17fdcda2.get_Item(String
> > index)
>
> > And I get the following exception without debugger:
>
> >  Rhino.Mocks.Exceptions.ExpectationViolationException :
> > IInnerIndexer.get_Item("index2"); Expected #1, Actual #0.
>
> > So the question is what's wrong with this code?
>
> > Thanks for your help
> > Slavik
>
> > On Jan 28, 2:31 pm, Tim Barcz <[email protected]> wrote:
>
> > > The code I pasted works. I actually put in compiler and it passes.
>
> > > On Thu, Jan 28, 2010 at 5:48 AM, Tim Barcz <[email protected]> wrote:
> > > > You're missing a return on your expectation.
>
> > > > using (m_Mocks.Record())
> > > > {
> > > >     Expect.Call(indexerObj["index1"]).*Return("hello")*;
> > > > }
>
> > > > using(m_Mocks.Playback())
> > > > {
> > > >     Console.WriteLine(indexerObj["index1"]);
>
> > > > }
>
> > > > On Thu, Jan 28, 2010 at 4:51 AM, slavlenty <[email protected]> wrote:
>
> > > >> I am trying to mock a class with an indexer property
> > > >> Here is the example of the code:
>
> > > >>  public interface IIndexer
> > > >>    {
> > > >>        string this[string index]
> > > >>        {
> > > >>            get;
> > > >>        }
> > > >>    }
> > > >>    [TestFixture]
> > > >>    public class TestApplication
> > > >>    {
> > > >>        private MockRepository m_Mocks;
> > > >>        [SetUp]
> > > >>        public void Setup()
> > > >>        {
> > > >>            m_Mocks = new MockRepository();
> > > >>        }
> > > >>        [Test]
> > > >>        public void CheckIndexer()
> > > >>        {
> > > >>            IIndexer indexerObj = m_Mocks.StrictMock<IIndexer>();
>
> > > >>            using (m_Mocks.Record())
> > > >>            {
> > > >>                Expect.Call(indexerObj["index1"]);
> > > >>            }
> > > >>        }
> > > >>    }
> > > >> There is an exception when I'm calling to  Expect.Call(indexerObj
> > > >> ["index1"]);
> > > >> The exception is the following:
>
> > > >> TestCase 'GSM.DataAccess.MDALAccess.Test.TestApplication.CheckIndexer'
> > > >> failed: System.InvalidOperationException : Previous method
> > > >> 'IIndexer.get_Item("index1");' requires a return value or an exception
> > > >> to throw.
> > > >>        at 
> > > >> Rhino.Mocks.Impl.RecordMockState.AssertPreviousMethodIsClose()
> > > >>        at Rhino.Mocks.Impl.RecordMockState.MethodCall(IInvocation
> > > >> invocation, MethodInfo method, Object[] args)
> > > >>        at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation,
> > > >> Object proxy, MethodInfo method, Object[] args)
> > > >>        at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation
> > > >> invocation)
> > > >>        at Castle.DynamicProxy.AbstractInvocation.Proceed()
> > > >>        at IIndexerProxyc2c7135b1bea490d8bc099fa605d11c4.get_Item(String
> > > >> index)
>
> > > >> How I can mock the call IIndexer.get_Item("index1")?
>
> > > >> Thanks
> > > >> Slavik
>
> > > >> --
> > > >> 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]<rhinomocks%2bunsubscr...@googlegrou
> > > >>  ps.com>
> > > >> .
> > > >> For more options, visit this group at
> > > >>http://groups.google.com/group/rhinomocks?hl=en.
>
> > > > --
> > > > Tim Barcz
> > > > Microsoft C# MVP
> > > > Microsoft ASPInsider
> > > >http://timbarcz.devlicio.us
> > > >http://www.twitter.com/timbarcz
>
> > > --
> > > Tim Barcz
> > > Microsoft C# MVP
> > > Microsoft 
> > > ASPInsiderhttp://timbarcz.devlicio.ushttp://www.twitter.com/timbarcz-Hide 
> > > quoted text -
>
> > - Show quoted text -

-- 
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