public HttpClient CreateHttpClient(string serviceUrl, ICredentials credentials) { if (serviceUrl == null) { throw new ArgumentNullException("serviceUrl"); } if (credentials == null) { throw new ArgumentNullException("credentials"); } var realHelper = new ManagementClientHelper(); var mockHandler = HttpMockServer.CreateInstance(); var authenticationHandler = realHelper.CreateClientHandler(serviceUrl, credentials); mockHandler.InnerHandler = authenticationHandler; HttpClient client = new HttpClient(mockHandler) { BaseAddress = new Uri(serviceUrl), MaxResponseContentBufferSize = 30 * 1024 * 1024 }; client.DefaultRequestHeaders.Accept.Clear(); return(client); }
public TClient CreateClient <TClient>(bool addRestLogHandler, EventHandler <ClientCreatedArgs> clientCreatedHandler, params object[] parameters) where TClient : ServiceClient <TClient> { TClient client = ManagementClients.FirstOrDefault(o => o is TClient) as TClient; if (client == null) { if (throwWhenNotAvailable) { throw new ArgumentException( string.Format("TestManagementClientHelper class wasn't initialized with the {0} client.", typeof(TClient).Name)); } else { var realHelper = new ManagementClientHelper(); var realClient = realHelper.CreateClient <TClient>(addRestLogHandler, clientCreatedHandler, parameters); realClient.WithHandler(HttpMockServer.CreateInstance()); return(realClient); } } return(client); }
private AzureSession() { ManagementClientHelper = new ManagementClientHelper(); }