示例#1
0
        protected void AssertNoError(ODataResponse response)
        {
            var error = GetError(response, false);

            if (error != null)
            {
                Assert.Fail(error.Message);
            }
        }
示例#2
0
        protected static ODataErrorResponse GetError(ODataResponse response, bool throwOnError = true)
        {
            var text = response.Result;

            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            var json = Deserialize(text);

            if (json == null)
            {
                if (throwOnError)
                {
                    throw new InvalidOperationException("Deserialized text is null.");
                }
                return(null);
            }

            if (json is JArray)
            {
                if (throwOnError)
                {
                    throw new InvalidOperationException("Object is not an error");
                }
                return(null);
            }

            if (!(json["error"] is JObject error))
            {
                if (throwOnError)
                {
                    throw new Exception("Object is not an error");
                }
                return(null);
            }

            var code          = error["code"]?.Value <string>() ?? string.Empty;
            var exceptionType = error["exceptiontype"]?.Value <string>() ?? string.Empty;
            var message       = error["message"] as JObject;
            var value         = message?["value"]?.Value <string>() ?? string.Empty;
            var innerError    = error["innererror"] as JObject;
            var trace         = innerError?["trace"]?.Value <string>() ?? string.Empty;

            Enum.TryParse <ODataExceptionCode>(code, out var oeCode);
            return(new ODataErrorResponse {
                Code = oeCode, ExceptionType = exceptionType, Message = value, StackTrace = trace
            });
        }
示例#3
0
        protected static ODataEntitiesResponse GetEntities(ODataResponse response)
        {
            var text = response.Result;

            var result = new List <ODataEntityResponse>();
            var jo     = (JObject)Deserialize(text);
            var d      = (JObject)jo["d"];
            var count  = d["__count"].Value <int>();
            var jarray = (JArray)d["results"];

            for (int i = 0; i < jarray.Count; i++)
            {
                result.Add(ODataEntityResponse.Create((JObject)jarray[i]));
            }
            return(new ODataEntitiesResponse(result.ToList(), count));
        }
示例#4
0
 protected static JObject GetObject(ODataResponse response)
 {
     return((JObject)Deserialize(response.Result));
 }