Example #1
0
        /// <summary>
        /// Verifies the extension rule.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if rule passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            Uri      metadataServiceUrl = new Uri(context.Destination.AbsoluteUri.TrimEnd('/') + @"/$metadata" + @"/");
            var      req      = WebRequest.Create(metadataServiceUrl) as HttpWebRequest;
            Response response = WebHelper.Get(req, RuleEngineSetting.Instance().DefaultMaximumPayloadSize);
            ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name, metadataServiceUrl.AbsoluteUri, "GET", string.Empty, response);

            if (response != null && response.StatusCode == HttpStatusCode.OK && response.ResponsePayload.IsMetadata())
            {
                passed = true;
            }
            else
            {
                passed = false;
                detail.ErrorMessage = "The response is not the metadata service document. Please refer to section 15 of [OData-CSDL].";
            }

            info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
            return(passed);
        }
Example #2
0
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus = ServiceStatus.GetInstance();
            string url       = svcStatus.RootURL + "?$format=application/json";
            var    resp      = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);
            var    detail    = new ExtensionRuleResultDetail("ServiceImpl_SystemQueryOptionFormat", url, HttpMethod.Get, string.Empty);

            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                passed = resp.ResponsePayload.IsJsonLightSvcDoc();
            }
            else
            {
                passed = false;
            }

            return(passed);
        }
        /// <summary>
        /// Verifies the extension rule.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if rule passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            string   url      = string.Format("{0}/?$find=*", context.Destination);
            var      req      = WebRequest.Create(url) as HttpWebRequest;
            Response response = WebHelper.Get(req, RuleEngineSetting.Instance().DefaultMaximumPayloadSize);
            ExtensionRuleResultDetail detail1 = new ExtensionRuleResultDetail(this.Name, url, "GET", string.Empty, response);

            if (response != null && response.StatusCode != null)
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    passed = true;
                }
                else
                {
                    passed = false;
                    detail1.ErrorMessage = "Services SHOULD fail the above URI because it contains query options 'find' which services does not understand.";
                }
            }
            else
            {
                passed = false;
                detail1.ErrorMessage = "No response returned from above URI.";
            }

            info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail1);
            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            //var svcStatus = ServiceStatus.GetInstance();
            var svcStatus = ServiceStatus.GetInstance(context.ServiceBaseUri.OriginalString, context.ResponseHttpHeaders.Replace("\r\n", ";"));

            string url    = svcStatus.RootURL.TrimEnd('/') + @"/$metadata";
            var    detail = new ExtensionRuleResultDetail(this.Name, url, HttpMethod.Get, string.Empty);

            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);

            if (!string.IsNullOrEmpty(context.MetadataDocument))
            {
                passed = true;
            }
            else
            {
                passed = false;
            }

            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus     = ServiceStatus.GetInstance();
            var    entitySetUrls = MetadataHelper.GetEntitySetURLs();
            var    entitySetUrl  = entitySetUrls[0];
            string url           = svcStatus.RootURL.TrimEnd('/') + "/" + entitySetUrl;
            int    actualNum     = JsonParserHelper.GetEntitiesCountFromFeed(url, svcStatus.DefaultHeaders);

            url = string.Format("{0}?$skip={1}", url, actualNum - 1);
            var resp   = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);
            var detail = new ExtensionRuleResultDetail("ServiceImpl_SystemQueryOptionSkip", url, HttpMethod.Get, string.Empty);

            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                JObject jObj = JObject.Parse(resp.ResponsePayload);
                JArray  jArr = jObj.GetValue("value") as JArray;
                passed = 1 == jArr.Count;
            }
            else
            {
                passed = false;
            }

            return(passed);
        }
