@@ -99,6 +99,13 @@ public T GetServiceClient<T>(bool internalBaseUri = false, params DelegatingHand
99
99
/// <returns></returns>
100
100
public T GetServiceClient < T > ( TestEnvironment currentEnvironment , bool internalBaseUri = false , params DelegatingHandler [ ] handlers ) where T : class
101
101
{
102
+ if ( ! currentEnvironment . TokenInfo . ContainsKey ( TokenAudience . Management ) )
103
+ {
104
+ throw new ArgumentNullException (
105
+ "currentEnvironment.TokenInfo[TokenAudience.Management]" ,
106
+ $ "Unable to create Service Client because { nameof ( T ) } authentication token was not acquired during Login.") ;
107
+ }
108
+
102
109
return GetServiceClientWithCredentials < T > ( currentEnvironment , currentEnvironment . TokenInfo [ TokenAudience . Management ] , internalBaseUri , handlers ) ;
103
110
}
104
111
@@ -108,9 +115,7 @@ public T GetServiceClient<T>(TestEnvironment currentEnvironment, bool internalBa
108
115
/// <typeparam name="T"></typeparam>
109
116
/// <param name="handlers">Delegating existingHandlers</param>
110
117
/// <returns></returns>
111
- public T GetGraphServiceClient < T > (
112
- bool internalBaseUri = false ,
113
- params DelegatingHandler [ ] handlers ) where T : class
118
+ public T GetGraphServiceClient < T > ( bool internalBaseUri = false , params DelegatingHandler [ ] handlers ) where T : class
114
119
{
115
120
return GetGraphServiceClient < T > ( TestFxEnvironment , internalBaseUri , handlers ) ;
116
121
}
@@ -121,52 +126,16 @@ public T GetGraphServiceClient<T>(
121
126
/// <typeparam name="T"></typeparam>
122
127
/// <param name="handlers">Delegating existingHandlers</param>
123
128
/// <returns></returns>
124
- public T GetGraphServiceClient < T > (
125
- TestEnvironment currentEnvironment ,
126
- bool internalBaseUri = false ,
127
- params DelegatingHandler [ ] handlers ) where T : class
129
+ public T GetGraphServiceClient < T > ( TestEnvironment currentEnvironment , bool internalBaseUri = false , params DelegatingHandler [ ] handlers ) where T : class
128
130
{
129
131
if ( ! currentEnvironment . TokenInfo . ContainsKey ( TokenAudience . Graph ) )
130
132
{
131
133
throw new ArgumentNullException (
132
134
"currentEnvironment.TokenInfo[TokenAudience.Graph]" ,
133
- "Unable to create Graph Management client because Graph authentication token was not acquired during Login." ) ;
135
+ "Unable to create Graph Client because Graph authentication token was not acquired during Login." ) ;
134
136
}
135
137
136
- return GetServiceClientWithCredentials < T > (
137
- currentEnvironment ,
138
- currentEnvironment . TokenInfo [ TokenAudience . Graph ] ,
139
- currentEnvironment . Endpoints . GraphUri ,
140
- internalBaseUri ,
141
- handlers ) ;
142
- }
143
-
144
- /// <summary>
145
- /// Get a test environment using default options
146
- /// </summary>
147
- /// <typeparam name="T">The type of the service client to return</typeparam>
148
- /// <param name="credentials">Credentials</param>
149
- /// <param name="handlers">Delegating existingHandlers</param>
150
- /// <returns>A Service client using credentials and base uri from the current environment</returns>
151
- public T GetServiceClientWithCredentials < T > ( object credentials , params DelegatingHandler [ ] handlers ) where T : class
152
- {
153
- return GetServiceClientWithCredentials < T > ( TestFxEnvironment , credentials , handlers : handlers ) ;
154
- }
155
-
156
- /// <summary>
157
- /// Get a test environment, allowing the test to customize the creation options
158
- /// </summary>
159
- /// <typeparam name="T"></typeparam>
160
- /// <param name="credentials">Credentials</param>
161
- /// <param name="handlers">Delegating existingHandlers</param>
162
- /// <returns></returns>
163
- public T GetServiceClientWithCredentials < T > (
164
- TestEnvironment currentEnvironment ,
165
- object credentials ,
166
- bool internalBaseUri = false ,
167
- params DelegatingHandler [ ] handlers ) where T : class
168
- {
169
- return GetServiceClientWithCredentials < T > ( currentEnvironment , credentials , currentEnvironment . BaseUri , internalBaseUri , handlers ) ;
138
+ return GetServiceClientWithCredentials < T > ( currentEnvironment , currentEnvironment . TokenInfo [ TokenAudience . Graph ] , internalBaseUri , handlers ) ;
170
139
}
171
140
172
141
/// <summary>
@@ -177,21 +146,14 @@ public T GetServiceClientWithCredentials<T>(
177
146
/// <param name="baseUri">Base Uri</param>
178
147
/// <param name="handlers">Delegating existingHandlers</param>
179
148
/// <returns></returns>
180
- public T GetServiceClientWithCredentials < T > (
181
- TestEnvironment currentEnvironment ,
182
- object credentials ,
183
- Uri baseUri ,
184
- bool internalBaseUri = false ,
185
- params DelegatingHandler [ ] handlers ) where T : class
149
+ public T GetServiceClientWithCredentials < T > ( TestEnvironment currentEnvironment , object credentials , bool internalBaseUri = false , params DelegatingHandler [ ] handlers ) where T : class
186
150
{
187
151
T client ;
188
152
handlers = AddHandlers ( currentEnvironment , handlers ) ;
189
153
var constructors = typeof ( T ) . GetConstructors ( BindingFlags . Public | BindingFlags . Static | BindingFlags . Instance | BindingFlags . NonPublic ) ;
190
154
191
155
ConstructorInfo constructor = null ;
192
- //We no longer use UseCustomUri function, rather check if BaseUri is notNull
193
- //UseCustomeUri use to return true when BaseUri was set to some value
194
- if ( ( currentEnvironment . BaseUri != null ) && ! internalBaseUri )
156
+ if ( ! internalBaseUri && currentEnvironment . BaseUri != null )
195
157
{
196
158
foreach ( var c in constructors )
197
159
{
@@ -207,12 +169,11 @@ public T GetServiceClientWithCredentials<T>(
207
169
}
208
170
if ( constructor == null )
209
171
{
210
- throw new InvalidOperationException (
211
- "can't find constructor (uri, ServiceClientCredentials, DelegatingHandler[]) to create client" ) ;
172
+ throw new InvalidOperationException ( "Cannot find constructor (uri, ServiceClientCredentials, DelegatingHandler[]) to create service client" ) ;
212
173
}
213
174
client = constructor . Invoke ( new object [ ]
214
175
{
215
- baseUri ,
176
+ currentEnvironment . BaseUri ,
216
177
credentials ,
217
178
handlers
218
179
} ) as T ;
@@ -232,8 +193,7 @@ public T GetServiceClientWithCredentials<T>(
232
193
}
233
194
if ( constructor == null )
234
195
{
235
- throw new InvalidOperationException (
236
- "can't find constructor (ServiceClientCredentials, DelegatingHandler[]) to create client" ) ;
196
+ throw new InvalidOperationException ( "Cannot find constructor (ServiceClientCredentials, DelegatingHandler[]) to create service client" ) ;
237
197
}
238
198
client = constructor . Invoke ( new object [ ]
239
199
{
@@ -262,15 +222,11 @@ private void SetLongRunningOperationTimeouts<T>(T client) where T : class
262
222
if ( HttpMockServer . Mode == HttpRecorderMode . Playback )
263
223
{
264
224
PropertyInfo retryTimeout = typeof ( T ) . GetProperty ( "LongRunningOperationRetryTimeout" ) ;
265
- if ( retryTimeout != null )
266
- {
267
- retryTimeout . SetValue ( client , 0 ) ;
268
- }
225
+ retryTimeout ? . SetValue ( client , 0 ) ;
269
226
}
270
227
}
271
228
272
- public DelegatingHandler [ ] AddHandlers ( TestEnvironment currentEnvironment ,
273
- params DelegatingHandler [ ] existingHandlers )
229
+ public DelegatingHandler [ ] AddHandlers ( TestEnvironment currentEnvironment , params DelegatingHandler [ ] existingHandlers )
274
230
{
275
231
HttpMockServer server ;
276
232
0 commit comments