I am trying to do something similar to A.CallTo(() => MyProject.Properties.Settings.Default.SomeProperty).Returns("Hello, World! ;-)");
, but I do get…
Non virtual methods can not be intercepted.
… in return.
Any ideas?
I am trying to do something similar to A.CallTo(() => MyProject.Properties.Settings.Default.SomeProperty).Returns("Hello, World! ;-)");
, but I do get…
Non virtual methods can not be intercepted.
… in return.
Any ideas?
FakeItEasy can not be used to override SomeProperty
. The problems is that Default
is a member of type Settings
which is a sealed
class. In order to be able to use A.CallTo
with Default.SomeProperty
, Default
must be a fake object created using A.Fake<…>.
Also, SomeProperty
will need to be virtual or otherwise overridden, as shown in the documentation's What can be faked page.
If you need to be able to provide fake configuration in your tests, you could introduce a layer of abstraction around the configuration and fake that, with your production code using a concrete class that delegates to MyProject.Properties.Settings
…
An alternative (which I think is superior) is to avoid faking/mocking altogether and just change the settings directly, perhaps by doing something like this:
MyProject.Properties.Settings.Default.SomeProperty= "Hello, World! ;-)"
Although as pointed out in the comments, this is only an option if the property has a setter, which it seems that Application properties do not, but User properties do.