15
15
using Microsoft . Azure . Commands . Common . Authentication ;
16
16
using Microsoft . Azure . Commands . Common . Authentication . Abstractions ;
17
17
using Microsoft . Azure . Commands . Common . Authentication . Models ;
18
+ using Microsoft . Azure . Commands . ResourceManager . Common ;
18
19
using Microsoft . Azure . Commands . ScenarioTest ;
19
20
using Microsoft . Azure . Commands . TestFx . Mocks ;
20
21
using Microsoft . Azure . ServiceManagement . Common . Models ;
21
22
using Microsoft . WindowsAzure . Commands . Common . Test . Mocks ;
22
23
using Microsoft . WindowsAzure . Commands . ScenarioTest ;
23
24
using Microsoft . WindowsAzure . Commands . Test . Utilities . Common ;
24
25
using Microsoft . WindowsAzure . Commands . Utilities . Common ;
26
+ using Moq ;
25
27
using System ;
26
28
using System . Linq ;
27
29
using System . Management . Automation ;
@@ -34,6 +36,7 @@ public class ProfileCmdletTests : RMTestBase
34
36
{
35
37
private MemoryDataStore dataStore ;
36
38
private MockCommandRuntime commandRuntimeMock ;
39
+ private AzKeyStore keyStore ;
37
40
38
41
public ProfileCmdletTests ( ITestOutputHelper output )
39
42
{
@@ -43,12 +46,25 @@ public ProfileCmdletTests(ITestOutputHelper output)
43
46
AzureSession . Instance . DataStore = dataStore ;
44
47
commandRuntimeMock = new MockCommandRuntime ( ) ;
45
48
AzureSession . Instance . AuthenticationFactory = new MockTokenAuthenticationFactory ( ) ;
49
+ keyStore = SetMockedAzKeyStore ( ) ;
50
+ }
51
+
52
+ private AzKeyStore SetMockedAzKeyStore ( )
53
+ {
54
+ var storageMocker = new Mock < IStorage > ( ) ;
55
+ storageMocker . Setup ( f => f . Create ( ) ) . Returns ( storageMocker . Object ) ;
56
+ storageMocker . Setup ( f => f . ReadData ( ) ) . Returns ( new byte [ 0 ] ) ;
57
+ storageMocker . Setup ( f => f . WriteData ( It . IsAny < byte [ ] > ( ) ) ) . Callback ( ( byte [ ] s ) => { } ) ;
58
+ var keyStore = new AzKeyStore ( AzureSession . Instance . ARMProfileDirectory , "keystore.cache" , false , false , storageMocker . Object ) ;
59
+ return keyStore ;
46
60
}
47
61
48
62
[ Fact ]
49
63
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
50
64
public void SelectAzureProfileInMemory ( )
51
65
{
66
+ AzureSession . Instance . RegisterComponent ( AzKeyStore . Name , ( ) => keyStore , true ) ;
67
+
52
68
var profile = new AzureRmProfile { DefaultContext = new AzureContext ( ) } ;
53
69
var env = new AzureEnvironment ( AzureEnvironment . PublicEnvironments . Values . FirstOrDefault ( ) ) ;
54
70
env . Name = "foo" ;
@@ -71,6 +87,7 @@ public void SelectAzureProfileInMemory()
71
87
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
72
88
public void SelectAzureProfileBadPath ( )
73
89
{
90
+ AzureSession . Instance . RegisterComponent ( AzKeyStore . Name , ( ) => keyStore , true ) ;
74
91
#pragma warning disable CS0618 // Suppress obsolescence warning: cmdlet name is changing
75
92
ImportAzureRMContextCommand cmdlt = new ImportAzureRMContextCommand ( ) ;
76
93
#pragma warning restore CS0618 // Suppress obsolescence warning: cmdlet name is changing
@@ -88,6 +105,7 @@ public void SelectAzureProfileBadPath()
88
105
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
89
106
public void SelectAzureProfileFromDisk ( )
90
107
{
108
+ AzureSession . Instance . RegisterComponent ( AzKeyStore . Name , ( ) => keyStore , true ) ;
91
109
var profile = new AzureRmProfile ( ) ;
92
110
profile . EnvironmentTable . Add ( "foo" , new AzureEnvironment ( new AzureEnvironment ( AzureEnvironment . PublicEnvironments . Values . FirstOrDefault ( ) ) ) ) ;
93
111
profile . EnvironmentTable [ "foo" ] . Name = "foo" ;
@@ -110,6 +128,7 @@ public void SelectAzureProfileFromDisk()
110
128
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
111
129
public void SaveAzureProfileInMemory ( )
112
130
{
131
+ AzureSession . Instance . RegisterComponent ( AzKeyStore . Name , ( ) => keyStore , true ) ;
113
132
var profile = new AzureRmProfile ( ) ;
114
133
profile . EnvironmentTable . Add ( "foo" , new AzureEnvironment ( AzureEnvironment . PublicEnvironments . Values . FirstOrDefault ( ) ) ) ;
115
134
profile . EnvironmentTable [ "foo" ] . Name = "foo" ;
@@ -134,6 +153,7 @@ public void SaveAzureProfileInMemory()
134
153
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
135
154
public void SaveAzureProfileNull ( )
136
155
{
156
+ AzureSession . Instance . RegisterComponent ( AzKeyStore . Name , ( ) => keyStore , true ) ;
137
157
#pragma warning disable CS0618 // Suppress obsolescence warning: cmdlet name is changing
138
158
SaveAzureRMContextCommand cmdlt = new SaveAzureRMContextCommand ( ) ;
139
159
#pragma warning restore CS0618 // Suppress obsolescence warning: cmdlet name is changing
@@ -150,6 +170,7 @@ public void SaveAzureProfileNull()
150
170
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
151
171
public void SaveAzureProfileFromDefault ( )
152
172
{
173
+ AzureSession . Instance . RegisterComponent ( AzKeyStore . Name , ( ) => keyStore , true ) ;
153
174
var profile = new AzureRmProfile ( ) ;
154
175
profile . EnvironmentTable . Add ( "foo" , new AzureEnvironment ( AzureEnvironment . PublicEnvironments . Values . FirstOrDefault ( ) ) ) ;
155
176
profile . DefaultContext = new AzureContext ( new AzureSubscription ( ) , new AzureAccount ( ) , profile . EnvironmentTable [ "foo" ] ) ;
0 commit comments