Example #6
0
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var svcStatus = ServiceStatus.GetInstance();

            string url    = svcStatus.RootURL.TrimEnd('/');
            var    detail = new ExtensionRuleResultDetail(this.Name, url, HttpMethod.Get, string.Empty);

            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);

            if (!string.IsNullOrEmpty(context.ServiceDocument))
            {
                passed = true;
            }
            else
            {
                passed = false;
            }

            return(passed);
        }
        /// <summary>
        /// Verifies the extension rule.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if rule passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed   = null;
            var  response = WebHelper.Get(context.Destination, string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);
            ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name, context.Destination.AbsoluteUri, "GET", StringHelper.MergeHeaders(string.Empty, context.RequestHeaders), response);

            if (response != null && response.StatusCode != null)
            {
                if (context.PayloadFormat == RuleEngine.PayloadFormat.JsonLight)
                {
                    passed = true;
                }
                else
                {
                    passed = false;
                    detail.ErrorMessage = "Get above URI with accept header 'application/json', the response is not JSON format.";
                }
            }
            else
            {
                passed = false;
                detail.ErrorMessage = String.Format("No response returned from above URI with accept header 'application/json'.");
            }

            info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus = ServiceStatus.GetInstance();
            string entityTypeShortName;
            var    propTypes = new string[2] {
                "Edm.Date", "Edm.DateTimeOffset"
            };
            var propNames = MetadataHelper.GetPropertyNames(propTypes, out entityTypeShortName);

            if (null == propNames || !propNames.Any())
            {
                return(passed);
            }

            string propName     = propNames[0];
            var    entitySetUrl = entityTypeShortName.GetAccessEntitySetURL();

            if (string.IsNullOrEmpty(entitySetUrl))
            {
                return(passed);
            }

            string url  = svcStatus.RootURL.TrimEnd('/') + "/" + entitySetUrl;
            var    resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);

            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                JObject jObj    = JObject.Parse(resp.ResponsePayload);
                JArray  jArr    = jObj.GetValue(Constants.Value) as JArray;
                var     entity  = jArr.First as JObject;
                var     propVal = Convert.ToDateTime(entity[propName]).Minute;
                url  = string.Format("{0}?$filter=minute({1}) eq {2}", url, propName, propVal);
                resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);
                var detail = new ExtensionRuleResultDetail(this.Name, url, HttpMethod.Get, string.Empty);
                info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
                if (null != resp && HttpStatusCode.OK == resp.StatusCode)
                {
                    jObj = JObject.Parse(resp.ResponsePayload);
                    jArr = jObj.GetValue(Constants.Value) as JArray;
                    foreach (JObject et in jArr)
                    {
                        passed = Convert.ToDateTime(et[propName]).Minute == propVal;
                    }
                }
                else
                {
                    passed = false;
                }
            }

            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus = ServiceStatus.GetInstance();
            string entityTypeShortName;
            var    propNames = MetadataHelper.GetPropertyNames("Edm.String", out entityTypeShortName);

            if (null == propNames || !propNames.Any())
            {
                return(passed);
            }

            string propName     = propNames[0];
            var    entitySetUrl = entityTypeShortName.MapEntityTypeShortNameToEntitySetURL();
            string url          = svcStatus.RootURL.TrimEnd('/') + "/" + entitySetUrl;
            var    resp         = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);

            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                JObject jObj    = JObject.Parse(resp.ResponsePayload);
                JArray  jArr    = jObj.GetValue(Constants.Value) as JArray;
                var     entity  = jArr.First as JObject;
                var     propVal = entity[propName].ToString();
                string  subStr  = propVal.Substring(propVal.Length / 2);
                url  = string.Format("{0}?$filter=contains({1}, '{2}')", url, propName, subStr);
                resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);
                var detail = new ExtensionRuleResultDetail(this.Name, url, HttpMethod.Get, string.Empty);
                detail.URI                = url;
                detail.ResponsePayload    = resp.ResponsePayload;
                detail.ResponseHeaders    = resp.ResponseHeaders;
                detail.HTTPMethod         = "GET";
                detail.ResponseStatusCode = resp.StatusCode.ToString();

                info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
                if (null != resp && HttpStatusCode.OK == resp.StatusCode)
                {
                    jObj = JObject.Parse(resp.ResponsePayload);
                    jArr = jObj.GetValue(Constants.Value) as JArray;
                    foreach (JObject et in jArr)
                    {
                        passed = et[propName].ToString().Contains(subStr);
                    }
                }
                else
                {
                    passed = false;
                    detail.ErrorMessage = "The server returned an error response:  " + detail.ResponseStatusCode;
                }
            }

            return(passed);
        }
