Skip to content

Commit 31fa47a

Browse files
authored
CORE SDK Auto Released By yinxi (#261)
* CORE SDK Auto Released By yinxi 发布日志: 1, code clean up to fit in with .net coding convention * Replace region id and product from ecs to vpc as instability * Remove unuse chinese comment and replace chinese comment with english
1 parent 9822be2 commit 31fa47a

File tree

149 files changed

+5445
-3853
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+5445
-3853
lines changed

README-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class Program
127127
// 发起请求,并得到 Response
128128
var response = client.GetAcsResponse(request);
129129

130-
//Do something as you want below
130+
// Do something as you want below
131131
}
132132
catch (ServerException ex)
133133
{

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Program
122122
// Initiate the request and get the response
123123
var response = client.GetAcsResponse(request);
124124

125-
//Do something as you want below
125+
// Do something as you want below
126126
}
127127
catch (ServerException ex)
128128
{

aliyun-net-sdk-core.Tests/Mock/ACKMock.cs

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
using System;
221

322
namespace Aliyun.Acs.Core.Tests.Mock
@@ -21,7 +40,9 @@ public static string GetRoleName(bool mock = false, string mockData = "RoleName"
2140

2241
private static string GetEnv(string envName, string mockData)
2342
{
24-
return Environment.GetEnvironmentVariable(envName) == null ? mockData : Environment.GetEnvironmentVariable(envName);
43+
return Environment.GetEnvironmentVariable(envName) == null
44+
? mockData
45+
: Environment.GetEnvironmentVariable(envName);
2546
}
2647
}
2748
}

aliyun-net-sdk-core.Tests/Mock/DateTimeMock.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
using System;
221

