Mocked indexers and null values

26 views
Skip to first unread message

Ed freeman

unread,
Jan 19, 2012, 11:06:20 AM1/19/12
to rhino...@googlegroups.com
Hi,

I posted a query onto the Mocks group a couple of days ago. As I'm a new member its gone for moderation, and hasn't emerged. Is there a problem with the thread I posted?

Thanks

Ed.

Ted

unread,
Jan 16, 2012, 8:29:20 AM1/16/12
to Rhino.Mocks
I've found what seems to be a bug. I have a stub on an interface with
an indexer. This test passes, as you'd expect:

public interface IIndexer
{
object this[string name] { get; }
}

[TestFixture]
public class MockTest
{
[Test]
public void ShouldPass()
{
IIndexer item = MockRepository.GenerateStub<IIndexer>();
Assert.IsNull(item[null]);
}
}

If I add a setter to the indexer the call fails, with a
NullReferenceException

public interface IIndexer
{
object this[string name] { get; set; }
}

[TestFixture]
public class MockTest
{
[Test]
public void ShouldFail()
{
IIndexer item = MockRepository.GenerateStub<IIndexer>();
Assert.IsNull(item[null]);
}
}

Now, if instead of passing in null I pass in a string, it passes
again:

public interface IIndexer
{
object this[string name] { get; set; }
}

[TestFixture]
public class MockTest
{
[Test]
public void ShouldPass()
{
IIndexer item = MockRepository.GenerateStub<IIndexer>();
Assert.IsNull(item["name"]);
}
}

Can Ayende or anyone shine any light on this strange behaviour?

Ted.

haifisch

unread,
Feb 1, 2012, 3:21:58 PM2/1/12
to Rhino.Mocks
Hi Ted,

this looks like you've found a bug (a NullReferenceException inside a
framework is always a bug in my eyes ;-)
If tried to fix it - you can get a .Net4 version on
https://github.com/alaendle/rhino-mocks/downloads - or just take a
look at the most recent changeset.

Best regards,

Andreas
Reply all
Reply to author
Forward
0 new messages