Example #10
0
        /// <summary>
        /// Verifies the extension rule.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if rule passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?  passed             = null;
            string selectedName       = string.Empty;
            string functionactionName = "forFunctionAction";

            // Use the XPath query language to access the metadata document and get all Namespace and Alias value.
            XElement      metadata             = XElement.Parse(context.MetadataDocument);
            string        xpath                = @"//*[local-name()='DataServices']/*[local-name()='Schema']";
            List <string> appropriateNamespace = MetadataHelper.GetPropertyValues(context, xpath, "Namespace");

            // Use the XPath query language to access the metadata document and get all Function names and all Action names.
            xpath = @"//*[local-name()='EntityContainer']/*[local-name()='FunctionImport']";
            List <string> functionImportNames = MetadataHelper.GetPropertyValues(context, xpath, "Name");

            xpath = @"//*[local-name()='EntityContainer']/*[local-name()='ActionImport']";
            List <string> actionImportNames = MetadataHelper.GetPropertyValues(context, xpath, "Name");

            if (!functionImportNames.Contains(functionactionName) && !actionImportNames.Contains(functionactionName))
            {
                selectedName = functionactionName;
            }
            else
            {
                selectedName = functionactionName + "New";
            }

            string url = string.Format("{0}/?$select={1}.{2}", context.Destination.ToString().TrimEnd('/'), appropriateNamespace[0], selectedName);
            //var req = WebRequest.Create(url) as HttpWebRequest;
            //var response = WebHelper.Get(req, RuleEngineSetting.Instance().DefaultMaximumPayloadSize);//REPLACE HEADER
            var response = WebHelper.Get(url, null, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);
            ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name, url, "GET", string.Empty, response);

            if (response != null && response.StatusCode != null)
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    passed = true;
                }
                else
                {
                    passed = false;
                    detail.ErrorMessage = "The OData service MUST fail any request that contains actions or functions that it does not understand.";
                }
            }
            else
            {
                passed = false;
                detail.ErrorMessage = String.Format("No response returned from above URI.");
            }

            info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus = ServiceStatus.GetInstance();
            string entityTypeShortName;
            var    keyProp = MetadataHelper.GetKeyProperty(out entityTypeShortName);

            if (null == keyProp)
            {
                return(passed);
            }

            string keyPropName = keyProp.Item1;
            string keyPropType = keyProp.Item2;

            if (string.IsNullOrEmpty(entityTypeShortName) || string.IsNullOrEmpty(keyPropName) || string.IsNullOrEmpty(keyPropType))
            {
                return(passed);
            }

            string entitySetUrl = entityTypeShortName.MapEntityTypeShortNameToEntitySetURL();
            string url          = svcStatus.RootURL.TrimEnd('/') + "/" + entitySetUrl;
            var    resp         = WebHelper.Get(new Uri(url), Constants.V4AcceptHeaderJsonFullMetadata, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);

            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                var jObj = JObject.Parse(resp.ResponsePayload);
                var jArr = jObj.GetValue("value") as JArray;
                var temp = ((JObject)(jArr.First))[keyPropName];
                if (null == temp)
                {
                    return(passed);
                }

                var    keyPropVal = temp.ToString();
                string pattern    = "Edm.String" == keyPropType ? "{0}('{1}')/{2}/$value" : "{0}({1})/{2}/$value";
                url  = string.Format(pattern, url, keyPropVal, keyPropName);
                resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);
                var detail = new ExtensionRuleResultDetail("ServiceImpl_SystemQueryOptionValue", url, HttpMethod.Get, string.Empty);
                info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
                if (null != resp && HttpStatusCode.OK == resp.StatusCode)
                {
                    passed = resp.ResponsePayload == keyPropVal;
                }
                else
                {
                    passed = false;
                }
            }

            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus = ServiceStatus.GetInstance();
            string entityTypeShortName;
            var    propNames = MetadataHelper.GetPropertyNames(
                "Edm.String",
                out entityTypeShortName,
                2,
                (elem) => {
                return(!(null != elem.Attribute("MaxLength") && elem.GetAttributeValue("MaxLength") == "max"));
            });

            if (null == propNames || propNames.Count < 2)
            {
                return(passed);
            }

            string propName1    = propNames[0];
            string propName2    = propNames[1];
            var    entitySetUrl = entityTypeShortName.MapEntityTypeShortNameToEntitySetURL();
            string url          = svcStatus.RootURL.TrimEnd('/') + "/" + entitySetUrl;
            var    resp         = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);

            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                JObject jObj     = JObject.Parse(resp.ResponsePayload);
                JArray  jArr     = jObj.GetValue(Constants.Value) as JArray;
                var     entity   = jArr.First as JObject;
                var     propVal1 = entity[propName1].ToString();
                var     propVal2 = entity[propName2].ToString();
                url  = string.Format("{0}?$filter=concat(concat({1}, ': '), {2}) eq '{3}: {4}'", url, propName1, propName2, propVal1, propVal2);
                resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);
                var detail = new ExtensionRuleResultDetail(this.Name, url, HttpMethod.Get, string.Empty);
                info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
                if (null != resp && HttpStatusCode.OK == resp.StatusCode)
                {
                    jObj = JObject.Parse(resp.ResponsePayload);
                    jArr = jObj.GetValue(Constants.Value) as JArray;
                    foreach (JObject et in jArr)
                    {
                        passed = string.Format("{0}: {1}", et[propName1].ToString(), et[propName2].ToString()) == string.Format("{0}: {1}", propVal1, propVal2);
                    }
                }
                else
                {
                    passed = false;
                }
            }

            return(passed);
        }
