@@ -50,6 +50,14 @@ public override void SetTokenCacheForProfile(IAzureContextContainer profile)
50
50
51
51
class TestContextContainer : IAzureContextContainer
52
52
{
53
+ List < IAzureEnvironment > _environments = new List < IAzureEnvironment > ( ) ;
54
+ public TestContextContainer ( )
55
+ {
56
+ foreach ( var environment in AzureEnvironment . PublicEnvironments )
57
+ {
58
+ _environments . Add ( environment . Value ) ;
59
+ }
60
+ }
53
61
public IEnumerable < IAzureAccount > Accounts
54
62
{
55
63
get ;
@@ -62,8 +70,8 @@ public IAzureContext DefaultContext
62
70
63
71
public IEnumerable < IAzureEnvironment > Environments
64
72
{
65
- get ;
66
- } = new List < IAzureEnvironment > ( ) ;
73
+ get { return _environments ; }
74
+ }
67
75
68
76
public IDictionary < string , string > ExtendedProperties
69
77
{
@@ -111,35 +119,46 @@ public void CanCreateStorageContextNameAndKey()
111
119
Assert . NotNull ( storageContext ) ;
112
120
Assert . Equal ( cmdlet . StorageAccountName , storageContext . StorageAccountName ) ;
113
121
114
- cmdlet = new NewAzureStorageContext
115
- {
116
- CommandRuntime = mock ,
117
- StorageAccountName = "contosostorage" ,
118
- Anonymous = true ,
119
- } ;
122
+ }
123
+ finally
124
+ {
125
+ AzureSMProfileProvider . SetInstance ( ( ) => smProvider , true ) ;
126
+ AzureRmProfileProvider . SetInstance ( ( ) => rmProvider , true ) ;
127
+ }
128
+ }
120
129
121
- cmdlet . SetParameterSet ( "AnonymousAccount" ) ;
122
- cmdlet . ExecuteCmdlet ( ) ;
123
- output = mock . OutputPipeline ;
124
- Assert . NotNull ( output ) ;
125
- storageContext = output . First ( ) as AzureStorageContext ;
126
- Assert . NotNull ( storageContext ) ;
127
- Assert . Equal ( cmdlet . StorageAccountName , storageContext . StorageAccountName ) ;
130
+ [ Fact ]
131
+ [ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
132
+ public void CanCreateStorageContextInChinaCloud ( )
133
+ {
134
+ AzureSessionInitializer . InitializeAzureSession ( ) ;
135
+ var smProvider = AzureSMProfileProvider . Instance ;
136
+ var rmProvider = AzureRmProfileProvider . Instance ;
137
+ AzureRmProfileProvider . SetInstance ( ( ) => new TestProfileProvider ( ) , true ) ;
138
+ AzureSMProfileProvider . SetInstance ( ( ) => new TestSMProfileProvider ( ) , true ) ;
139
+ try
140
+ {
141
+ var mock = new MockCommandRuntime ( ) ;
128
142
129
- cmdlet = new NewAzureStorageContext
143
+ AzureSMProfileProvider . Instance . Profile = null ;
144
+ AzureRmProfileProvider . Instance . Profile = new TestContextContainer ( ) ;
145
+ var cmdlet = new NewAzureStorageContext
130
146
{
131
147
CommandRuntime = mock ,
132
148
StorageAccountName = "contosostorage" ,
133
- SasToken = "AAAAAAAA" ,
149
+ StorageAccountKey = "AAAAAAAA" ,
150
+ Environment = EnvironmentName . AzureChinaCloud
134
151
} ;
135
152
136
- cmdlet . SetParameterSet ( "SasToken " ) ;
153
+ cmdlet . SetParameterSet ( "AccountNameAndKeyEnvironment " ) ;
137
154
cmdlet . ExecuteCmdlet ( ) ;
138
- output = mock . OutputPipeline ;
155
+ var output = mock . OutputPipeline ;
139
156
Assert . NotNull ( output ) ;
140
- storageContext = output . First ( ) as AzureStorageContext ;
157
+ var storageContext = output . First ( ) as AzureStorageContext ;
141
158
Assert . NotNull ( storageContext ) ;
142
159
Assert . Equal ( cmdlet . StorageAccountName , storageContext . StorageAccountName ) ;
160
+ Assert . True ( storageContext . BlobEndPoint . Contains ( ".cn" ) ) ;
161
+
143
162
}
144
163
finally
145
164
{
@@ -148,6 +167,7 @@ public void CanCreateStorageContextNameAndKey()
148
167
}
149
168
}
150
169
170
+
151
171
[ Fact ]
152
172
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
153
173
public void CanCreateStorageContextSASToken ( )
0 commit comments