14
14
15
15
using Microsoft . Azure . Commands . Common . Authentication ;
16
16
using Microsoft . Azure . Commands . Common . Authentication . Abstractions ;
17
- using Microsoft . WindowsAzure . Commands . Common ;
18
17
using Microsoft . WindowsAzure . Commands . Common . Test . Mocks ;
19
18
using Microsoft . WindowsAzure . Commands . ScenarioTest ;
20
19
using Microsoft . WindowsAzure . Commands . Storage ;
21
20
using Microsoft . WindowsAzure . Commands . Storage . Common . Cmdlet ;
22
21
using Microsoft . WindowsAzure . Commands . Utilities . Common ;
22
+ using System . Collections . Generic ;
23
23
using System . Linq ;
24
24
using Xunit ;
25
- using System ;
26
- using System . Collections . Generic ;
27
25
28
26
namespace Microsoft . WindowsAzure . Management . Storage . Test . Common . Cmdlet
29
27
{
@@ -85,7 +83,7 @@ public void Clear()
85
83
86
84
[ Fact ]
87
85
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
88
- public void CanCreateStorageContext ( )
86
+ public void CanCreateStorageContextNameAndKey ( )
89
87
{
90
88
AzureSessionInitializer . InitializeAzureSession ( ) ;
91
89
var smProvider = AzureSMProfileProvider . Instance ;
@@ -112,12 +110,117 @@ public void CanCreateStorageContext()
112
110
var storageContext = output . First ( ) as AzureStorageContext ;
113
111
Assert . NotNull ( storageContext ) ;
114
112
Assert . Equal ( cmdlet . StorageAccountName , storageContext . StorageAccountName ) ;
113
+
114
+ cmdlet = new NewAzureStorageContext
115
+ {
116
+ CommandRuntime = mock ,
117
+ StorageAccountName = "contosostorage" ,
118
+ Anonymous = true ,
119
+ } ;
120
+
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 ) ;
128
+
129
+ cmdlet = new NewAzureStorageContext
130
+ {
131
+ CommandRuntime = mock ,
132
+ StorageAccountName = "contosostorage" ,
133
+ SasToken = "AAAAAAAA" ,
134
+ } ;
135
+
136
+ cmdlet . SetParameterSet ( "SasToken" ) ;
137
+ cmdlet . ExecuteCmdlet ( ) ;
138
+ output = mock . OutputPipeline ;
139
+ Assert . NotNull ( output ) ;
140
+ storageContext = output . First ( ) as AzureStorageContext ;
141
+ Assert . NotNull ( storageContext ) ;
142
+ Assert . Equal ( cmdlet . StorageAccountName , storageContext . StorageAccountName ) ;
115
143
}
116
144
finally
117
145
{
118
146
AzureSMProfileProvider . SetInstance ( ( ) => smProvider , true ) ;
119
147
AzureRmProfileProvider . SetInstance ( ( ) => rmProvider , true ) ;
120
148
}
121
149
}
150
+
151
+ [ Fact ]
152
+ [ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
153
+ public void CanCreateStorageContextSASToken ( )
154
+ {
155
+ AzureSessionInitializer . InitializeAzureSession ( ) ;
156
+ var smProvider = AzureSMProfileProvider . Instance ;
157
+ var rmProvider = AzureRmProfileProvider . Instance ;
158
+ AzureRmProfileProvider . SetInstance ( ( ) => new TestProfileProvider ( ) , true ) ;
159
+ AzureSMProfileProvider . SetInstance ( ( ) => new TestSMProfileProvider ( ) , true ) ;
160
+ try
161
+ {
162
+ var mock = new MockCommandRuntime ( ) ;
163
+
164
+ AzureSMProfileProvider . Instance . Profile = null ;
165
+ AzureRmProfileProvider . Instance . Profile = new TestContextContainer ( ) ;
166
+ var cmdlet = new NewAzureStorageContext
167
+ {
168
+ CommandRuntime = mock ,
169
+ StorageAccountName = "contosostorage" ,
170
+ SasToken = "AAAAAAAA" ,
171
+ } ;
172
+
173
+ cmdlet . SetParameterSet ( "SasToken" ) ;
174
+ cmdlet . ExecuteCmdlet ( ) ;
175
+ var output = mock . OutputPipeline ;
176
+ Assert . NotNull ( output ) ;
177
+ var storageContext = output . First ( ) as AzureStorageContext ;
178
+ Assert . NotNull ( storageContext ) ;
179
+ Assert . Equal ( "[SasToken]" , storageContext . StorageAccountName ) ;
180
+ }
181
+ finally
182
+ {
183
+ AzureSMProfileProvider . SetInstance ( ( ) => smProvider , true ) ;
184
+ AzureRmProfileProvider . SetInstance ( ( ) => rmProvider , true ) ;
185
+ }
186
+ }
187
+
188
+ [ Fact ]
189
+ [ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
190
+ public void CanCreateStorageContextAnonymous ( )
191
+ {
192
+ AzureSessionInitializer . InitializeAzureSession ( ) ;
193
+ var smProvider = AzureSMProfileProvider . Instance ;
194
+ var rmProvider = AzureRmProfileProvider . Instance ;
195
+ AzureRmProfileProvider . SetInstance ( ( ) => new TestProfileProvider ( ) , true ) ;
196
+ AzureSMProfileProvider . SetInstance ( ( ) => new TestSMProfileProvider ( ) , true ) ;
197
+ try
198
+ {
199
+ var mock = new MockCommandRuntime ( ) ;
200
+
201
+ AzureSMProfileProvider . Instance . Profile = null ;
202
+ AzureRmProfileProvider . Instance . Profile = new TestContextContainer ( ) ;
203
+ var cmdlet = new NewAzureStorageContext
204
+ {
205
+ CommandRuntime = mock ,
206
+ StorageAccountName = "contosostorage" ,
207
+ Anonymous = true ,
208
+ } ;
209
+
210
+ cmdlet . SetParameterSet ( "AnonymousAccount" ) ;
211
+ cmdlet . ExecuteCmdlet ( ) ;
212
+ var output = mock . OutputPipeline ;
213
+ Assert . NotNull ( output ) ;
214
+ var storageContext = output . First ( ) as AzureStorageContext ;
215
+ Assert . NotNull ( storageContext ) ;
216
+ Assert . Equal ( "[Anonymous]" , storageContext . StorageAccountName ) ;
217
+ }
218
+ finally
219
+ {
220
+ AzureSMProfileProvider . SetInstance ( ( ) => smProvider , true ) ;
221
+ AzureRmProfileProvider . SetInstance ( ( ) => rmProvider , true ) ;
222
+ }
223
+ }
224
+
122
225
}
123
226
}
0 commit comments