|
|
|
|
|
by ghubbard
4865 days ago
|
|
Trying to unit test the internet is not a good idea, your life will be easier if you refactor things and simplify a little. public bool StringIsEvenLength(string somestring )
public string FetchRemoteString( string uri )
public bool RemoteStringIsEvenLength(string uri)
{
fetched = FetchRemoteString( uri );
if( fetched != null ) {
return StringIsEvenLength( fetched );
}
throw new SomeOtherException("Didn't get a string to check the length of.");
}
Now StringIsEvenLength is trivial to test.
When you want to test RemoteStringIsEvenLengthYou can mock out FetchRemoteString and don't even have to use a WebClient at all. |
|
The general point still stands though - if there was an interface, we wouldn't have to come up with these workarounds.