Example #13
0
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus = ServiceStatus.GetInstance();
            string entityTypeShortName;
            var    propTypes = new string[1] {
                "Edm.DateTimeOffset"
            };
            var propNames = MetadataHelper.GetPropertyNames(propTypes, out entityTypeShortName);

            if (null == propNames || !propNames.Any())
            {
                return(passed);
            }

            string propName     = propNames[0];
            var    entitySetUrl = entityTypeShortName.GetAccessEntitySetURL();

            if (string.IsNullOrEmpty(entitySetUrl))
            {
                return(passed);
            }

            string url  = svcStatus.RootURL.TrimEnd('/') + "/" + entitySetUrl;
            var    resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);

            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                url  = string.Format("{0}?$filter={1} le maxdatetime()", url, propName);
                resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);
                var detail = new ExtensionRuleResultDetail(this.Name, url, HttpMethod.Get, string.Empty);
                detail.URI                = url;
                detail.ResponsePayload    = resp.ResponsePayload;
                detail.ResponseHeaders    = resp.ResponseHeaders;
                detail.HTTPMethod         = "GET";
                detail.ResponseStatusCode = resp.StatusCode.ToString();

                info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
                if (null != resp && HttpStatusCode.OK == resp.StatusCode)
                {
                    passed = true;
                }
                else
                {
                    detail.ErrorMessage = "The server returned an error response:  " + detail.ResponseStatusCode;
                    passed = false;
                }
            }

            return(passed);
        }
Example #14
0
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus = ServiceStatus.GetInstance();
            string entityTypeShortName;
            var    navigPropNames = MetadataHelper.GetNavigationPropertyNames(
                out entityTypeShortName,
                null,
                (elem) => {
                return(!(null != elem.Attribute("Nullable") && elem.GetAttributeValue("Nullable") == "false"));
            });

            if (null == navigPropNames || !navigPropNames.Any())
            {
                return(passed);
            }

            string navigPropName = navigPropNames[0];

            navigPropNames.RemoveAt(0);
            var    entitySetUrl = entityTypeShortName.MapEntityTypeShortNameToEntitySetURL();
            string url          = string.Format("{0}/{1}?$expand={2}", svcStatus.RootURL.TrimEnd('/'), entitySetUrl, navigPropName);
            var    resp         = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);
            var    detail       = new ExtensionRuleResultDetail("ServiceImpl_SystemQueryOptionExpand", url, HttpMethod.Get, string.Empty);

            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                var jObj = JObject.Parse(resp.ResponsePayload);
                var jArr = jObj.GetValue("value") as JArray;
                foreach (JObject entity in jArr)
                {
                    passed = false;
                    foreach (JProperty prop in entity.Children())
                    {
                        if (prop.Name == navigPropName)
                        {
                            passed = true;
                            break;
                        }
                    }

                    if (passed == true)
                    {
                        break;
                    }
                }
            }

            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus = ServiceStatus.GetInstance();
            string entityTypeShortName;
            var    propNames = MetadataHelper.GetNumericPropertyNames(out entityTypeShortName);
            string propName  = propNames[0];

            if (string.IsNullOrEmpty(entityTypeShortName) || string.IsNullOrEmpty(propName))
            {
                return(passed);
            }

            string entitySetUrl = entityTypeShortName.MapEntityTypeShortNameToEntitySetURL();

            // Set the negative number as -5.0. It is only a testing number, so it can be any numbers.
            double negativeNum = -5.0;
            string url         = string.Format("{0}/{1}?$filter={2} gt -({3})", svcStatus.RootURL.TrimEnd('/'), entitySetUrl, propName, negativeNum);
            var    resp        = WebHelper.Get(new Uri(url), Constants.V4AcceptHeaderJsonFullMetadata, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);
            var    detail      = new ExtensionRuleResultDetail(this.Name, url, HttpMethod.Get, string.Empty);

            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                var jObj = JObject.Parse(resp.ResponsePayload);
                var jArr = jObj.GetValue(Constants.Value);
                passed = true;
                foreach (JObject entity in jArr)
                {
                    try
                    {
                        double val = Convert.ToDouble(entity[propName]);
                        if (val <= -negativeNum)
                        {
                            passed = false;
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        return(null);
                    }
                }
            }
            else
            {
                passed = false;
            }

            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus = ServiceStatus.GetInstance();
            string entityTypeShortName;
            var    keyProp = MetadataHelper.GetKeyProperty(out entityTypeShortName);

            if (null == keyProp)
            {
                return(passed);
            }

            string keyPropName = keyProp.Item1;
            string keyPropType = keyProp.Item2;

            if (string.IsNullOrEmpty(entityTypeShortName) || string.IsNullOrEmpty(keyPropName) || string.IsNullOrEmpty(keyPropType))
            {
                return(passed);
            }

            string entitySetUrl = entityTypeShortName.MapEntityTypeShortNameToEntitySetURL();
            string url          = string.Format("{0}/{1}?$orderby={2} desc", svcStatus.RootURL.TrimEnd('/'), entitySetUrl, keyPropName);
            var    resp         = WebHelper.Get(new Uri(url), Constants.V4AcceptHeaderJsonFullMetadata, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);
            var    detail       = new ExtensionRuleResultDetail("ServiceImpl_SystemQueryOptionOrderBy", url, HttpMethod.Get, resp.ResponseHeaders, resp);

            detail.URI                = url;
            detail.ResponsePayload    = resp.ResponsePayload;
            detail.ResponseHeaders    = resp.ResponseHeaders;
            detail.HTTPMethod         = "GET";
            detail.ResponseStatusCode = resp.StatusCode.ToString();
            //public ExtensionRuleResultDetail(string ruleName, string uri, string httpMethod, string requestHeaders, string responseStatusCode = "", string responseHeaders = "", string responsePayload = "", string errorMessage = "", string requestData = "")
            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                var jObj = JObject.Parse(resp.ResponsePayload);
                var jArr = jObj.GetValue("value") as JArray;
                passed = true;
                for (int i = 0; i < jArr.Count - 1; i++)
                {
                    if (!CompareOperationHelper.Compare(jArr[i][keyPropName], jArr[i + 1][keyPropName], keyPropType, ComparerType.Equal | ComparerType.GreaterThan))
                    {
                        passed = false;
                        break;
                    }
                }
            }

            return(passed);
        }
