public async Task TestPropertiesWhenInvalidHost()
        {
            HttpCall call = await HttpCall.CreateGet("http://bogus").ExecuteAsync();

            Assert.IsTrue(call.Executed);
            Assert.IsFalse(call.Success);
            Assert.IsNotNull(call.Error);
        }
Пример #2
0
        public void TestPropertiesWhenInvalidHost()
        {
            HttpCall call = HttpCall.CreateGet("http://bogus").Execute().Result;

            Assert.IsTrue(call.Executed);
            Assert.IsFalse(call.Success);
            Assert.IsNotNull(call.Error);
        }
Пример #3
0
        public void TestPropertiesWhenNotExecuted()
        {
            HttpCall call = HttpCall.CreateGet("http://www.google.com");

            Assert.IsFalse(call.Executed);
            Assert.IsFalse(call.HasResponse);
            AssertThrows <InvalidOperationException>(() => { bool x = call.Success; });
            AssertThrows <InvalidOperationException>(() => { Exception x = call.Error; });
            AssertThrows <InvalidOperationException>(() => { string x = call.ResponseBody; });
        }
Пример #4
0
        /// <summary>
        ///     Async method to execute the HTTP request which expects the HTTP response body to be a Json object that can be
        ///     deserizalized as an instance of type T
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public async Task <T> ExecuteAndDeserialize <T>()
        {
            HttpCall call = await Execute().ConfigureAwait(false);

            if (call.Success)
            {
                return(JsonConvert.DeserializeObject <T>(call.ResponseBody));
            }
            throw call.Error;
        }
Пример #5
0
        public void TestPropertiesWhenExecuted()
        {
            HttpCall call = HttpCall.CreateGet("http://www.google.com").Execute().Result;

            Assert.IsTrue(call.Executed);
            Assert.IsTrue(call.HasResponse);
            Assert.IsTrue(call.Success);
            Assert.IsNull(call.Error);
            Assert.IsTrue(call.ResponseBody.Contains("Google Search"));
            Assert.AreEqual(HttpStatusCode.Ok, call.StatusCode);
        }
Пример #6
0
 /// <summary>
 /// Async method to execute the HTTP request which expects the HTTP response body to be a Json object that can be deserizalized as an instance of type T
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public async Task <T> ExecuteAndDeserialize <T>()
 {
     return(await Execute().ContinueWith(t =>
     {
         HttpCall call = t.Result;
         if (call.Success)
         {
             return JsonConvert.DeserializeObject <T>(call.ResponseBody);
         }
         else
         {
             throw call.Error;
         }
     }));
 }
Пример #7
0
        /// <summary>
        ///     Async method to execute the HTTP request which expects the HTTP response body to be a Json object that can be
        ///     deserizalized as an instance of type T
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public async Task <T> ExecuteAndDeserialize <T>()
        {
            HttpCall call = await Execute().ConfigureAwait(false);

            if (call.Success)
            {
                return(JsonConvert.DeserializeObject <T>(call.ResponseBody));
            }
            else
            {
                if (!String.IsNullOrWhiteSpace(call.ResponseBody))//try to handle refresh token expired
                {
                    JObject error     = JObject.Parse(call.ResponseBody);
                    var     errorType = error.Property("error");
                    if (errorType != null && errorType.Value.ToString() == "invalid_grant") //refresh token has expired
                    {
                        var errorMessage = error.Property("error_description");
                        throw new OAuthException("invalid_grant", call.Error);
                    }
                }
                //TODO: throws exception that goes up and is not caught
                throw call.Error;
            }
        }