public static void CompileExpectError(Type errorType, string code, IHttpRequestFactory requestFactory) { var compiler = new Compiler(code); var assembly = compiler.ToAssembly(); Assert.IsTrue(compiler.Errors.Count == 1); Assert.IsTrue(compiler.Errors[0].GetType() == errorType); }
public SelectTests() { var html = @" <div> <span class=""center"">here</span> <a href=""http://google.com"">link</a> <div class=""dollar"">$6,566.00</div> <span class=""address"">4332 Forest Hill Blvd<br>West Palm Beach, FL 33406</span> <div id=""match-tests""> <li>6,566</li> <li>6</li> <li>8,975</li> <li>6,566,888</li> </div> <div id=""match-tests""> <li>10,566</li> <li>3</li> <li>1,975</li> <li>2,566,888</li> </div> </div> "; var httpRequest = new Mock<IHttpRequest>(); httpRequest.Setup(x => x.Download()).Returns(System.Text.Encoding.UTF8.GetBytes(html)); var requestFactory = new Mock<IHttpRequestFactory>(); requestFactory.Setup(x => x.Create(It.IsAny<IHttpWire>())).Returns(httpRequest.Object); _requestFactory = requestFactory.Object; }
public CompetitionApi(IHttpRequestFactory httpRequestFactory, IOptions <ApiSettings> options) { this.httpRequestFactory = httpRequestFactory; this.apiSettings = options.Value; this.teamLeagueApiUrl = $"{apiSettings.TeamLeagueApiUrl}"; }
private void BuildRuntimePipeline() { #if BCL || BCL45 var httpRequestFactory = new HttpWebRequestFactory(); var httpHandler = new HttpHandler <Stream>(httpRequestFactory, this); #elif UNITY IHttpRequestFactory <string> httpRequestFactory = null; HttpHandler <string> httpHandler = null; if (AWSConfigs.HttpClient == AWSConfigs.HttpClientOption.UnityWWW) { httpRequestFactory = new UnityWwwRequestFactory(); httpHandler = new HttpHandler <string>(httpRequestFactory, this); } else { httpRequestFactory = new UnityWebRequestFactory(); httpHandler = new HttpHandler <string>(httpRequestFactory, this); } #else var httpRequestFactory = new HttpRequestMessageFactory(this.Config); var httpHandler = new HttpHandler <System.Net.Http.HttpContent>(httpRequestFactory, this); #endif var preMarshallHandler = new CallbackHandler(); preMarshallHandler.OnPreInvoke = this.ProcessPreRequestHandlers; var postMarshallHandler = new CallbackHandler(); postMarshallHandler.OnPreInvoke = this.ProcessRequestHandlers; var postUnmarshallHandler = new CallbackHandler(); postUnmarshallHandler.OnPostInvoke = this.ProcessResponseHandlers; var errorCallbackHandler = new ErrorCallbackHandler(); errorCallbackHandler.OnError = this.ProcessExceptionHandlers; // Build default runtime pipeline. this.RuntimePipeline = new RuntimePipeline(new List <IPipelineHandler> { httpHandler, new Unmarshaller(this.SupportResponseLogging), new ErrorHandler(_logger), postUnmarshallHandler, new Signer(), new CredentialsRetriever(this.Credentials), new RetryHandler(new DefaultRetryPolicy(this.Config)), postMarshallHandler, new EndpointResolver(), new Marshaller(), preMarshallHandler, errorCallbackHandler, new MetricsHandler() #if UNITY , new ThreadPoolExecutionHandler(10) //remove the hardcoded to unity config #endif }, _logger ); CustomizeRuntimePipeline(this.RuntimePipeline); }
/// <summary> /// Initializes a new instance of the <see cref="JsonRestClient"/> class. /// </summary> /// <param name="uri">The base <see cref="Uri"/> for the REST service.</param> /// <param name="httpRequestFactory">The factory to use to create our HTTP Requests.</param> public JsonRestClient(Uri uri, IHttpRequestFactory httpRequestFactory) : base(uri, StringConstants.JsonMimeType, httpRequestFactory) { Contract.Requires <ArgumentNullException>(uri != null); Contract.Requires <ArgumentException>(uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps); Contract.Requires <ArgumentException>(httpRequestFactory != null); }
public SelectTests() { var html = @" <div> <span class=""center"">here</span> <a href=""http://google.com"">link</a> <div class=""dollar"">$6,566.00</div> <span class=""address"">4332 Forest Hill Blvd<br>West Palm Beach, FL 33406</span> <div id=""match-tests""> <li>6,566</li> <li>6</li> <li>8,975</li> <li>6,566,888</li> </div> <div id=""match-tests""> <li>10,566</li> <li>3</li> <li>1,975</li> <li>2,566,888</li> </div> </div> "; var httpRequest = new Mock <IHttpRequest>(); httpRequest.Setup(x => x.Download()).Returns(System.Text.Encoding.UTF8.GetBytes(html)); var requestFactory = new Mock <IHttpRequestFactory>(); requestFactory.Setup(x => x.Create("http://mock.com")).Returns(httpRequest.Object); _requestFactory = requestFactory.Object; }
public RedditImageDownloaderService(ILoggerFactory loggerFactory, IHttpRequestFactory httpRequestFactory) { _logger = loggerFactory?.CreateLogger <RedditImageDownloaderService>() ?? throw new ArgumentNullException(nameof(loggerFactory)); _httpRequestFactory = httpRequestFactory ?? throw new ArgumentNullException(nameof(httpRequestFactory)); _logger.LogDebug("RedditImageDownloaderService created"); }
public reading_feed_from_remote_source() { HttpRequestFactory = A.Fake <IHttpRequestFactory>(); _configurationProvider = new TestConfigurationProvider(); _remoteData = new RemoteData(HttpRequestFactory, _configurationProvider, new RemoteContentPreProcessor()); _incorrectUri = "http://incorrect.uri"; }
public static void ReplaceHttpRequestHandler <T>( AmazonServiceClient client, IHttpRequestFactory <T> httpRequestFactory) { var httpHandler = new HttpHandler <T>(httpRequestFactory, client); ReplaceHttpHandler(client, httpHandler); }
public RequestParser(IHttpRequestFactory requestFactory) { if (requestFactory == null) { throw new ArgumentNullException(nameof(requestFactory)); } this._requestFactory = requestFactory; }
public RestProxy( IHttpRequestFactory httpRequestFactory, IRestCallResultAdapter resultAdapter, IHttpClientProxy httpClientProxy) { _httpRequestFactory = httpRequestFactory; _resultAdapter = resultAdapter; _httpClientProxy = httpClientProxy; }
public static Runable Compile(string code, IHttpRequestFactory requestFactory) { var compiler = new Compiler(code); var assembly = compiler.ToAssembly(); Assert.IsTrue(compiler.Errors.Count == 0); var runable = new Runable(assembly); if(requestFactory != null) runable.SetRequestFactory(requestFactory); return runable; }
/// <summary> /// Initializes a new instance of the <see cref="RestClientBase"/> class. /// </summary> /// <param name="uri">The base <see cref="Uri"/> for the REST service.</param> /// <param name="acceptHeader">The accept header to use in web requests.</param> /// <param name="httpRequestFactory">The factory used to create Linq2Rest.Provider.IHttpRequest implementations.</param> protected RestClientBase(Uri uri, string acceptHeader, IHttpRequestFactory httpRequestFactory) { CustomContract.Requires <ArgumentNullException>(uri != null); CustomContract.Requires <ArgumentException>(uri.Scheme == HttpUtility.UriSchemeHttp || uri.Scheme == HttpUtility.UriSchemeHttps); CustomContract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(acceptHeader)); CustomContract.Requires <ArgumentException>(httpRequestFactory != null); _acceptHeader = acceptHeader; _httpRequestFactory = httpRequestFactory; ServiceBase = uri; }
/// <summary> /// 创建一个指定相对路径的请求。 /// </summary> /// <param name="factory"></param> /// <param name="method">谓词。</param> /// <param name="relativePath">相对路径。</param> /// <returns></returns> public static IHttpRequest Create(this IHttpRequestFactory factory, HttpMethods method, string relativePath) { Uri.TryCreate(relativePath, UriKind.RelativeOrAbsolute, out Uri requestUri); IHttpRequest request = new HttpRequest(); request.Method = method; request.RequestUri = requestUri ?? new Uri("/", UriKind.Relative); return(request); }
public static async Task <byte[]> GetBytesAsync(this IHttpRequestFactory httpRequestFactory, string url, TimeoutSpecification timeout = default) { if (url == null) { throw new ArgumentNullException(nameof(url)); } var response = await httpRequestFactory.Get(url.ToUrl()).SendAsync(timeout).ConfigureAwait(false); return(await response.GetBytesAsync().ConfigureAwait(false)); }
internal ExternHttpClient(IHttpRequestFactory httpRequestFactory) { Http = httpRequestFactory; Accounts = new AccountClient(httpRequestFactory); Docflows = new DocflowsClient(httpRequestFactory); Replies = new RepliesClient(httpRequestFactory); Drafts = new DraftsClient(httpRequestFactory); Events = new EventsClient(httpRequestFactory); Contents = new ContentsClient(httpRequestFactory); DraftsBuilder = new DraftsBuilderClient(httpRequestFactory); Organizations = new OrganizationsClient(httpRequestFactory); }
public EventSendingService( IOptions <AzureSignalRServiceOptions> config, IAzureSignalRHttpClient signalRHttpClient, IUrlProvider urlProvider, IHttpRequestFactory httpRequestFactory ) { _signalRHttpClient = signalRHttpClient; _httpRequestFactory = httpRequestFactory; _urlProvider = urlProvider; _connectionString = ConnectionString.Parse(config.Value.ConnectionString); }
private static DownloadImage GetImage(IHttpRequestFactory factory, IHttpWire wire) { var request = CreateRequest(factory, wire); var bytes = request.Download(); string extension = Path.GetExtension(wire.Url); string fileName = Guid.NewGuid().ToString("N") + extension; if (bytes.Length == 0) fileName = ""; return new DownloadImage() { date = DateTime.Now, image = bytes, size = bytes.Length, url = wire.Url, filename = fileName }; }
private static HtmlDocument GetDocument(IHttpRequestFactory factory, IHttpWire wire, out int length) { var request = CreateRequest(factory, wire); var bytes = request.Download(); string html = string.Empty; length = bytes.Length; html = Encoding.UTF8.GetString(bytes, 0, bytes.Length); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); return doc; }
public static async Task <byte[]?> TryGetBytesAsync(this IHttpRequestFactory httpRequestFactory, string url, TimeoutSpecification timeout = default) { if (url == null) { throw new ArgumentNullException(nameof(url)); } var response = await httpRequestFactory.Get(url.ToUrl()).SendAsync(timeout, IgnoreNotFoundApiErrors).ConfigureAwait(false); return(response.Status.IsNotFound ? default : await response.GetBytesAsync().ConfigureAwait(false)); }
public static Runable Compile(string code, IHttpRequestFactory requestFactory) { var compiler = new Compiler(code); var assembly = compiler.ToAssembly(); Assert.IsTrue(compiler.Errors.Count == 0); var runable = new Runable(assembly); if (requestFactory != null) { runable.SetRequestFactory(requestFactory); } return(runable); }
private static HtmlDocument GetDocument(IHttpRequestFactory factory, string url, out int length) { var request = CreateRequest(factory, url); var bytes = request.Download(); string html = string.Empty; length = bytes.Length; html = Encoding.UTF8.GetString(bytes, 0, bytes.Length); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); return(doc); }
public void Setup() { _fakeFactory = Substitute.For <IHttpRequestFactory>(); _fakeBuilder = Substitute.For <IHttpRequestBuilder>(); _fakeBuilder.SendAsync().Returns(new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest }); _fakeBuilder.AddAuthentication(Arg.Any <string>(), Arg.Any <string>()).Returns(_fakeBuilder); _userFake = Substitute.For <IUser>(); _userFake.Username = "******"; _userFake.Password = "******"; _userFake.GivenName = "TestMansen"; _userFake.LastName = "Swagattack"; _userFake.Email = "*****@*****.**"; }
public ExternClientServices( ContentManagementOptions contentManagementOptions, IHttpRequestFactory http, IJsonSerializer jsonSerializer, IExternHttpClient api, IPollingStrategy longOperationsPollingStrategy, IAuthenticator authenticator, ICrypt crypt) { Http = http ?? throw new ArgumentNullException(nameof(http)); JsonSerializer = jsonSerializer ?? throw new ArgumentNullException(nameof(jsonSerializer)); Api = api ?? throw new ArgumentNullException(nameof(api)); LongOperationsPollingStrategy = longOperationsPollingStrategy ?? throw new ArgumentNullException(nameof(longOperationsPollingStrategy)); Authenticator = authenticator ?? throw new ArgumentNullException(nameof(authenticator)); Crypt = crypt ?? throw new ArgumentNullException(nameof(crypt)); ContentService = new ContentService(api.Contents, contentManagementOptions); }
private static DownloadImage GetImage(IHttpRequestFactory factory, string url) { var request = CreateRequest(factory, url); var bytes = request.Download(); string extension = Path.GetExtension(url); string fileName = Guid.NewGuid().ToString("N") + extension; if (bytes.Length == 0) { fileName = ""; } return(new DownloadImage() { date = DateTime.Now, image = bytes, size = bytes.Length, url = url, filename = fileName }); }
private static RuntimeTable <DynamicObject> ProcesJson(IHttpRequestFactory factory, IHttpWire wire) { var request = CreateRequest(factory, wire); var json = request.Download() as string; if (json == null) { json = string.Empty; } dynamic serializedValue = JsonConvert.DeserializeObject(json); var dynamics = new List <DynamicObject>(); if (serializedValue != null && serializedValue is IEnumerable <dynamic> ) { IEnumerable <dynamic> jsonArray = serializedValue; if (!(serializedValue is JArray)) { jsonArray = new[] { serializedValue } } ; var properties = new List <Dictionary <string, object> >(); foreach (dynamic v in jsonArray) { var dynamic = new DynamicObject(); Dictionary <string, object> values = v.ToObject <Dictionary <string, object> >(); foreach (var p in values.Keys) { dynamic.Add(p, values[p].ToString()); } dynamics.Add(dynamic); } } var table = new RuntimeTable <DynamicObject>(); table.SetRows(dynamics); return(table); }
private static HtmlDoc GetDocument(IHttpRequestFactory factory, IHttpWire wire, out int length) { var request = CreateRequest(factory, wire); var bytes = request.Download() as byte[]; if (bytes == null) { bytes = new byte[0]; } string html = string.Empty; length = bytes.Length; html = Encoding.UTF8.GetString(bytes, 0, bytes.Length); HtmlDoc doc = Config.DomFactory.Create(); doc.Load(html); return(doc); }
public TentClientFactory( IHttpRequestFactory httpRequestFactory, IHttpClientFactory httpClientFactory, IQueryStringHelpers queryStringHelpers, IBewitLogic bewitLogic, IUriHelpers uriHelpers, ITentConstants tentConstants) { Ensure.Argument.IsNotNull(httpRequestFactory, nameof(httpRequestFactory)); Ensure.Argument.IsNotNull(httpClientFactory, nameof(httpClientFactory)); Ensure.Argument.IsNotNull(queryStringHelpers, nameof(queryStringHelpers)); Ensure.Argument.IsNotNull(bewitLogic, nameof(bewitLogic)); Ensure.Argument.IsNotNull(uriHelpers, nameof(uriHelpers)); Ensure.Argument.IsNotNull(tentConstants, nameof(tentConstants)); this.httpRequestFactory = httpRequestFactory; this.httpClientFactory = httpClientFactory; this.queryStringHelpers = queryStringHelpers; this.bewitLogic = bewitLogic; this.uriHelpers = uriHelpers; this.tentConstants = tentConstants; }
private static DownloadImage GetImage(IHttpRequestFactory factory, IHttpWire wire) { var request = CreateRequest(factory, wire); var bytes = request.Download() as byte[]; if (bytes == null) { bytes = new byte[0]; } string extension = Path.GetExtension(wire.Url); string fileName = Guid.NewGuid().ToString("N") + extension; if (bytes.Length == 0) { fileName = ""; } return(new DownloadImage() { date = DateTime.Now, image = bytes, size = bytes.Length, url = wire.Url, filename = fileName }); }
protected abstract IHttpRequest MakeRequestForCommonTests(IHttpRequestFactory http);
public CF_Client(IHttpRequestFactory http_factory) : base(http_factory) { }
public static Task <TResponseDto?> TryGetAsync <TResponseDto>(this IHttpRequestFactory httpRequestFactory, string url, in TimeoutSpecification timeout = default)
public Client(IHttpRequestFactory http_factory) : base(http_factory) { _http_factory = http_factory; }
public AlbumService(IHttpRequestFactory httpRequestFactory) { _httpRequestFactory = httpRequestFactory; }
public RestClient(IHttpRequestFactory requestFactory, string uriFormat, RestService service) : this(requestFactory, service) { _uriFormat = uriFormat; }
/// <summary> /// Initializes a new instance of the <see><cref>Openstack.Swift.Client</cref></see> class. /// </summary> public SwiftClient() { _http_factory = new HttpRequestFactory(); }
public SwiftClient(int timeout, int chunkSize) { Timeout = timeout; ChunkSize = chunkSize; _http_factory = new HttpRequestFactory(); }
/// <summary> /// The constructor for HttpHandler. /// </summary> /// <param name="requestFactory">The request factory used to create HTTP Requests.</param> /// <param name="callbackSender">The sender parameter used in any events raised by this handler.</param> public HttpHandler(IHttpRequestFactory <TRequestContent> requestFactory, object callbackSender) { _requestFactory = requestFactory; this.CallbackSender = callbackSender; }
public Anchor(HttpClient httpClient, IHttpRequestFactory httpRequestBuilder, IHttpResponseParser httpResponseParser) { HttpClient = httpClient; HttpRequestBuilder = httpRequestBuilder; HttpResponseParser = httpResponseParser; }
public HttpVerbRequestBuilder(IHttpRequestFactory requestFactory) { _requestFactory = requestFactory; ParametersStore = new ParametersStore(); }
private RestClient(IHttpRequestFactory requestFactory, string uriFormat, RestService service, string operationGroup, Dictionary<string, object> inheritedParameters) : this(requestFactory, uriFormat, service) { _operationGroup = operationGroup; _parameters = inheritedParameters; }
protected override IHttpRequest MakeRequestForCommonTests(IHttpRequestFactory http) => http.Get("/some-resource");
private static IHttpRequest CreateRequest(IHttpRequestFactory factory, IHttpWire wire) { return factory.Create(wire); }
private void BuildRuntimePipeline() { #if BCL || BCL45 var httpRequestFactory = new HttpWebRequestFactory(new AmazonSecurityProtocolManager()); var httpHandler = new HttpHandler <Stream>(httpRequestFactory, this); #elif UNITY IHttpRequestFactory <string> httpRequestFactory = null; HttpHandler <string> httpHandler = null; if (AWSConfigs.HttpClient == AWSConfigs.HttpClientOption.UnityWWW) { httpRequestFactory = new UnityWwwRequestFactory(); httpHandler = new HttpHandler <string>(httpRequestFactory, this); } else { httpRequestFactory = new UnityWebRequestFactory(); httpHandler = new HttpHandler <string>(httpRequestFactory, this); } #else var httpRequestFactory = new HttpRequestMessageFactory(this.Config); var httpHandler = new HttpHandler <System.Net.Http.HttpContent>(httpRequestFactory, this); #endif var preMarshallHandler = new CallbackHandler(); preMarshallHandler.OnPreInvoke = this.ProcessPreRequestHandlers; var postMarshallHandler = new CallbackHandler(); postMarshallHandler.OnPreInvoke = this.ProcessRequestHandlers; var postUnmarshallHandler = new CallbackHandler(); postUnmarshallHandler.OnPostInvoke = this.ProcessResponseHandlers; var errorCallbackHandler = new ErrorCallbackHandler(); errorCallbackHandler.OnError = this.ProcessExceptionHandlers; // Build default runtime pipeline. this.RuntimePipeline = new RuntimePipeline(new List <IPipelineHandler> { httpHandler, new Unmarshaller(this.SupportResponseLogging), new ErrorHandler(_logger), postUnmarshallHandler, new Signer(), new CredentialsRetriever(this.Credentials), new RetryHandler(new DefaultRetryPolicy(this.Config)), postMarshallHandler, new EndpointResolver(), new Marshaller(), preMarshallHandler, errorCallbackHandler, new MetricsHandler() #if UNITY , new ThreadPoolExecutionHandler(10) //remove the hardcoded to unity config #endif }, _logger ); #if BCL || CORECLR if (DeterminedCSMConfiguration.Instance.CSMConfiguration.Enabled && !string.IsNullOrEmpty(ServiceMetadata.ServiceId)) { this.RuntimePipeline.AddHandlerBefore <ErrorHandler>(new CSMCallAttemptHandler()); this.RuntimePipeline.AddHandlerBefore <MetricsHandler>(new CSMCallEventHandler()); } #endif CustomizeRuntimePipeline(this.RuntimePipeline); // Apply global pipeline customizations RuntimePipelineCustomizerRegistry.Instance.ApplyCustomizations(this.GetType(), this.RuntimePipeline); }
public void SetRequestFactory(IHttpRequestFactory requestFactory) { _instance.RequestFactory = requestFactory; }
/// <summary> /// Initializes a new instance of the <see><cref>Openstack.Swift.Client</cref></see> class. /// </summary> /// <param name='http_factory'> /// Implement the <see><cref>Openstack.Swift.IHttpRequestFactory</cref></see> interface for a custom HttpRequestFactory. /// </param> public SwiftClient(IHttpRequestFactory http_factory) { _http_factory = http_factory; }
public RestClient(IHttpRequestFactory requestFactory, RestService service) { _requestFactory = requestFactory; _service = service; }
public TemplatedUriRequestBuilder(IHttpRequestFactory requestFactory) { _requestFactory = requestFactory; ParametersStore = new ParametersStore(); }
public WebCommunication(IHttpRequestFactory httpRequestFactory) { _httpRequestFactory = httpRequestFactory; }