I am trying to test some async methods involving the HttpClient work with vs 2012 express for win 8 and it’s test framework. No matter how I try I always get the same exception.
For example this test code:
[TestMethod]
public async Task Connect()
{
HttpClient client = new HttpClient();
string reply = await client.GetStringAsync("http://google.com");
Assert.AreNotEqual(0, reply.Length);
}
Which should probably work considering this: http://www.richard-banks.org/2012/03/how-to-unit-test-async-methods-with.html
Throws
System.Net.WebException: The remote name could not be resolved: 'google.com'
The same code works just fine when called from an actual program (not a test case).
Any help is appreciated.
Please refer to my comments and I can include this as an answer to your question.
“Are you are using the metro style Unit Testing template? If yes you need to enable the Internet Client (I think) in the app manifest file -> capabilities to allow this behaviour?. Also since you are testing an external call, this is not a Unit Test. It is more of an integration test.“
I have used exactly the same code you have and I get exactly the same error. As I said if you just tick the the Package.appxmanifest -> Capabilities – > Internet (Client) check box, you test should pass.