示例#1
0
        internal async Task<SimpleHttpResponse> SendAsync(SimpleHttpClient client, int expectedReturnStatus)
        {
            var result = await client.SendAsync();

            if (((int)result.StatusCode) != expectedReturnStatus)
            {
                // Check if we can deserialize the response
                CloudFoundryException cloudFoundryException;
                try
                {
                    string response = await result.Content.ReadAsStringAsync();
                    var exceptionObject = Utilities.DeserializeJson<CloudFoundryExceptionObject>(response);
                    cloudFoundryException = new CloudFoundryException(exceptionObject);
                    cloudFoundryException.Response = result;
                    throw cloudFoundryException;
                }
                catch (CloudFoundryException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new CloudFoundryException(string.Format(CultureInfo.InvariantCulture, "An error occurred while talking to the server ({0})", result.StatusCode), ex);
                }
            }

            return result;
        }
        public void TestException()
        {
            CloudFoundryExceptionObject exceptionObject = new CloudFoundryExceptionObject();
            exceptionObject.Code = "object";
            exceptionObject.Description = "this is an exception";
            exceptionObject.ErrorCode = "errorCode";

            CloudFoundryException exception = new CloudFoundryException(exceptionObject);

            Assert.AreEqual(exception.Message, "this is an exception");
        }