Esempio n. 1
0
        public void GetEndpoint()
        {
            var mockAcsRequest = new MockAcsRequest();

            Assert.Equal("", mockAcsRequest.GetProductEndpoint());

            var endpointMap = new Dictionary <string, string>();

            endpointMap.Add("cn-hangzhou", "test.cn-hangzhou.aliyuncs.com");

            mockAcsRequest.ProductEndpointMap  = endpointMap;
            mockAcsRequest.ProductEndpointType = "regional";

            mockAcsRequest.RegionId = "cn-hangzhou";
            Assert.Equal("test.cn-hangzhou.aliyuncs.com", mockAcsRequest.GetProductEndpoint());

            mockAcsRequest.Product  = "Test";
            mockAcsRequest.RegionId = "cn-beijing";
            Assert.Equal("test.cn-beijing.aliyuncs.com", mockAcsRequest.GetProductEndpoint());

            mockAcsRequest.ProductEndpointType = "central";
            Assert.Equal("test.aliyuncs.com", mockAcsRequest.GetProductEndpoint());

            mockAcsRequest.ProductNetwork = "vpc";
            Assert.Equal("test-vpc.aliyuncs.com", mockAcsRequest.GetProductEndpoint());

            var productEndpointMap = new Dictionary <string, string>();

            mockAcsRequest.ProductEndpointType = "test-type";
            mockAcsRequest.ProductEndpointMap  = productEndpointMap;

            Assert.Empty(mockAcsRequest.GetProductEndpoint());
        }
Esempio n. 2
0
        public void CheckShowJsonItemName()
        {
            var mockAcsRequest = new MockAcsRequest();

            // CheckShowJsonItemName return true
            Assert.True(mockAcsRequest.CheckShowJsonItemName());
        }
Esempio n. 3
0
        public void ConcatQueryString()
        {
            var mockAcsRequest = new MockAcsRequest();

            Dictionary <string, string> tmpDic = null;

            // When parameters is null
            var result = MockAcsRequest.ConcatQueryString(tmpDic);

            Assert.Null(result);

            // when parameters is empty
            tmpDic = new Dictionary <string, string>();
            result = MockAcsRequest.ConcatQueryString(tmpDic);

            // Get the empty not null
            Assert.NotNull(result);
            Assert.Empty(result);

            // When parammters is not null
            tmpDic = new Dictionary <string, string> {
                { "foo", "bar" }, { "a", "A" }, { "n", null }
            };
            result = MockAcsRequest.ConcatQueryString(tmpDic);
            Assert.Equal("foo=bar&a=A&n", result);
        }
Esempio n. 4
0
        public void CheckShowJsonItemName()
        {
            var mockAcsRequest = new MockAcsRequest();

            // CheckShowJsonItemName 方法会回调true,且无其它逻辑
            Assert.True(mockAcsRequest.CheckShowJsonItemName());
        }
Esempio n. 5
0
        public void Instance()
        {
            var mockAcsRequest = new MockAcsRequest();

            Assert.IsType <MockAcsRequest>(mockAcsRequest);

            mockAcsRequest.AcceptFormat = FormatType.XML;
            Assert.Equal(FormatType.XML, mockAcsRequest.AcceptFormat);
            Assert.Equal(ProtocolType.HTTP, mockAcsRequest.Protocol);
        }
Esempio n. 6
0
        public void SetEndpoint()
        {
            var endpoint = "ecs.cn-hangzhou.aliyuncs.com";

            var mockAcsRequest = new MockAcsRequest();

            mockAcsRequest.SetEndpoint(endpoint);

            Assert.Equal(endpoint, mockAcsRequest.ProductDomain.DomainName);

            mockAcsRequest.ProductDomain = null;
        }
Esempio n. 7
0
        public void UserAgentConfigTest()
        {
            var mockAcsRequest = new MockAcsRequest();

            mockAcsRequest.AppendUserAgent("test", "1.2.3");
            mockAcsRequest.AppendUserAgent("test", "1.2.4");
            mockAcsRequest.AppendUserAgent("mock", "1.1.2");

            var userAgent = UserAgent.Resolve(mockAcsRequest.GetSysUserAgentConfig(), null);
            var resultStr = UserAgent.GetDefaultMessage() + " test/1.2.4" + " mock/1.1.2";

            Assert.Equal(resultStr, userAgent);
        }
Esempio n. 8
0
        public void Parameters()
        {
            var mockAcsRequest = new MockAcsRequest();

            var tmpDic = new Dictionary <string, string> {
                { "foo", "bar" }
            };

            mockAcsRequest.QueryParameters = tmpDic;

            mockAcsRequest.DomainParameters = tmpDic;
            Assert.Equal(tmpDic, mockAcsRequest.DomainParameters);

            mockAcsRequest.BodyParameters = tmpDic;
            Assert.Equal(tmpDic, mockAcsRequest.BodyParameters);
        }
Esempio n. 9
0
        public void SignRequest()
        {
            var tmpDic = new Dictionary <string, string> {
                { "foo", "bar" }, { "a", "A" }, { "n", null }
            };

            var mockAcsRequest = new MockAcsRequest("https://www.alibabacloud.com/");
            var signer         = new HmacSHA1Signer();
            var credential     = new Credential("accessKeyId", "accessKeySecret", "securityToken");
            var domain         = new ProductDomain();

            MockAcsRequest.ConcatQueryString(tmpDic);

            var request = mockAcsRequest.SignRequest(signer, credential, FormatType.JSON, domain);

            Assert.Equal("Instance by MockAcsRequest", request.Url);
        }
Esempio n. 10
0
        public void validateParam()
        {
            var acsRequest = new MockAcsRequest();

            Assert.Throws <ArgumentException>(() =>
            {
                acsRequest.RegionId = "a.b";
            });

            acsRequest.RegionId = "";
            Assert.Empty(acsRequest.RegionId);

            acsRequest.RegionId = null;
            Assert.Null(acsRequest.RegionId);
            Assert.Throws <ArgumentException>(() =>
            {
                acsRequest.ProductNetwork = "a.b";
            });

            acsRequest.ProductNetwork = "private";
            Assert.Equal("private", acsRequest.ProductNetwork);

            acsRequest.ProductNetwork = "";
            Assert.Empty(acsRequest.ProductNetwork);

            acsRequest.ProductNetwork = null;
            Assert.Null(acsRequest.ProductNetwork);

            Assert.Throws <ArgumentException>(() =>
            {
                acsRequest.ProductSuffix = "a.b";
            });

            acsRequest.ProductSuffix = "";
            Assert.Empty(acsRequest.ProductSuffix);

            acsRequest.ProductSuffix = null;
            Assert.Null(acsRequest.ProductSuffix);
        }