in DarabonbaUnitTests/CoreTest.cs [66:138]
public void TestDoAction()
{
Request request = new Request
{
Protocol = "http",
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" }
};
Dictionary<string, object> runtime = new Dictionary<string, object>
{
{ "readTimeout", 7000 },
{ "connectTimeout", 7000 },
// result in failure on .NET framework 45
// { "httpsProxy", "http://www.alibabacloud.com/s/zh?k=ecs" },
{ "ignoreSSL", true }
};
Response response = Core.DoAction(request, runtime);
Assert.NotNull(response);
request.Protocol = "https";
response = Core.DoAction(request);
Assert.NotNull(response);
string bodyStr = Core.GetResponseBody(response);
Assert.NotNull(bodyStr);
request.Method = "POST";
request.Body = new MemoryStream(Encoding.UTF8.GetBytes("test"));
request.Headers["content-test"] = "test";
response = Core.DoAction(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 }
};
Assert.Throws<AggregateException>(() => { Core.DoAction(request404, runtime404); });
Request requestProxy = new Request();
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 = Core.DoAction(requestException, runtimeException);
Assert.NotNull(responseException);
}