in DarabonbaUnitTests/CoreTest.cs [141:207]
public async Task TestDoActionAsync()
{
Request request = new Request
{
Protocol = "https",
Method = "GET",
Headers = new Dictionary<string, string>()
};
request.Headers["host"] = "www.alibabacloud.com";
request.Pathname = "/s/zh";
request.Query = new Dictionary<string, string>
{
{ "k", "ecs" }
};
Response response = await Core.DoActionAsync(request);
Assert.NotNull(response);
Dictionary<string, object> runtime = new Dictionary<string, object>
{
{ "readTimeout", 4000 },
{ "connectTimeout", 0 }
};
response = await Core.DoActionAsync(request, runtime);
Assert.NotNull(response);
string bodyStr = Core.GetResponseBody(response);
Assert.NotNull(bodyStr);
request.Method = "POST";
request.Body = new MemoryStream(Encoding.UTF8.GetBytes("test"));
response = await Core.DoActionAsync(request, runtime);
Assert.NotNull(response);
Request request404 = new Request
{
Protocol = "https",
Method = "GET",
Headers = new Dictionary<string, string>()
};
request404.Headers["host"] = "www.alibabacloud404.com";
request404.Pathname = "/s/zh";
request404.Query = new Dictionary<string, string>
{
{ "k", "ecs" }
};
Dictionary<string, object> runtime404 = new Dictionary<string, object>
{
{ "readTimeout", 7000 },
{ "connectTimeout", 7000 }
};
await Assert.ThrowsAsync<HttpRequestException>(async () =>
{
await Core.DoActionAsync(request404, runtime);
});
Request requestException = new Request
{
Protocol = "http",
Method = "GET",
Pathname = "/test"
};
Dictionary<string, object> runtimeException = new Dictionary<string, object>();
requestException.Headers["host"] = "www.aliyun.com";
Response responseException = await Core.DoActionAsync(requestException, runtimeException);
}