public void GetProfile() { DefaultProfile.ClearDefaultProfile(); DefaultProfile profile = DefaultProfile.GetProfile(); Assert.IsType <DefaultProfile>(profile); string regionId = "cn-hangzhou"; profile = DefaultProfile.GetProfile(regionId); Assert.Equal(regionId, profile.GetRegionId()); string accessKeyId = "accessKeyId"; string accessKeysecret = "accessKeysecret"; profile = DefaultProfile.GetProfile(regionId, accessKeyId, accessKeysecret); Assert.Equal(accessKeyId, profile.GetCredential().AccessKeyId); var mockICredentialProvider = new Mock <ICredentialProvider>(); Exception exception = new Exception(); mockICredentialProvider.Setup(foo => foo.Fresh()).Throws(exception); ICredentialProvider iCredentialProvider = mockICredentialProvider.Object; profile = DefaultProfile.GetProfile(regionId, iCredentialProvider); // 有异常抛出,说明执行了Fresh方法 Assert.Throws <Exception>( () => { profile.GetCredential(); } ); }
public void SetCredentialsProvider() { DefaultProfile.ClearDefaultProfile(); Credential credential; DefaultProfile profile = DefaultProfile.GetProfile(); var mock = new Mock <AlibabaCloudCredentialsProvider>(); AlibabaCloudCredentialsProvider provider = mock.Object; profile.SetCredentialsProvider(provider); // 不为null时,直接回调,即此操作无效 credential = profile.GetCredential(); // 会执行credential初始化 Assert.NotNull(credential); Assert.IsType <CredentialsBackupCompatibilityAdaptor>(credential); profile.SetCredentialsProvider(null); // 会执行credential初始化 credential = profile.GetCredential(); // 不会执行credential初始化 Assert.NotNull(credential); Assert.IsType <CredentialsBackupCompatibilityAdaptor>(credential); }
public void Get() { DefaultProfile.ClearDefaultProfile(); string regionId = "cn-hangzhou"; string accessKeyId = "accessKeyId"; string accessKeysecret = "accessKeysecret"; DefaultProfile profile = DefaultProfile.GetProfile(regionId, accessKeyId, accessKeysecret); Assert.Equal(regionId, profile.GetRegionId()); Assert.Equal(FormatType.XML, profile.GetFormat()); Assert.IsType <Credential>(profile.GetCredential()); }