322
namespace Aliyun.Acs.Core.Tests.Mock
423
{
524
public class DateTimeMock
625
{
7-
826
public static DateTime getDateTimeNow()
927
{
1028
return DateTime.Now;

aliyun-net-sdk-core.Tests/Units/AcsRequest.cs

+62-42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
using System;
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
220
using System.Collections.Generic;
321

422
using Aliyun.Acs.Core.Auth;
@@ -12,6 +30,39 @@ namespace Aliyun.Acs.Core.Tests.Units
1230
{
1331
public class AcsRequestTest
1432
{
33+
[Fact]
34+
public void CheckShowJsonItemName()
35+
{
36+
var mockAcsRequest = new MockAcsRequest();
37+
// CheckShowJsonItemName return true
38+
Assert.True(mockAcsRequest.CheckShowJsonItemName());
39+
}
40+
41+
[Fact]
42+
public void ConcatQueryString()
43+
{
44+
var mockAcsRequest = new MockAcsRequest();
45+
46+
Dictionary<string, string> tmpDic = null;
47+
48+
// When parameters is null
49+
var result = MockAcsRequest.ConcatQueryString(tmpDic);
50+
Assert.Null(result);
51+
52+
// when parameters is empty
53+
tmpDic = new Dictionary<string, string>();
54+
result = MockAcsRequest.ConcatQueryString(tmpDic);
55+
56+
// Get the empty not null
57+
Assert.NotNull(result);
58+
Assert.Empty(result);
59+
60+
// When parammters is not null
61+
tmpDic = new Dictionary<string, string> {{"foo", "bar"}, {"a", "A"}, {"n", null}};
62+
result = MockAcsRequest.ConcatQueryString(tmpDic);
63+
Assert.Equal("foo=bar&a=A&n", result);
64+
}
65+
1566
[Fact]
1667
public void Instance()
1768
{
@@ -28,7 +79,7 @@ public void Parameters()
2879
{
2980
var mockAcsRequest = new MockAcsRequest();
3081

31-
Dictionary<String, String> tmpDic = new Dictionary<String, String> { { "foo", "bar" } };
82+
var tmpDic = new Dictionary<string, string> {{"foo", "bar"}};
3283
mockAcsRequest.QueryParameters = tmpDic;
3384

3485
mockAcsRequest.DomainParameters = tmpDic;
@@ -38,53 +89,22 @@ public void Parameters()
3889
Assert.Equal(tmpDic, mockAcsRequest.BodyParameters);
3990
}
4091

41-
[Fact]
42-
public void ConcatQueryString()
43-
{
44-
var mockAcsRequest = new MockAcsRequest();
45-
46-
Dictionary<String, String> tmpDic = null;
47-
48-
// When parameters is null
49-
var result = MockAcsRequest.ConcatQueryString(tmpDic);
50-
Assert.Null(result);
51-
52-
// when parameters is empty
53-
tmpDic = new Dictionary<String, String> { };
54-
result = MockAcsRequest.ConcatQueryString(tmpDic);
55-
Assert.NotNull(result); // 非null 但是为空
56-
Assert.Empty(result);
57-
58-
// When parammters is not null
59-
tmpDic = new Dictionary<String, String> { { "foo", "bar" }, { "a", "A" }, { "n", null } };
60-
result = MockAcsRequest.ConcatQueryString(tmpDic);
61-
Assert.Equal("foo=bar&a=A&n", result);
62-
}
63-
6492
[Fact]
6593
public void SignRequest()
6694
{
67-
Dictionary<String, String> tmpDic = new Dictionary<String, String> { { "foo", "bar" }, { "a", "A" }, { "n", null } };
95+
var tmpDic = new Dictionary<string, string> {{"foo", "bar"}, {"a", "A"}, {"n", null}};
6896

6997
var mockAcsRequest = new MockAcsRequest("https://www.alibabacloud.com/");
70-
HmacSHA1Signer signer = new HmacSHA1Signer();
71-
Credential credential = new Credential("accessKeyId", "accessKeySecret", "securityToken");
72-
ProductDomain domain = new ProductDomain();
98+
var signer = new HmacSHA1Signer();
99+
var credential = new Credential("accessKeyId", "accessKeySecret", "securityToken");
100+
var domain = new ProductDomain();
73101
MockAcsRequest.ConcatQueryString(tmpDic);
74102

75-
HttpRequest request = mockAcsRequest.SignRequest(signer, credential, FormatType.JSON, domain);
103+
var request = mockAcsRequest.SignRequest(signer, credential, FormatType.JSON, domain);
76104

77105
Assert.Equal("Instance by MockAcsRequest", request.Url);
78106
}
79107

80-
[Fact]
81-
public void CheckShowJsonItemName()
82-
{
83-
var mockAcsRequest = new MockAcsRequest();
84-
// CheckShowJsonItemName 方法会回调true,且无其它逻辑
85-
Assert.True(mockAcsRequest.CheckShowJsonItemName());
86-
}
87-
88108
[Fact]
89109
public void UserAgentConfigTest()
90110
{
@@ -104,24 +124,24 @@ public sealed class MockAcsRequest : AcsRequest<CommonRequest>
104124
{
105125
public MockAcsRequest(string urlStr = null) : base(urlStr)
106126
{
107-
108127
}
128+
109129
public override HttpRequest SignRequest(Signer signer, AlibabaCloudCredentials credentials,
110130
FormatType? format, ProductDomain domain)
111131
{
112-
HttpRequest httpRequest = new HttpRequest();
132+
var httpRequest = new HttpRequest();
113133
httpRequest.Url = "Instance by MockAcsRequest";
114134
return httpRequest;
115135
}
116136

117-
public override String ComposeUrl(String endpoint, Dictionary<String, String> queries)
137+
public override string ComposeUrl(string endpoint, Dictionary<string, string> queries)
118138
{
119139
return "";
120140
}
121141

122142
public override CommonRequest GetResponse(UnmarshallerContext unmarshallerContext)
123143
{
124-
CommonRequest t = new CommonRequest();
144+
var t = new CommonRequest();
125145
return t;
126146
}
127147
}

aliyun-net-sdk-core.Tests/Units/Auth/AcsURLEncoder.cs

+28-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
using System.Text;
1+
using System.Text;
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
221
using System.Web;
322

423
using Aliyun.Acs.Core.Auth;
@@ -12,16 +31,20 @@ public class AcsUrlEncoderTest
1231
[Fact]
1332
public void Encode()
1433
{
15-
string source = " ♂:@#¥%&*(";
16-
string encode = HttpUtility.UrlDecode(AcsURLEncoder.Encode(" ♂:@#¥%&*("), Encoding.UTF8);
34+
var source = " ♂:@#¥%&*(";
35+
var encode = HttpUtility.UrlDecode(AcsURLEncoder.Encode(" ♂:@#¥%&*("), Encoding.UTF8);
1736
Assert.Equal(encode, source);
1837
}
1938

2039
[Fact]
2140
public void PercentEncode()
2241
{
23-
string result = AcsURLEncoder.PercentEncode("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~!@#$%^&*()");
24-
Assert.Equal("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~%21%40%23%24%25%5E%26%2A%28%29", result);
42+
var result =
43+
AcsURLEncoder.PercentEncode(
44+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~!@#$%^&*()");
45+
Assert.Equal(
46+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~%21%40%23%24%25%5E%26%2A%28%29",
47+
result);
2548
}
2649
}
2750
}

aliyun-net-sdk-core.Tests/Units/Auth/BasicCredentials.cs

+27-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
using System;
221

322
using Aliyun.Acs.Core.Auth;
@@ -11,17 +30,10 @@ public class BasicCredentialsTest
1130
[Fact]
1231
public void GetAccessKeyId()
1332
{
14-
BasicCredentials basicCredentials = new BasicCredentials("foo", "bar");
33+
var basicCredentials = new BasicCredentials("foo", "bar");
1534
Assert.Equal("foo", basicCredentials.GetAccessKeyId());
1635
}
1736

18-
[Fact]
19-
public void GetAccessKeySecret()
20-
{
21-
BasicCredentials basicCredentials = new BasicCredentials("foo", "bar");
22-
Assert.Equal("bar", basicCredentials.GetAccessKeySecret());
23-
}
24-
2537
[Fact]
2638
public void GetAccessKeyIdException()
2739
{
@@ -33,6 +45,13 @@ public void GetAccessKeyIdException()
3345
Assert.Equal("Access key ID cannot be null.", exception.ParamName);
3446
}
3547

48+
[Fact]
49+
public void GetAccessKeySecret()
50+
{
51+
var basicCredentials = new BasicCredentials("foo", "bar");
52+
Assert.Equal("bar", basicCredentials.GetAccessKeySecret());
53+
}
54+
3655
[Fact]
3756
public void GetAccessKeySecretException()
3857
{

0 commit comments

Comments
 (0)