Skip to content

Commit

Permalink
fix: dara to darabonba
Browse files Browse the repository at this point in the history
  • Loading branch information
PanPanZou committed Aug 13, 2024
1 parent 8d99850 commit 8e25a7e
Show file tree
Hide file tree
Showing 85 changed files with 606 additions and 439 deletions.
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

Binary file removed Dara/.DS_Store
Binary file not shown.
21 changes: 0 additions & 21 deletions Dara/Exceptions/DaraUnretryableException.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Dara/Exceptions/RespException.cs

This file was deleted.

40 changes: 0 additions & 40 deletions Dara/Utils/ListUtil.cs

This file was deleted.

57 changes: 0 additions & 57 deletions Dara/Utils/StringUtil.cs

This file was deleted.

Binary file removed DaraUnitTests/.DS_Store
Binary file not shown.
116 changes: 71 additions & 45 deletions DaraUnitTests/DaraCoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Dara;
using Dara.RetryPolicy;
using Dara.Exceptions;
using Darabonba;
using Darabonba.RetryPolicy;
using Darabonba.Exceptions;
using Xunit;

namespace DaraUnitTests
Expand Down Expand Up @@ -63,19 +63,25 @@ public void TestComposeUrl()
[Fact]
public void TestDoAction()
{
DaraRequest daraRequest = new DaraRequest();
daraRequest.Protocol = "http";
daraRequest.Method = "GET";
daraRequest.Headers = new Dictionary<string, string>();
DaraRequest daraRequest = new DaraRequest
{
Protocol = "http",
Method = "GET",
Headers = new Dictionary<string, string>()
};
daraRequest.Headers["host"] = "www.alibabacloud.com";
daraRequest.Pathname = "/s/zh";
daraRequest.Query = new Dictionary<string, string>();
daraRequest.Query.Add("k", "ecs");
Dictionary<string, object> runtime = new Dictionary<string, object>();
runtime.Add("readTimeout", 7000);
runtime.Add("connectTimeout", 7000);
runtime.Add("httpsProxy", "http://www.alibabacloud.com/s/zh?k=ecs");
runtime.Add("ignoreSSL", true);
daraRequest.Query = new Dictionary<string, string>
{
{ "k", "ecs" }
};
Dictionary<string, object> runtime = new Dictionary<string, object>
{
{ "readTimeout", 7000 },
{ "connectTimeout", 7000 },
{ "httpsProxy", "http://www.alibabacloud.com/s/zh?k=ecs" },
{ "ignoreSSL", true }
};

DaraResponse daraResponse = DaraCore.DoAction(daraRequest, runtime);
Assert.NotNull(daraResponse);
Expand All @@ -94,17 +100,23 @@ public void TestDoAction()
daraResponse = DaraCore.DoAction(daraRequest, runtime);
Assert.NotNull(daraResponse);

DaraRequest daraRequest404 = new DaraRequest();
daraRequest404.Protocol = "https";
daraRequest404.Method = "GET";
daraRequest404.Headers = new Dictionary<string, string>();
DaraRequest daraRequest404 = new DaraRequest
{
Protocol = "https",
Method = "GET",
Headers = new Dictionary<string, string>()
};
daraRequest404.Headers["host"] = "www.alibabacloud404.com";
daraRequest404.Pathname = "/s/zh";
daraRequest404.Query = new Dictionary<string, string>();
daraRequest404.Query.Add("k", "ecs");
Dictionary<string, object> runtime404 = new Dictionary<string, object>();
runtime404.Add("readTimeout", 7000);
runtime404.Add("connectTimeout", 7000);
daraRequest404.Query = new Dictionary<string, string>
{
{ "k", "ecs" }
};
Dictionary<string, object> runtime404 = new Dictionary<string, object>
{
{ "readTimeout", 7000 },
{ "connectTimeout", 7000 }
};
Assert.Throws<AggregateException>(() => { DaraCore.DoAction(daraRequest404, runtime404); });

DaraRequest daraRequestProxy = new DaraRequest();
Expand All @@ -125,21 +137,27 @@ public void TestDoAction()
[Fact]
public async Task TestDoActionAsync()
{
DaraRequest daraRequest = new DaraRequest();
daraRequest.Protocol = "https";
daraRequest.Method = "GET";
daraRequest.Headers = new Dictionary<string, string>();
DaraRequest daraRequest = new DaraRequest
{
Protocol = "https",
Method = "GET",
Headers = new Dictionary<string, string>()
};
daraRequest.Headers["host"] = "www.alibabacloud.com";
daraRequest.Pathname = "/s/zh";
daraRequest.Query = new Dictionary<string, string>();
daraRequest.Query.Add("k", "ecs");
daraRequest.Query = new Dictionary<string, string>
{
{ "k", "ecs" }
};

DaraResponse daraResponse = await DaraCore.DoActionAsync(daraRequest);
Assert.NotNull(daraResponse);

Dictionary<string, object> runtime = new Dictionary<string, object>();
runtime.Add("readTimeout", 4000);
runtime.Add("connectTimeout", 0);
Dictionary<string, object> runtime = new Dictionary<string, object>
{
{ "readTimeout", 4000 },
{ "connectTimeout", 0 }
};

daraResponse = await DaraCore.DoActionAsync(daraRequest, runtime);
Assert.NotNull(daraResponse);
Expand All @@ -152,17 +170,23 @@ public async Task TestDoActionAsync()
daraResponse = await DaraCore.DoActionAsync(daraRequest, runtime);
Assert.NotNull(daraResponse);

DaraRequest daraRequest404 = new DaraRequest();
daraRequest404.Protocol = "https";
daraRequest404.Method = "GET";
daraRequest404.Headers = new Dictionary<string, string>();
DaraRequest daraRequest404 = new DaraRequest
{
Protocol = "https",
Method = "GET",
Headers = new Dictionary<string, string>()
};
daraRequest404.Headers["host"] = "www.alibabacloud404.com";
daraRequest404.Pathname = "/s/zh";
daraRequest404.Query = new Dictionary<string, string>();
daraRequest404.Query.Add("k", "ecs");
Dictionary<string, object> runtime404 = new Dictionary<string, object>();
runtime404.Add("readTimeout", 7000);
runtime404.Add("connectTimeout", 7000);
daraRequest404.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 DaraCore.DoActionAsync(daraRequest404, runtime); });

