Skip to content

Commit 77df068

Browse files
committed
Adding check-in test for disconnected scenario
1 parent c619a44 commit 77df068

File tree

3 files changed

+126
-1
lines changed

3 files changed

+126
-1
lines changed

AzurePowershell.Test.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
<AsmXUnitTests Include=".\src\ServiceManagement\Common\Commands.ScenarioTest\bin\Debug\Microsoft.WindowsAzure.Commands.ScenarioTest.dll"/>
6666
<AsmXUnitTests Include=".\src\ServiceManagement\RecoveryServices\Commands.RecoveryServices.Test\bin\Debug\Microsoft.Azure.Commands.RecoveryServices.Test.dll"/>
6767
<AsmXUnitTests Include=".\src\ServiceManagement\Network\Commands.Network.Test\bin\Debug\Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.dll"/>
68-
</ItemGroup>
68+
<AsmXUnitTests Include=".\src\Storage\Commands.Storage.Test\bin\Debug\Microsoft.WindowsAzure.Commands.Storage.Test.dll"/>
69+
</ItemGroup>
6970
<ItemGroup Condition=" '$(scope)' == 'all' ">
7071
<XUnitTests Include=".\tools\StaticAnalysis\StaticAnalysis.Test\bin\Debug\StaticAnalysis.Test.dll"/>
7172
<XUnitTests Include=".\src\ResourceManager\ApiManagement\Commands.ApiManagement.Test\bin\Debug\Microsoft.Azure.Commands.ApiManagement.Test.dll"/>

src/Storage/Commands.Storage.Test/Commands.Storage.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
<Compile Include="Common\Cmdlet\NewAzureStorageContextTest.cs" />
204204
<Compile Include="Common\Cmdlet\SetAzureStorageServiceLoggingTest.cs" />
205205
<Compile Include="Common\Cmdlet\SetAzureStorageServiceHourMetricsTest.cs" />
206+
<Compile Include="Common\Cmdlet\StorageContextDisconnectedTests.cs" />
206207
<Compile Include="Common\CommunicationExceptionUtilTest.cs" />
207208
<Compile Include="Common\FileNamingGenerator.cs" />
208209
<Compile Include="Common\IStorageManagement.cs" />
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Common.Authentication;
16+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
17+
using Microsoft.WindowsAzure.Commands.Common;
18+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Microsoft.WindowsAzure.Commands.Storage;
21+
using Microsoft.WindowsAzure.Commands.Storage.Common.Cmdlet;
22+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
23+
using System.Linq;
24+
using Xunit;
25+
using System;
26+
using System.Collections.Generic;
27+
28+
namespace Microsoft.WindowsAzure.Management.Storage.Test.Common.Cmdlet
29+
{
30+
public class StorageContextDisconnectedTests
31+
{
32+
class TestProfileProvider : AzureRmProfileProvider
33+
{
34+
public override T GetProfile<T>()
35+
{
36+
return default(T);
37+
}
38+
}
39+
40+
class TestSMProfileProvider : AzureSMProfileProvider
41+
{
42+
public override T GetProfile<T>()
43+
{
44+
return default(T);
45+
}
46+
47+
public override void SetTokenCacheForProfile(IAzureContextContainer profile)
48+
{
49+
50+
}
51+
}
52+
53+
class TestContextContainer : IAzureContextContainer
54+
{
55+
public IEnumerable<IAzureAccount> Accounts
56+
{
57+
get;
58+
} = new List<IAzureAccount>();
59+
60+
public IAzureContext DefaultContext
61+
{
62+
get; set;
63+
}
64+
65+
public IEnumerable<IAzureEnvironment> Environments
66+
{
67+
get;
68+
} = new List<IAzureEnvironment>();
69+
70+
public IDictionary<string, string> ExtendedProperties
71+
{
72+
get;
73+
} = new Dictionary<string, string>();
74+
75+
public IEnumerable<IAzureSubscription> Subscriptions
76+
{
77+
get;
78+
} = new List<IAzureSubscription>();
79+
80+
public void Clear()
81+
{
82+
83+
}
84+
}
85+
86+
[Fact]
87+
[Trait(Category.AcceptanceType, Category.CheckIn)]
88+
public void CanCreateStorageContext()
89+
{
90+
AzureSessionInitializer.InitializeAzureSession();
91+
var smProvider = AzureSMProfileProvider.Instance;
92+
var rmProvider = AzureRmProfileProvider.Instance;
93+
AzureRmProfileProvider.SetInstance(() => new TestProfileProvider(), true);
94+
AzureSMProfileProvider.SetInstance(()=> new TestSMProfileProvider(), true);
95+
try
96+
{
97+
var mock = new MockCommandRuntime();
98+
99+
AzureSMProfileProvider.Instance.Profile = null;
100+
AzureRmProfileProvider.Instance.Profile = new TestContextContainer();
101+
var cmdlet = new NewAzureStorageContext
102+
{
103+
CommandRuntime = mock,
104+
StorageAccountName = "contosostorage",
105+
StorageAccountKey = "AAAAAAAA",
106+
};
107+
108+
cmdlet.SetParameterSet("AccountNameAndKey");
109+
cmdlet.ExecuteCmdlet();
110+
var output = mock.OutputPipeline;
111+
Assert.NotNull(output);
112+
var storageContext = output.First() as AzureStorageContext;
113+
Assert.NotNull(storageContext);
114+
Assert.Equal(cmdlet.StorageAccountName, storageContext.StorageAccountName);
115+
}
116+
finally
117+
{
118+
AzureSMProfileProvider.SetInstance(() => smProvider, true);
119+
AzureRmProfileProvider.SetInstance(() => rmProvider, true);
120+
}
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)