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%[email protected]>
> .
> 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

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