我正在开发Windows手机应用程序,其中数据来自网络。我想测试一些方法:
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);
}
}
我知道在某些情况下我应该打印PrintSomeObject()
,我想测试它。但我需要控制请求响应中的数据。是否可能,或者我需要分别测试每种方法?