This can be done with methods as follows:
myStub.Stub(x => x.SomeMethod()).WhenCalled(x => do something);
Is there any way the same thing can be done when a property setter is called?
The following will work:
Expect.Call(myStub.MyProperty).WhenCalled(p => Console.WriteLine("Called")).Return("Test result");
Please note that this only works if your properties (MyProperty
in this case) is declared virtual.
I don't have Visual Studio handy, but I am sure something along these lines should work:
myStub.Stub(x => x.SomeProperty = null).WhenCalled(x => do something);
Put the mock back into "record" mode and use the old record/playback semantics to set the expectation for the property setter:
stub.BackToRecord();
Expect.Call(stub.SomeProperty).SetPropertyAndIgnoreArgument().WhenCalled(p => ...do something...);
stub.Replay();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With