Re: [nsubstitute] When.Do for virtual property being set

128 views
Skip to first unread message

David Tchepak

unread,
Dec 20, 2012, 3:51:38 PM12/20/12
to nsubs...@googlegroups.com
You'll need to call the setter when specifying the call within the When block. Something like:

var mySubstitute = Substitute.For<MyClass>();
mySubstitute.When(x  => x.VirtualProperty = Arg.Any<Foo>()).Do(x => DoSomething());
mySubstitute.VirtualProperty = aValue;

Regards,
David


On Fri, Dec 21, 2012 at 6:58 AM, Richard Garside <richard...@richardsprojects.co.uk> wrote:
I'd like to call some code when a virtual property is set on the class I've substituted. Something like this:

var mySubstitute = Substitute.For<MyClass>();

// This line doesn't work, but was my best guess
mySubstitute.When(x  => x.VirtualProperty).Do(x => DoSomething());

mySubstitute.VirtualProperty = aValue; // DoSomething should also get called


Can this be done, and if it can, how?

--
You received this message because you are subscribed to the Google Groups "NSubstitute" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nsubstitute/-/cQYxKBwaDuUJ.
To post to this group, send email to nsubs...@googlegroups.com.
To unsubscribe from this group, send email to nsubstitute...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nsubstitute?hl=en.

Richard Garside

unread,
Dec 21, 2012, 6:06:30 AM12/21/12
to nsubs...@googlegroups.com
That's brilliant. Thanks.
Reply all
Reply to author
Forward
0 new messages