Example #17
0
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus = ServiceStatus.GetInstance();
            string entityTypeShortName;
            var    propNames = MetadataHelper.GetPropertyNames(out entityTypeShortName);

            if (null == propNames || !propNames.Any())
            {
                return(passed);
            }

            string propName = propNames[0];

            propNames.RemoveAt(0);
            var    entitySetUrl = entityTypeShortName.MapEntityTypeShortNameToEntitySetURL();
            string url          = string.Format("{0}/{1}?$select={2}", svcStatus.RootURL.TrimEnd('/'), entitySetUrl, propName);
            var    resp         = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);
            var    detail       = new ExtensionRuleResultDetail("ServiceImpl_SystemQueryOptionSelect", url, HttpMethod.Get, string.Empty);

            detail.URI                = url;
            detail.ResponsePayload    = resp.ResponsePayload;
            detail.ResponseHeaders    = resp.ResponseHeaders;
            detail.HTTPMethod         = "GET";
            detail.ResponseStatusCode = resp.StatusCode.ToString();

            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                var jObj = JObject.Parse(resp.ResponsePayload);
                var jArr = jObj.GetValue("value") as JArray;
                foreach (JObject entity in jArr)
                {
                    foreach (JProperty prop in entity.Children())
                    {
                        passed = true;
                        if (propNames.Contains(prop.Name))
                        {
                            detail.ErrorMessage = propNames + " does not contain " + prop.Name;

                            passed = false;
                            break;
                        }
                    }
                }
            }

            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus = ServiceStatus.GetInstance();
            string entityTypeShortName;
            var    keyProp = MetadataHelper.GetKeyProperty(out entityTypeShortName);

            if (null == keyProp || string.IsNullOrEmpty(entityTypeShortName))
            {
                return(passed);
            }

            string keyPropName  = keyProp.Item1;
            string keyPropType  = keyProp.Item2;
            string entitySetUrl = entityTypeShortName.MapEntityTypeShortNameToEntitySetURL();

            if (string.IsNullOrEmpty(entitySetUrl))
            {
                return(passed);
            }

            string url  = svcStatus.RootURL.TrimEnd('/') + "/" + entitySetUrl;
            var    resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);

            if (null == resp || HttpStatusCode.OK != resp.StatusCode)
            {
                return(passed);
            }

            var    jObj       = JObject.Parse(resp.ResponsePayload);
            string keyPropVal = jObj.GetValue(Constants.Value).First[keyPropName].ToString();
            string pattern    = "Edm.String" == keyPropType ? "{0}/$entity?$id={1}('{2}')" : "{0}/$entity?$id={1}({2})";

            url  = string.Format(pattern, svcStatus.RootURL.TrimEnd('/'), svcStatus.RootURL.TrimEnd('/') + "/" + entitySetUrl, keyPropVal);
            resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);
            var detail = new ExtensionRuleResultDetail("ServiceImpl_SystemQueryOptionEntity_Id", url, HttpMethod.Get, string.Empty);

            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                passed = true;
            }
            else
            {
                passed = false;
            }

            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus          = ServiceStatus.GetInstance();
            string entitySetUrl       = MetadataHelper.GetEntitySetURLs().First();
            string entityTypeFullName = entitySetUrl.MapEntitySetURLToEntityTypeFullName();
            string url    = string.Format("{0}/{1}?$filter=isof('{2}')", svcStatus.RootURL.TrimEnd('/'), entitySetUrl, entityTypeFullName);
            var    resp   = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);
            var    detail = new ExtensionRuleResultDetail(this.Name, url, HttpMethod.Get, string.Empty);

            detail.URI                = url;
            detail.ResponsePayload    = resp.ResponsePayload;
            detail.ResponseHeaders    = resp.ResponseHeaders;
            detail.HTTPMethod         = "GET";
            detail.ResponseStatusCode = resp.StatusCode.ToString();

            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                JObject jObj = JObject.Parse(resp.ResponsePayload);
                JArray  jArr = jObj.GetValue(Constants.Value) as JArray;
                foreach (JObject entity in jArr)
                {
                    if (null == entity[Constants.V4OdataType])
                    {
                        passed = true;
                    }
                    else
                    {
                        passed = entity[Constants.V4OdataType].ToString() == entityTypeFullName;
                        if (passed == false)
                        {
                            detail.ErrorMessage = entity[Constants.V4OdataType].ToString() + " not equal to " + entityTypeFullName;
                            break;
                        }
                    }
                }
            }
            else
            {
                detail.ErrorMessage = "The server returned an error response:  " + detail.ResponseStatusCode;
                passed = false;
            }

            return(passed);
        }
        /// <summary>
        /// Verifies the extension rule.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if rule passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            var response = WebHelper.Get(context.Destination, Constants.AcceptHeaderJson, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);
            ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name, context.Destination.AbsoluteUri, "GET", StringHelper.MergeHeaders(Constants.AcceptHeaderJson, context.RequestHeaders), response);

            detail.URI                = context.Destination.OriginalString;
            detail.ResponsePayload    = response.ResponsePayload;
            detail.ResponseHeaders    = response.ResponseHeaders;
            detail.HTTPMethod         = "GET";
            detail.ResponseStatusCode = response.StatusCode.ToString();

            if (response != null && response.StatusCode != null)
            {
                // Extracts OData-Version value from ResponseHttpHeaders.
                string oDataVersion = context.ResponseHttpHeaders.GetHeaderValue(Constants.ODataVersion).TrimEnd(';');

                if (!string.IsNullOrEmpty(oDataVersion))
                {
                    float version = float.Parse(oDataVersion);

                    // The minimal OData version of conformance validation is 4.0.
                    if (version >= 4.0)
                    {
                        passed = true;
                    }
                    else
                    {
                        passed = false;
                        detail.ErrorMessage = string.Format(@"The OData version is {0} which should be not less than minimal version 4.0.", version);
                    }
                }
                else
                {
                    passed = false;
                    detail.ErrorMessage = @"Can not get the OData-Version header from response headers.";
                }
            }
            else
            {
                passed = null;
                detail.ErrorMessage = "Cannot get response from above URI.";
            }

            info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
            return(passed);
        }
        /// <summary>
        /// Verifies the extension rule.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if rule passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            string url      = context.Destination.AbsoluteUri.TrimEnd('/') + @"/$metadata";
            var    response = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);
            ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name, url, "GET", StringHelper.MergeHeaders(string.Empty, context.RequestHeaders), response);

            detail.URI                = url;
            detail.ResponsePayload    = response.ResponsePayload;
            detail.ResponseHeaders    = response.ResponseHeaders;
            detail.HTTPMethod         = "GET";
            detail.ResponseStatusCode = response.StatusCode.ToString();

            if (response != null && response.StatusCode != null)
            {
                // Get EntityContainer from metadata payload.
                string   xpath    = @"//*[local-name()='EntityContainer']";
                XElement metadata = XElement.Parse(response.ResponsePayload);
                IEnumerable <XElement> entityContainer = metadata.XPathSelectElements(xpath, ODataNamespaceManager.Instance);
                List <string>          propNames       = new List <string>();

                foreach (var prop in entityContainer)
                {
                    propNames.Add(prop.Attribute("Name").Value);
                }

                if (propNames.Count > 0)
                {
                    passed = true;
                }
                else
                {
                    passed = false;
                    detail.ErrorMessage = "There is no EntityContainer in metadata document.";
                }
            }
            else
            {
                passed = false;
                detail.ErrorMessage = String.Format("No response returned from above URI.");
            }

            info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
            return(passed);
        }
