public bool Verify(string content, out TestResult result) { if (content == null) { throw new ArgumentNullException("content"); } using (StringReader sr = new StringReader(content)) { XmlTextReader xtrXml = new XmlTextReader(sr); using (RelaxngValidatingReader vr = new RelaxngValidatingReader(xtrXml, this.rngPattern)) { try { while (vr.Read()) { // Ignore } result = new TestResult(); return true; } catch (RelaxngException rngex) { result = new TestResult() { LineNumberInError = vr.LineNumber, ErrorDetail = rngex.Message }; } return false; } } }
/// <summary> /// Verifies Json literal content /// </summary> /// <param name="content">the Json literal to be verified</param> /// <param name="result">output paramter of test result</param> /// <returns>true if verification passes; false otherwiser</returns> public bool Verify(string content, out TestResult result) { using (var stringReader = new StringReader(content)) { using (JsonTextReader rdr = new JsonTextReader(stringReader)) { using (JsonValidatingReader vr = new JsonValidatingReader(rdr)) { vr.Schema = this.schema; try { while (vr.Read()) { // Ignore } result = new TestResult(); return true; } catch (JsonSchemaException jex) { result = new TestResult() { LineNumberInError = jex.LineNumber, ErrorDetail = jex.Message }; return false; } } } } }
/// <summary> /// Verifies whether the payload of current request session complies to the specified RelaxNG schema or not /// </summary> /// <param name="context">Context object representing the current OData interop session</param> /// <param name="result">Output parameter of validation result</param> /// <returns>True if passed; false if failed</returns> public bool Verify(ServiceContext context, out TestResult result) { if (context == null) { throw new ArgumentNullException("context"); } return this.Verify(context.ResponsePayload, out result); }
protected bool Verify(string input, out TestResult result) { var match = this.regex.Match(input); if (match.Success) { result = new TestResult() { TextInvolved = match.Groups["_involving_"].Value, }; } else { result = new TestResult() { ErrorDetail = Resource.RegexPatternNotFound }; } return match.Success; }
/// <summary> /// Verifies the specified payload of interop request context against current regular expression rule /// </summary> /// <param name="context">interop request session whose payload is to be verified</param> /// <param name="result">output parameter of verification result</param> /// <returns>true if passed; false if failed</returns> /// <exception cref="ArgumentNullExption">Throws excpetion when context parameter is null</exception> /// <exception cref="ArgumentException">Throws exception when context payload is not of Json</exception> public bool Verify(ServiceContext context, out TestResult result) { if (context == null) { throw new ArgumentNullException("context"); } if (context.PayloadFormat != PayloadFormat.Json && context.PayloadFormat != PayloadFormat.JsonLight) { throw new ArgumentException(Resource.PayloadFormatUnexpected); } return this.Verify(context.ResponsePayload, out result); }
public new bool Verify(ServiceContext context, out TestResult result) { if (context == null) { throw new ArgumentNullException("context"); } bool passed = this.Verify(context.ResponseHttpHeaders, out result); if (!passed) { result.TextInvolved = this.GetHeaderLineOfName(context.ResponseHttpHeaders); } return passed; }
private static bool Verify(string xsltRule, string content, string metadata, out TestResult result) { string jsonSchema = XsltTransformer.Transform(metadata, xsltRule); try { var jsonSchemaVerifier = new JsonSchemaVerifier(jsonSchema); return jsonSchemaVerifier.Verify(content, out result); } catch (Exception e) { if (!ExceptionHelper.IsCatchableExceptionType(e)) { throw; } throw new RuntimeException(e, jsonSchema); } }
private static bool Verify(string xsltRule, string content, string metadata, out TestResult result) { string rng = XsltTransformer.Transform(metadata, xsltRule); try { var rngChecker = new RngVerifier(rng); return rngChecker.Verify(content, out result); } catch (Exception e) { if (!ExceptionHelper.IsCatchableExceptionType(e)) { throw; } throw new RuntimeException(e, rng); } }
/// <summary> /// Verifies the specified interop request context with the rule /// </summary> /// <param name="context">The interop request context</param> /// <param name="result">Output parameter of validation result</param> /// <returns>True if passed; false if failed</returns> public bool Verify(ServiceContext context, out TestResult result) { if (context == null) { throw new ArgumentNullException("context"); } if (context.PayloadFormat != PayloadFormat.Xml && context.PayloadFormat != PayloadFormat.Atom) { throw new ArgumentException(Resource.PayloadFormatUnexpected); } if (!context.HasMetadata) { throw new ArgumentException(Resource.MetadataUnavailable); } string xsltMaterialized = XsltRulePreprocessor.Preprocess(context, this.xslt); return XsltRngVerifier.Verify(xsltMaterialized, context.ResponsePayload, context.MetadataDocument, out result); }
/// <summary> /// Verifies whether the specific interop request context pass the validation or not /// </summary> /// <param name="context">Current interop request context</param> /// <param name="result">Output parameter of TestResult object</param> /// <returns>True if passed; false if failed</returns> public bool Verify(ServiceContext context, out TestResult result) { if (context == null) { throw new ArgumentNullException("context"); } bool? flagExec; ExtensionRuleViolationInfo info; flagExec = this.semanticExtensionVerifier(context, out info); bool passed = flagExec.HasValue ? flagExec.Value : true; result = new TestResult(); if (info != null) { result.ErrorDetail = info.Message; result.LineNumberInError = info.PayloadLineNumberInError; if (info.Endpoint != null) { result.TextInvolved = info.Endpoint.AbsoluteUri; } if (info.Details != null) { result.Details = new List<ExtensionRuleResultDetail>(); foreach (ExtensionRuleResultDetail detail in info.Details) { result.Details.Add(detail.Clone()); } } } if (!flagExec.HasValue) { result.Classification = Constants.ClassificationNotApplicable; } return passed; }
/// <summary> /// Creates an aborted test result from rule definition and job ID /// </summary> /// <param name="rule">The rule this aborted result is about</param> /// <param name="jobId">The job this aborted validation is part of</param> /// <returns>TestResult object for aborted validation</returns> public static TestResult CreateAbortedResult(Rule rule, Guid jobId) { TestResult result = new TestResult(); result.JobId = jobId; result.SetProperties(rule, true); result.Classification = Constants.ClassificationAborted; return result; }
/// <summary> /// Executes one rule to validate the current interop request contecxt /// </summary> /// <param name="context">the current interop request context</param> /// <param name="rule">the rule to be validated</param> /// <returns>TestResult object of the validation</returns> /// <exception cref="Exception">Throws various exception when rule engine encounters unrecoverable errors like bad dynamic rules</exception> public static TestResult ExecuteRule(ServiceContext context, Rule rule) { if (context == null) { throw new ArgumentNullException("context"); } if (rule == null) { throw new ArgumentNullException("rule"); } bool passed = true; TestResult result; TestResult dummy; //Set the test service's current verified rule if (DataService.serviceInstance != null) { DataService.serviceInstance.SwitchRule(rule.Name); } if (rule.Condition == null || rule.Condition.Verify(context, out dummy)) { passed = rule.Action.Verify(context, out result); } else { result = new TestResult(); } result.JobId = context.JobId; result.SetProperties(rule, passed); return result; }