@@ -66,14 +66,7 @@ public EnvironmentSetupHelper()
66
66
System . Net . ServicePointManager . ServerCertificateValidationCallback += ( se , cert , chain , sslerror ) => true ;
67
67
68
68
// Set RunningMocked
69
- if ( HttpMockServer . GetCurrentMode ( ) == HttpRecorderMode . Playback )
70
- {
71
- TestMockSupport . RunningMocked = true ;
72
- }
73
- else
74
- {
75
- TestMockSupport . RunningMocked = false ;
76
- }
69
+ TestMockSupport . RunningMocked = HttpMockServer . GetCurrentMode ( ) == HttpRecorderMode . Playback ;
77
70
}
78
71
79
72
/// <summary>
@@ -103,32 +96,29 @@ public void SetupEnvironment(AzureModule mode)
103
96
104
97
private void SetupAzureEnvironmentFromEnvironmentVariables ( AzureModule mode )
105
98
{
106
- TestEnvironment rdfeEnvironment = new RDFETestEnvironmentFactory ( ) . GetTestEnvironment ( ) ;
107
- TestEnvironment csmEnvironment = new CSMTestEnvironmentFactory ( ) . GetTestEnvironment ( ) ;
108
- TestEnvironment currentEnvironment = ( mode == AzureModule . AzureResourceManager ? csmEnvironment : rdfeEnvironment ) ;
99
+ TestEnvironment currentEnvironment = null ;
100
+ if ( mode == AzureModule . AzureResourceManager )
101
+ {
102
+ currentEnvironment = new CSMTestEnvironmentFactory ( ) . GetTestEnvironment ( ) ;
103
+ }
104
+ else
105
+ {
106
+ currentEnvironment = new RDFETestEnvironmentFactory ( ) . GetTestEnvironment ( ) ;
107
+ }
109
108
110
109
if ( currentEnvironment . UserName == null )
111
110
{
112
111
currentEnvironment . UserName = "[email protected] " ;
113
112
}
114
113
115
- SetAuthenticationFactory ( mode , rdfeEnvironment , csmEnvironment ) ;
114
+ SetAuthenticationFactory ( mode , currentEnvironment ) ;
116
115
117
116
AzureEnvironment environment = new AzureEnvironment { Name = testEnvironmentName } ;
118
117
119
118
Debug . Assert ( currentEnvironment != null ) ;
120
119
environment . Endpoints [ AzureEnvironment . Endpoint . ActiveDirectory ] = currentEnvironment . Endpoints . AADAuthUri . AbsoluteUri ;
121
120
environment . Endpoints [ AzureEnvironment . Endpoint . Gallery ] = currentEnvironment . Endpoints . GalleryUri . AbsoluteUri ;
122
-
123
- if ( csmEnvironment != null )
124
- {
125
- environment . Endpoints [ AzureEnvironment . Endpoint . ResourceManager ] = csmEnvironment . BaseUri . AbsoluteUri ;
126
- }
127
-
128
- if ( rdfeEnvironment != null )
129
- {
130
- environment . Endpoints [ AzureEnvironment . Endpoint . ServiceManagement ] = rdfeEnvironment . BaseUri . AbsoluteUri ;
131
- }
121
+ environment . Endpoints [ AzureEnvironment . Endpoint . ServiceManagement ] = currentEnvironment . BaseUri . AbsoluteUri ;
132
122
133
123
if ( ! ProfileClient . Profile . Environments . ContainsKey ( testEnvironmentName ) )
134
124
{
@@ -169,44 +159,29 @@ private void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode)
169
159
}
170
160
}
171
161
172
- private void SetAuthenticationFactory ( AzureModule mode , TestEnvironment rdfeEnvironment , TestEnvironment csmEnvironment )
162
+ private void SetAuthenticationFactory ( AzureModule mode , TestEnvironment environment )
173
163
{
174
164
string jwtToken = null ;
175
165
X509Certificate2 certificate = null ;
176
- TestEnvironment currentEnvironment = ( mode == AzureModule . AzureResourceManager ? csmEnvironment : rdfeEnvironment ) ;
177
166
178
- if ( mode == AzureModule . AzureServiceManagement )
167
+ if ( environment . Credentials is TokenCloudCredentials )
179
168
{
180
- if ( rdfeEnvironment . Credentials is TokenCloudCredentials )
181
- {
182
- jwtToken = ( ( TokenCloudCredentials ) rdfeEnvironment . Credentials ) . Token ;
183
- }
184
- if ( rdfeEnvironment . Credentials is CertificateCloudCredentials )
185
- {
186
- certificate = ( ( CertificateCloudCredentials ) rdfeEnvironment . Credentials ) . ManagementCertificate ;
187
- }
169
+ jwtToken = ( ( TokenCloudCredentials ) environment . Credentials ) . Token ;
188
170
}
189
- else
171
+ if ( environment . Credentials is CertificateCloudCredentials )
190
172
{
191
- if ( csmEnvironment . Credentials is TokenCloudCredentials )
192
- {
193
- jwtToken = ( ( TokenCloudCredentials ) csmEnvironment . Credentials ) . Token ;
194
- }
195
- if ( csmEnvironment . Credentials is CertificateCloudCredentials )
196
- {
197
- certificate = ( ( CertificateCloudCredentials ) csmEnvironment . Credentials ) . ManagementCertificate ;
198
- }
173
+ certificate = ( ( CertificateCloudCredentials ) environment . Credentials ) . ManagementCertificate ;
199
174
}
200
175
201
176
202
177
if ( jwtToken != null )
203
178
{
204
- AzureSession . AuthenticationFactory = new MockTokenAuthenticationFactory ( currentEnvironment . UserName ,
179
+ AzureSession . AuthenticationFactory = new MockTokenAuthenticationFactory ( environment . UserName ,
205
180
jwtToken ) ;
206
181
}
207
182
else if ( certificate != null )
208
183
{
209
- AzureSession . AuthenticationFactory = new MockCertificateAuthenticationFactory ( currentEnvironment . UserName ,
184
+ AzureSession . AuthenticationFactory = new MockCertificateAuthenticationFactory ( environment . UserName ,
210
185
certificate ) ;
211
186
}
212
187
}
0 commit comments