Skip to content

Commit 49074e9

Browse files
committed
Adding tests for additional offline scenarios
1 parent 77df068 commit 49074e9

File tree

1 file changed

+107
-4
lines changed

1 file changed

+107
-4
lines changed

src/Storage/Commands.Storage.Test/Common/Cmdlet/StorageContextDisconnectedTests.cs

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414

1515
using Microsoft.Azure.Commands.Common.Authentication;
1616
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
17-
using Microsoft.WindowsAzure.Commands.Common;
1817
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
1918
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2019
using Microsoft.WindowsAzure.Commands.Storage;
2120
using Microsoft.WindowsAzure.Commands.Storage.Common.Cmdlet;
2221
using Microsoft.WindowsAzure.Commands.Utilities.Common;
22+
using System.Collections.Generic;
2323
using System.Linq;
2424
using Xunit;
25-
using System;
26-
using System.Collections.Generic;
2725

2826
namespace Microsoft.WindowsAzure.Management.Storage.Test.Common.Cmdlet
2927
{
@@ -85,7 +83,7 @@ public void Clear()
8583

8684
[Fact]
8785
[Trait(Category.AcceptanceType, Category.CheckIn)]
88-
public void CanCreateStorageContext()
86+
public void CanCreateStorageContextNameAndKey()
8987
{
9088
AzureSessionInitializer.InitializeAzureSession();
9189
var smProvider = AzureSMProfileProvider.Instance;
@@ -112,12 +110,117 @@ public void CanCreateStorageContext()
112110
var storageContext = output.First() as AzureStorageContext;
113111
Assert.NotNull(storageContext);
114112
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);
115143
}
116144
finally
117145
{
118146
AzureSMProfileProvider.SetInstance(() => smProvider, true);
119147
AzureRmProfileProvider.SetInstance(() => rmProvider, true);
120148
}
121149
}
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+
122225
}
123226
}

0 commit comments

Comments
 (0)