chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
I've just spent a full day trying to figure out why the following:

[Test]
public void Test()
{
    using (RecordExpectations recorder = new RecordExpectations())
    {
        Foo foo = new Foo();
        recorder.ExpectAndReturn(foo.Bar.Text, "foo"); // <-- error
    }
    Assert.AreEqual("foo", new Foo().Bar.Text);
    MockManager.Verify();
}


Kept giving me a NullReferenceException (on the line marked with "<-- error"). Just to find out that Bar is a public field and NOT a property. :oops:
DON'T LET THIS HAPPEN TO YOU!

- Levi
asked by levi.haskell (600 points)

1 Answer

0 votes
Thanks Levi
This is a good tip.
We really should cater for this, and support mocking fields, but I have a feeling that this will take some time to implement.
answered by scott (32k points)
...