DaraRequest requestException = new DaraRequest
Expand All @@ -179,8 +203,10 @@ public async Task TestDoActionAsync()
[Fact]
public void TestConvertHeaders()
{
WebHeaderCollection headers = new WebHeaderCollection();
headers.Add("testKey", "testValue");
WebHeaderCollection headers = new WebHeaderCollection
{
{ "testKey", "testValue" }
};
Dictionary<string, string> dic = DaraCore.ConvertHeaders(headers);
Assert.NotNull(dic);
Assert.True(dic.ContainsKey("testkey"));
Expand All @@ -190,7 +216,7 @@ public void TestConvertHeaders()
[Fact]
public void TestAllowRetry()
{
long _now = System.DateTime.Now.Millisecond;
long _now = DateTime.Now.Millisecond;

Assert.True(DaraCore.AllowRetry(null, 0, _now));

Expand Down Expand Up @@ -672,7 +698,7 @@ public void TestGetBackoffDelay()
}


public class ThrottlingException : RespException
public class ThrottlingException : ResponseException
{
public ThrottlingException() : base()
{
Expand Down
15 changes: 10 additions & 5 deletions DaraUnitTests/DaraDateTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Globalization;
using Dara;
using Darabonba;
using Xunit;
using System;

Expand All @@ -10,11 +9,17 @@ public class DaraDateTest
DaraDate dateLocal = new DaraDate("2023-12-31 00:00:00.916000");
DaraDate dateUTC = new DaraDate("2023-12-31 00:00:00.916000 +0000");

[Fact]
public void Test_TimestampStr()
{
DaraDate date = new DaraDate("1723081751");
Assert.Equal("2024-08-08 01:49:11.000000 +0000 UTC", date.Date.ToString("yyyy-MM-dd HH:mm:ss.ffffff '+0000 UTC'"));
}

[Fact]
public void Test_Init_NoTimeZone()
{
DateTime expectedDate = DateTime.SpecifyKind(DateTime.Parse("2023-12-31 00:00:00.916000"), DateTimeKind.Local).ToUniversalTime();
Assert.Equal(expectedDate, dateLocal.Date);
Assert.Equal("2023-12-31 00:00:00.916000", dateLocal.Date.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss.ffffff"));
}

[Fact]
Expand Down Expand Up @@ -43,7 +48,7 @@ public void Test_Unix()
public void Test_UTC()
{
Assert.Equal("2023-12-31 00:00:00.916000 +0000 UTC", dateUTC.UTC());
// Local时间,但非北京时间
// Local time
Assert.Equal("2023-12-31 00:00:00.916000 +0000 UTC", dateLocal.UTC());
}

Expand Down
2 changes: 1 addition & 1 deletion DaraUnitTests/DaraFileTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text;
using Dara;
using Darabonba;
using Xunit;
using System;
using System.IO;
Expand Down
2 changes: 1 addition & 1 deletion DaraUnitTests/DaraModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Dara;
using Darabonba;
using DaraUnitTests.Models;

using Xunit;
Expand Down
2 changes: 1 addition & 1 deletion DaraUnitTests/DaraRequestTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dara;
using Darabonba;

using Xunit;

Expand Down
Loading

0 comments on commit 8e25a7e

Please sign in to comment.