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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Faking properties and method calls using Isolate.WhenCalled
I need to fake WebClient instances and DownloadStringCompletedEventArgs instances this is in order to simulate calls to property such as DownloadStringCompletedEventArgs.Error & DownloadStringCompletedEventArgs.Result

var fakeWebClient = Isolate.Fake.Instance<WebClient>();

var fakeDownloadStringCompletedEventArgs = Isolate.Fake.Instance<DownloadStringCompletedEventArgs>();

Isolate.Swap.NextInstance<WebClient>().With(fakeWebClient);

Isolate.Swap.NextInstance<DownloadStringCompletedEventArgs>().With(fakeDownloadStringCompletedEventArgs);

Isolate.WhenCalled(() => fakeDownloadStringCompletedEventArgs.Error).WillReturn(null);

Isolate.WhenCalled(() => fakeDownloadStringCompletedEventArgs.Result).WillReturn("some string response");


But as you might guess or know this won't let the test run already. I guess the reason is because now I am referencing System.Core for silverlight! Do you have any workaround for this?

I posted this issue to http://cthru.codeplex.com/Thread/View.a ... adId=68931
asked by mosessaur (600 points)

1 Answer

0 votes
Unfortunately, any calls to Isolate.WhenCalled are not officially supported.
what (is( supported however is the ability to create fake instances of of unfakeable objects using the silverunit API - FYI - since silverunit is open source, you should be able to add your own API hooks to silverunit to get the "whenCalled" functionality you want, I think.
to see how, looks at the SilverUnit.MakeEventArgs() method in the source.

hope this helps,
Roy
answered by royo (2k points)
...