Skip to content

Commit 1851ceb

Browse files
committed
Cleaning up tests and adding test for additional environment
1 parent 49074e9 commit 1851ceb

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

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

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ public override void SetTokenCacheForProfile(IAzureContextContainer profile)
5050

5151
class TestContextContainer : IAzureContextContainer
5252
{
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+
}
5361
public IEnumerable<IAzureAccount> Accounts
5462
{
5563
get;
@@ -62,8 +70,8 @@ public IAzureContext DefaultContext
6270

6371
public IEnumerable<IAzureEnvironment> Environments
6472
{
65-
get;
66-
} = new List<IAzureEnvironment>();
73+
get { return _environments; }
74+
}
6775

6876
public IDictionary<string, string> ExtendedProperties
6977
{
@@ -111,35 +119,46 @@ public void CanCreateStorageContextNameAndKey()
111119
Assert.NotNull(storageContext);
112120
Assert.Equal(cmdlet.StorageAccountName, storageContext.StorageAccountName);
113121

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+
}
120129

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();
128142

129-
cmdlet = new NewAzureStorageContext
143+
AzureSMProfileProvider.Instance.Profile = null;
144+
AzureRmProfileProvider.Instance.Profile = new TestContextContainer();
145+
var cmdlet = new NewAzureStorageContext
130146
{
131147
CommandRuntime = mock,
132148
StorageAccountName = "contosostorage",
133-
SasToken = "AAAAAAAA",
149+
StorageAccountKey = "AAAAAAAA",
150+
Environment = EnvironmentName.AzureChinaCloud
134151
};
135152

136-
cmdlet.SetParameterSet("SasToken");
153+
cmdlet.SetParameterSet("AccountNameAndKeyEnvironment");
137154
cmdlet.ExecuteCmdlet();
138-
output = mock.OutputPipeline;
155+
var output = mock.OutputPipeline;
139156
Assert.NotNull(output);
140-
storageContext = output.First() as AzureStorageContext;
157+
var storageContext = output.First() as AzureStorageContext;
141158
Assert.NotNull(storageContext);
142159
Assert.Equal(cmdlet.StorageAccountName, storageContext.StorageAccountName);
160+
Assert.True(storageContext.BlobEndPoint.Contains(".cn"));
161+
143162
}
144163
finally
145164
{
@@ -148,6 +167,7 @@ public void CanCreateStorageContextNameAndKey()
148167
}
149168
}
150169

170+
151171
[Fact]
152172
[Trait(Category.AcceptanceType, Category.CheckIn)]
153173
public void CanCreateStorageContextSASToken()

0 commit comments

Comments
 (0)