I am developing windows phone application, where data comes from web. I would like to test some method:
public void PrintSomeObject()
{
var apiInstance = new Api();
apiInstance.GetSomeObject("bar",
(res) =>
{
Debug.WriteLine(res.data);
});
}
public class Api
{
public GetSomeObject(string path, Action<SomeObject> callback,)
{
HTTPRequest("http://foo.com/" + path,
(resultStr) =>
{
SomeObject t = ParseSomeObject(resultStr);
callback(t);
});
}
void async void HTTPRequest(string baseUri, Action<string> resultCallback)
{
var result = await httpClient.PostAsync(new Uri(baseUri, UriKind.Absolute), content);
var resultStr = await result.Content.ReadAsStringAsync();
// var resultStr = "{data: 'some fake data', number: 42}" // I want insert fake data here
resultCallback(resultStr);
}
}
I know want PrintSomeObject() should print in some cases, and I'd like to test it. But I need to control data which I get in request response. Is it possible, or I need test each method separatly?
Aucun commentaire:
Enregistrer un commentaire