Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new instance of a ChesService, initializes with specified arguments.
 /// </summary>
 /// <param name="options"></param>
 /// <param name="user"></param>
 /// <param name="client"></param>
 /// <param name="tokenHandler"></param>
 public ChesService(IOptions <ChesOptions> options, ClaimsPrincipal user, IHttpRequestClient client, JwtSecurityTokenHandler tokenHandler)
 {
     this.Options  = options.Value;
     _user         = user;
     this.Client   = client;
     _tokenHandler = tokenHandler;
 }
Ejemplo n.º 2
0
 public TestBuilder(string uri, IHttpRequestClient client, bool useCamelCase = false)
 {
     this.request            = new HttpRequestMessage();
     this.request.RequestUri = new Uri(uri, UriKind.Relative);
     this.client             = client;
     this.assertions         = new List <Action>();
     this.useCamelCase       = useCamelCase;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new instance of a GeocoderService, initializes with specified arguments.
 /// </summary>
 /// <param name="options"></param>
 /// <param name="client"></param>
 public GeocoderService(IOptions <GeocoderOptions> options, IHttpRequestClient client)
 {
     this.Options = options.Value;
     this.Client  = client;
     if (!String.IsNullOrWhiteSpace(this.Options.Key))
     {
         client.Client.DefaultRequestHeaders.Add("apikey", this.Options.Key);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new instance of a LtsaService, initializes with specified arguments.
 /// </summary>
 /// <param name="options"></param>
 /// <param name="client"></param>
 /// <param name="tokenHandler"></param>
 /// <param name="logger"></param>
 /// <param name="serializerOptions"></param>
 public LtsaService(IOptions <LtsaOptions> options, IHttpRequestClient client, ILogger <ILtsaService> logger, IOptions <JsonSerializerOptions> serializerOptions)
 {
     this.Options           = options.Value;
     this.Client            = client;
     _logger                = logger;
     _jsonSerializerOptions = serializerOptions.Value;
     _authPolicy            = Policy
                              .Handle <HttpClientRequestException>(ex => ex.StatusCode == HttpStatusCode.Forbidden || ex.StatusCode == HttpStatusCode.Unauthorized)
                              .RetryAsync(async(exception, retryCount) =>
     {
         _token = await RefreshAccessTokenAsync();
         this.Client.Client?.DefaultRequestHeaders?.Clear();
         this.Client.Client?.DefaultRequestHeaders?.Add("X-Authorization", $"Bearer {_token.AccessToken}");
     });
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a new instance of an LtsaException class, initializes it with the specified arguments.
 /// </summary>
 /// <param name="exception"></param>
 /// <param name="client"></param>
 /// <param name="error"></param>
 public LtsaException(HttpClientRequestException exception, IHttpRequestClient client, Error error)
     : base($"{exception.Message}{Environment.NewLine}", exception, exception.StatusCode.Value)
 {
     if (exception?.Response?.Content != null)
     {
         if (error?.ErrorMessages?.Count > 0)
         {
             this.Detail = String.Join(Environment.NewLine, error.ErrorMessages.Select(e => $"\t{e}"));
         }
     }
     else
     {
         this.Client = client;
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Instantiate a new <see cref="MegaApiClient" /> object with the provided <see cref="IHttpRequestClient" />
        /// </summary>
        public MegaApiClient(IHttpRequestClient webClient)
        {
            if (webClient == null)
            {
                throw new ArgumentNullException("webClient");
            }

            this.webClient      = webClient;
            this.BufferSize     = DefaultBufferSize;
            this.ChunksPackSize = DefaultChunksPackSize;

#if NET45
            this.ReportProgressChunkSize = DefaultReportProgressChunkSize;
#endif
        }
Ejemplo n.º 7
0
        public AssertionTests()
        {
            request            = new HttpRequestMessage();
            message            = new HttpResponseMessage();
            message.StatusCode = HttpStatusCode.OK;
            message.Content    = new StringContent("Hello World");
            message.Headers.Add("TestHeader", "Test");

            user = new User {
                Name = "Peter", Age = 32, Id = 1
            };

            clientMock = new Mock <IHttpRequestClient>();
            clientMock.Setup(c => c.AsyncMakeRequest(It.IsAny <HttpRequestMessage>())).ReturnsAsync(() => message);

            client = clientMock.Object;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new instances of a FileStationApi object, initializes with specified arguments.
 /// </summary>
 /// <param name="options"></param>
 /// <param name="httpClient"></param>
 /// <param name="logger"></param>
 public FileStationApi(IOptionsMonitor <Options.SynologyOptions> options, IHttpRequestClient httpClient, ILogger <FileStationApi> logger)
 {
     _options = options.CurrentValue;
     _client  = httpClient;
     _logger  = logger;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Create an instance of an ITestBuilder implementation
 /// </summary>
 /// <param name="url">The url for the test builder</param>
 /// <param name="client">The http client to use for making http requests.</param>
 /// <param name="useCamelCase">Formatter setting for whether or not to use camel casing</param>
 /// <returns>An instance of an ITestBuilder implementation</returns>
 public static ITestBuilder Create(string url, IHttpRequestClient client, bool useCamelCase = false)
 {
     return(new TestBuilder(url, client, useCamelCase));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Creates a new instance of an ChesException class, initializes it with the specified arguments.
 /// </summary>
 /// <param name="exception"></param>
 /// <param name="client"></param>
 /// <param name="model"></param>
 public ChesException(HttpClientRequestException exception, IHttpRequestClient client, ErrorResponseModel model)
     : this($"{exception.Message}{Environment.NewLine}", exception, exception.StatusCode)
 {
     this.Client = client;
     this.Detail = $"{model.Title}{Environment.NewLine}{model.Detail}{Environment.NewLine}{model.Type}{Environment.NewLine}{String.Join(Environment.NewLine, model.Errors.Select(e => $"\t{e.Message}"))}";
 }
Ejemplo n.º 11
0
 public TestClient(string serverName)
 {
     _server = ServerFactory.Instance.Build(serverName);
     _client = _server.GetClient();
     _requestBuilder = new RequestBuilder();
 }