Faking properties and method calls using Isolate.WhenCalled

Sep 15, 2009 at 2:42 AM
Edited Sep 15, 2009 at 2:45 AM

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?

Developer
Sep 15, 2009 at 12:57 PM

mosessaur,

Why not post this question to the TypeMock forums?

ulu

Sep 15, 2009 at 1:14 PM

Yes Sure I will. Just thought it is related to CThru & SilverUnit! that is why I posted here. Will post it on TypeMock forum now.