Beispiel #1
0
        public void SetConfiguration(EndpointConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (configuration.EndpointUri == null || !configuration.EndpointUri.IsAbsoluteUri)
            {
                throw new ArgumentException("The endpoint must be a valid absolute URI");
            }

            if (configuration.Version == null || !configuration.Version.IsSupported())
            {
                string supportedVersions = string.Join(", ", XApiVersion.SUPPORTED_VERSIONS);
                throw new ArgumentException($"Version is not supported. Supported versions are: {supportedVersions}");
            }

            this._useOwnHttpClient = (configuration.HttpClient == null);
            this._httpClient       = configuration.HttpClient ?? new HttpClient();
            this._baseUri          = configuration.EndpointUri;
            this._version          = configuration.Version;

            this._authenticator = configuration.GetAuthenticator();
        }
Beispiel #2
0
        public void SetUpHttpClient()
        {
            this._mockHttp = new MockHttpMessageHandler();
            EndpointConfiguration config = this.GetEndpointConfiguration();

            config.EndpointUri = new Uri(ENDPOINT_URI);
            config.Version     = XApiVersion.Parse(VERSION);
            config.HttpClient  = this._mockHttp.ToHttpClient();
            this._client       = XApiClientFactory.Create(config);
        }
Beispiel #3
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     if (reader.TokenType == JsonToken.Null)
     {
         return(null);
     }
     else if (reader.TokenType == JsonToken.String)
     {
         try
         {
             return(XApiVersion.Parse((string)reader.Value));
         }
         catch (Exception ex)
         {
             throw new JsonSerializationException($"Error parsing version string: {reader.Value}", ex);
         }
     }
     else
     {
         throw new JsonSerializationException($"Unexpected token or value when parsing version. Token: {reader.TokenType}, Value: {reader.Value}");
     }
 }