3

I have simple class

public class Simple
{
    public virtual int VirtualProperty { get; set; }
}

When i run (FakeItEasy.1.13.1)

var strict = A.Fake<Simple>(options => options.Strict());
A.CallTo(() => strict.VirtualProperty).CallsBaseMethod();
strict.VirtualProperty = 999;

I get an error

Call to non configured method "set_VirtualProperty" of strict fake.

And I have to

var strict = A.Fake<Simple>(options => options.Strict());
A.CallTo(strict).Where(a => a.Method.Name == "get_VirtualProperty").CallsBaseMethod();
A.CallTo(strict).Where(a => a.Method.Name == "set_VirtualProperty").CallsBaseMethod();
strict.VirtualProperty = 999;

Does CallBaseMethod () works for virtual property? What am I doing wrong?

dskalski
  • 31
  • 1
  • 1
    I suspect that the behavior is a bug, but am on holiday, away from easy access to the code. Consider raiding an issue on github. Or I will when I'm near technology with bigger screens. In the meantime, I think you workaround is the best answer. – Blair Conrad Sep 16 '13 at 11:57
  • 1
    Of course, I meant to suggest raising an issue, not raiding one. We are not Vikings. – Blair Conrad Sep 18 '13 at 02:33
  • I see you've opened https://github.com/FakeItEasy/FakeItEasy/issues/175. Thanks. – Blair Conrad Sep 27 '13 at 11:19

1 Answers1

1

Update: since 2.0.0 has been released, there's a more convenient way to configure a property setter in some cases.

As more light has been shone on this over at FakeItEasy Issue 175, it's become apparent that the real snag is that A.CallTo(() => strict.VirtualProperty).CallsBaseMethod() configures the property getter, but not the setter. After that configuration, get calls made on strict.VirtualProperty will call the base method (property).

However, there's no convenient way to configure the property setter. The workaround you have is about as good as it gets.

Blair Conrad
  • 233,004
  • 25
  • 132
  • 111