public void GetAcsResponseWhenStatusIsNotSuccess() { // 400 Error DefaultAcsClient instance = this.MockDefaultAcsClient(400); // Mock AcsResquest MockAcsRequestForDefaultAcsClient request = new MockAcsRequestForDefaultAcsClient(); request.RegionId = "cn-hangzhou"; request.Product = "Ess"; request.LocationProduct = "ess"; request.LocationEndpointType = "openAPI"; // Mock credentials Credential credentials = new Credential(AKID, AKSE); Action testCode400 = () => { var result = instance.GetAcsResponse <AcsResponse>(request, "cn-hangzhou", credentials); }; var ex = Record.Exception(testCode400); Assert.NotNull(ex); Assert.IsType <ClientException>(ex); Assert.Equal("ThisIsCode : ThisIsMessage", ex.Message); // 502 Error instance = this.MockDefaultAcsClient(502); Action testCode502 = () => { var result = instance.GetAcsResponse <AcsResponse>(request, "cn-hangzhou", credentials); }; ex = Record.Exception(testCode400); Assert.NotNull(ex); Assert.IsType <ServerException>(ex); Assert.Equal("ThisIsCode : ThisIsMessage", ex.Message); }
public void GetAcsResponse1() { DefaultAcsClient instance = this.MockDefaultAcsClient(); // Mock AcsResquest MockAcsRequestForDefaultAcsClient request = new MockAcsRequestForDefaultAcsClient(); request.RegionId = "cn-hangzhou"; request.Product = "Ess"; request.LocationProduct = "ess"; request.LocationEndpointType = "openAPI"; var result = instance.GetAcsResponse <AcsResponse>(request); Assert.IsType <CommonResponse>(result); var mockIClientProfile = new Mock <IClientProfile>(); IClientProfile iClientProfile = mockIClientProfile.Object; result = instance.GetAcsResponse <AcsResponse>(request, iClientProfile); Assert.IsType <CommonResponse>(result); Assert.NotNull(result); }
public void TestSignatureDoesNotMatch() { DefaultAcsClient instance = this.MockDefaultAcsClient(400, "SignatureDoesNotMatch", "signature does not conform to standards. server string to sign is:Error Signature"); MockAcsRequestForDefaultAcsClient request = new MockAcsRequestForDefaultAcsClient(); request.StringToSign = "this is string to sign info"; Credential credentials = new Credential(AKID, AKSE); Exception signatureException = Assert.Throws <ClientException>(() => { var result = instance.GetAcsResponse <AcsResponse>(request, "cn-hangzhou", credentials); }); Assert.Equal("SignatureDoesNotMatch : signature does not conform to standards. server string to sign is:Error Signature", signatureException.Message); instance = this.MockDefaultAcsClient(400, "SignatureDoesNotMatch", "signature does not conform to standards. server string to sign is:this is string to sign info"); Exception invalidException = Assert.Throws <ClientException>(() => { var result = instance.GetAcsResponse <AcsResponse>(request, "cn-hangzhou", credentials); }); Assert.Equal("SDK.InvalidAccessKeySecret : Specified Access Key Secret is not valid.", invalidException.Message); }