Example #22
0
        public ExtensionRuleResultDetail Clone()
        {
            ExtensionRuleResultDetail desDetail = new ExtensionRuleResultDetail();

            desDetail.RuleName           = this.RuleName;
            desDetail.URI                = this.URI;
            desDetail.HTTPMethod         = this.HTTPMethod;
            desDetail.RequestHeaders     = this.RequestHeaders;
            desDetail.RequestData        = this.RequestData;
            desDetail.ResponseStatusCode = this.ResponseStatusCode;
            desDetail.ResponseHeaders    = this.ResponseHeaders;
            desDetail.ResponsePayload    = this.ResponsePayload;
            desDetail.ErrorMessage       = this.ErrorMessage;

            return(desDetail);
        }
Example #23
0
        /// <summary>
        /// Verifies the extension rule.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if rule passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name);

            detail.ErrorMessage = @"This negative rule is not verified.";
            info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);

            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var svcStatus = ServiceStatus.GetInstance();
            var pagingLimitEntitySetUrls = MetadataHelper.GetPagingLimitEntitySetURLs();

            if (null == pagingLimitEntitySetUrls || !pagingLimitEntitySetUrls.Any())
            {
                return(passed);
            }

            var    pagingLimitEntitySetUrl = pagingLimitEntitySetUrls.First();
            string url       = svcStatus.RootURL.TrimEnd('/') + "/" + pagingLimitEntitySetUrl;
            int    actualNum = JsonParserHelper.GetEntitiesCountFromFeed(url);
            var    resp      = WebHelper.Get(new Uri(url), Constants.V4AcceptHeaderJsonFullMetadata, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);
            var    detail    = new ExtensionRuleResultDetail("ServiceImpl_SystemQueryOptionSkipToken", url, HttpMethod.Get, string.Empty);

            detail.URI                = url;
            detail.ResponsePayload    = resp.ResponsePayload;
            detail.ResponseHeaders    = resp.ResponseHeaders;
            detail.HTTPMethod         = "GET";
            detail.ResponseStatusCode = resp.StatusCode.ToString();
            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                var jObj = JObject.Parse(resp.ResponsePayload);
                var jArr = jObj.GetValue("value") as JArray;
                passed = jArr.Count < actualNum;
            }
            else
            {
                passed = false;
            }

            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus     = ServiceStatus.GetInstance();
            var    entitySetUrls = MetadataHelper.GetEntitySetURLs();
            var    entitySetUrl  = entitySetUrls[0];
            string url           = svcStatus.RootURL.TrimEnd('/') + "/" + entitySetUrl;
            int    actualNum     = JsonParserHelper.GetEntitiesCountFromFeed(url, svcStatus.DefaultHeaders);

            url = string.Format("{0}/$count", url);
            var resp   = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);
            var detail = new ExtensionRuleResultDetail("ServiceImpl_SystemQueryOptionCount", url, HttpMethod.Get, string.Empty);

            detail.URI                = url;
            detail.ResponsePayload    = resp.ResponsePayload;
            detail.ResponseHeaders    = resp.ResponseHeaders;
            detail.HTTPMethod         = "GET";
            detail.ResponseStatusCode = resp.StatusCode.ToString();

            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                passed = Convert.ToInt32(resp.ResponsePayload) == actualNum;
                if (passed == false)
                {
                    detail.ErrorMessage = "The response did not return the correct number";
                }
            }
            else
            {
                detail.ErrorMessage = "The Response returned an error:  " + resp.StatusCode.ToString();
                passed = false;
            }

            return(passed);
        }
