Today I start implementing unit tests for my WP 8.1 Silvelight app, and on start I found a problem.
I have async static
method wchich has try
/ catch
block and here it is.
Some code before explanation: Method to test (not 100% real code but have same logic):
async public static Task<string> MyMethodAsync(string param, string param2)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://url.pl");
request.Method = "GET";
string result = string.Empty;
try
{
response = await request.GetResponseAsync();
}
catch(Exception e)
{
result = "error";
return result;
}
result = "Expected result value";
return result;
}
And now I want test it in unit tests:
[TestMethod]
public void TestMethod()
{
string result = StaticClass.MyMethodAsync("param1", "param2").Result;
Assert.IsTrue(result == "Expected result value");
}
Problem is that test method hangs or return fail everytime, even if in app method returns expected values every single time.
It seems to "catch" internal exception before try / catch
in MyMethodAsync
and raise fail event.
Do you have any idea what's wrong?
Aucun commentaire:
Enregistrer un commentaire