Example #26
0
        /// <summary>
        /// Verifies the extension rule.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if rule passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            var response = WebHelper.Get(context.ServiceBaseUri, string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);
            ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name, context.Destination.AbsoluteUri, "GET", StringHelper.MergeHeaders(string.Empty, context.RequestHeaders), response);

            detail.URI                = context.Destination.OriginalString;
            detail.ResponsePayload    = response.ResponsePayload;
            detail.ResponseHeaders    = response.ResponseHeaders;
            detail.HTTPMethod         = "GET";
            detail.ResponseStatusCode = response.StatusCode.ToString();

            if (response != null && response.StatusCode != null)
            {
                var payloadFormat = response.ResponsePayload.GetFormatFromPayload();
                var payloadType   = response.ResponsePayload.GetTypeFromPayload(payloadFormat);

                if (payloadType == RuleEngine.PayloadType.ServiceDoc)
                {
                    passed = true;
                }
                else
                {
                    passed = false;
                    detail.ErrorMessage = "The response is not service document.";
                }
            }
            else
            {
                passed = false;
                detail.ErrorMessage = String.Format("No response returned from above URI.");
            }

            info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);
            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var    svcStatus     = ServiceStatus.GetInstance();
            var    entitySetUrls = MetadataHelper.GetEntitySetURLs();
            var    entitySetUrl  = entitySetUrls[0];
            string url           = svcStatus.RootURL.TrimEnd('/') + "/" + entitySetUrl + "?$top=1";
            var    resp          = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders);
            var    detail        = new ExtensionRuleResultDetail("ServiceImpl_SystemQueryOptionTop", url, HttpMethod.Get, string.Empty);

            detail.URI                = url;
            detail.ResponsePayload    = resp.ResponsePayload;
            detail.ResponseHeaders    = resp.ResponseHeaders;
            detail.HTTPMethod         = "GET";
            detail.ResponseStatusCode = resp.StatusCode.ToString();

            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);
            if (null != resp && HttpStatusCode.OK == resp.StatusCode)
            {
                JObject jObj = JObject.Parse(resp.ResponsePayload);
                JArray  jArr = jObj.GetValue("value") as JArray;
                passed = 1 == jArr.Count;
                if (passed == false)
                {
                    detail.ErrorMessage = "The Response Payload returned more that one record";
                }
            }
            else
            {
                detail.ErrorMessage = "Response status code was and error:  " + resp.StatusCode.ToString();
                passed = false;
            }

            return(passed);
        }
        /// <summary>
        /// Verifies the extension rule.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if rule passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;

            ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name);

            detail.ErrorMessage = "This test is dependent upon passing Intermediate.Conformance.100701, Intermediate.Conformance.100702, Intermediate.Conformance.100703, Intermediate.Conformance.100704, Intermediate.Conformance.100705";
            info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);



            return(passed);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            List <string> entitySetURLs = MetadataHelper.GetEntitySetURLs();

            string   url  = context.ServiceBaseUri.OriginalString.TrimEnd('/') + @"/" + "$crossjoin(" + entitySetURLs.First <string>() + "," + entitySetURLs.Last <string>() + ")";
            Response resp = WebHelper.Get(new Uri(url),
                                          Constants.AcceptHeaderJson, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders);

            ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(this.Name, url, HttpMethod.Get, resp.ResponseHeaders, resp);

            detail.URI                = url;
            detail.ResponsePayload    = resp.ResponsePayload;
            detail.ResponseHeaders    = resp.ResponseHeaders;
            detail.HTTPMethod         = "GET";
            detail.ResponseStatusCode = resp.StatusCode.ToString();

            info = new ExtensionRuleViolationInfo(context.Destination, context.ResponsePayload, detail);

            if (null == resp || HttpStatusCode.OK != resp.StatusCode)
            {
                return(false);
            }

            JObject feed;

            resp.ResponsePayload.TryToJObject(out feed);

            if (feed == null || JTokenType.Object != feed.Type)
            {
                return(false);
            }

            JArray entities = JsonParserHelper.GetEntries(feed);

            return(true);
        }
        /// <summary>
        /// Verifies the service implementation feature.
        /// </summary>
        /// <param name="context">The Interop service context</param>
        /// <param name="info">out parameter to return violation information when rule does not pass</param>
        /// <returns>true if the service implementation feature passes; false otherwise</returns>
        public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool?passed = null;

            info = null;
            var svcStatus = ServiceStatus.GetInstance();

            string url = svcStatus.RootURL.TrimEnd('/') + @"/$metadata/";

            Response response = WebHelper.GetPropertyValue(url);

            var detail = new ExtensionRuleResultDetail(this.Name, url, HttpMethod.Get, string.Empty);

            info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail);

            if (response.StatusCode == HttpStatusCode.OK && !string.IsNullOrEmpty(response.ResponsePayload) && response.ResponsePayload.IsXmlPayload())
            {
                if (response.IsServiceDocument())
                {
                    passed = true;
                }
                else
                {
                    passed = false;
                }
            }
            else
            {
                passed = false;
            }

            return(passed);
        }
        private void AddTestResultDetailToDB(ODataValidationSuiteEntities ctx, int testResulID, ExtensionRuleResultDetail detail)
        {
            // Write one detail information to the DB.
            ResultDetail resultDetailInDB = new ResultDetail();
            int resultID = testResulID;
            resultDetailInDB.TestResultID = resultID;
            resultDetailInDB.RuleName = detail.RuleName;
            resultDetailInDB.URI = detail.URI;
            resultDetailInDB.HTTPMethod = detail.HTTPMethod;
            resultDetailInDB.RequestHeaders = detail.RequestHeaders;
            resultDetailInDB.RequestData = detail.RequestData;
            if (string.IsNullOrEmpty(detail.ResponseStatusCode))
            {
                resultDetailInDB.ResponseStatusCode = detail.ResponseStatusCode;
            }
            else
            {
                HttpStatusCode? responseStatusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), detail.ResponseStatusCode);
                int statusCode = Convert.ToInt32(responseStatusCode);
                resultDetailInDB.ResponseStatusCode = string.Format("{0},{1}", statusCode.ToString(), detail.ResponseStatusCode.ToString());
            }

            resultDetailInDB.ResponseHeaders = detail.ResponseHeaders;
            resultDetailInDB.ResponsePayload = detail.ResponsePayload;
            resultDetailInDB.ErrorMessage = detail.ErrorMessage;

            ctx.AddToResultDetails(resultDetailInDB);
        }