コード例 #1
0
 private void ProcessException(System.Xml.Schema.XmlSchemaException ex)
 {
     // If stack traces is empty then...
     if (ex.StackTrace == null)
     {
         try
         {
             throw new System.Xml.Schema.XmlSchemaException(ex.Message, ex, ex.LineNumber, ex.LinePosition);
         }
         catch (System.Xml.Schema.XmlSchemaException ex1)
         {
             //Dim remoteStackTraceString As Reflection.FieldInfo = GetType(Exception).GetField("_remoteStackTraceString", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
             // to the current InnerException.StackTrace
             //remoteStackTraceString.SetValue(ex, New StackTrace(True).ToString())
             ex = ex1;
         }
     }
     Exceptions.Add(ex);
     ex.Data.Add("XSD", _xsd);
     if (!string.IsNullOrEmpty(_xmlPath))
     {
         ex.Data.Add("XML Path", _xmlPath);
     }
     if (_xml.Length > 8192)
     {
         ex.Data.Add("XML Size", _xml.Length.ToString("#,##0"));
         _xml = _xml.Substring(0, 8192);
     }
     ex.Data.Add("XML", _xml);
 }
コード例 #2
0
        public void Invalid_Namespaces_Identifier()
        {
            string toValidate  = Resources.IValidationService.Invalid.Namespaces.Identifier;
            var    interpreter = new DebugIntepreter();

            interpreter.InterpretationFunction = (exception) =>
            {
                if (false == (exception is System.Xml.Schema.XmlSchemaException))
                {
                    Assert.Fail("Expected System.Xml.Schema.XmlSchemaException");
                }
                System.Xml.Schema.XmlSchemaException e = exception as System.Xml.Schema.XmlSchemaException;
                if (e.LineNumber != 15)
                {
                    Assert.Fail("This test should fail on line 15");
                }
                if (e.LinePosition != 6)
                {
                    Assert.Fail("This test should fail at line position 6");
                }
                Assert.IsTrue
                (
                    e.Message.StartsWith("The element 'provider' in namespace 'http://xcri.org/profiles/1.2/catalog' has invalid child element 'identifier' in namespace 'http://xcri.org/profiles/1.2/catalog'"),
                    "Exception expected to complain about identifier missing namespace"
                );
                return(XCRI.Validation.XmlExceptionInterpretation.InterpretationStatus.Interpreted);
            };

            var t = base.Instantiate();

            t.AttemptSchemaLocationInjection = false;
            t.XmlExceptionInterpreters.Add(interpreter);
            t.Source = new XCRI.Validation.XmlRetrieval.StringSource(null, this.XmlResolver);
            var results = t.Validate(toValidate);

            Assert.AreEqual <int>(1, results.Count, "1 exception expected");
        }
コード例 #3
0
        public void Invalid_Formatting_GeneratedAttribute()
        {
            string toValidate  = Resources.IValidationService.Invalid.Formatting.GeneratedAttribute;
            var    interpreter = new DebugIntepreter();

            interpreter.InterpretationFunction = (exception) =>
            {
                if (false == (exception is System.Xml.Schema.XmlSchemaException))
                {
                    Assert.Fail("Expected System.Xml.Schema.XmlSchemaException");
                }
                System.Xml.Schema.XmlSchemaException e = exception as System.Xml.Schema.XmlSchemaException;
                if (e.LineNumber != 6)
                {
                    Assert.Fail("This test should fail on line 6");
                }
                if (e.LinePosition != 3)
                {
                    Assert.Fail("This test should fail at line position 3");
                }
                Assert.IsTrue
                (
                    exception.Message == "The 'generated' attribute is invalid - The value '2011-03-21 20:00:23' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:dateTime' - The string '2011-03-21 20:00:23' is not a valid DateTime value.",
                    "Exception expected to complain about description missing namespace"
                );
                return(XCRI.Validation.XmlExceptionInterpretation.InterpretationStatus.Interpreted);
            };

            var t = base.Instantiate();

            t.AttemptSchemaLocationInjection = false;
            t.XmlExceptionInterpreters.Add(interpreter);
            t.Source = new XCRI.Validation.XmlRetrieval.StringSource(null, this.XmlResolver);
            var results = t.Validate(toValidate);

            Assert.AreEqual <int>(1, results.Count, "1 exception expected");
        }
コード例 #4
0
        public void Invalid_Namespaces_NoDocumentNamespace()
        {
            string toValidate  = Resources.IValidationService.Invalid.Namespaces.NoDocumentNamespace;
            var    interpreter = new DebugIntepreter();

            interpreter.InterpretationFunction = (exception) =>
            {
                if (false == (exception is System.Xml.Schema.XmlSchemaException))
                {
                    Assert.Fail("Expected System.Xml.Schema.XmlSchemaException");
                }
                System.Xml.Schema.XmlSchemaException e = exception as System.Xml.Schema.XmlSchemaException;
                if (e.LineNumber != 2)
                {
                    Assert.Fail("This test should fail on line 2");
                }
                if (e.LinePosition != 2)
                {
                    Assert.Fail("This test should fail at line position 2");
                }
                Assert.IsTrue
                (
                    exception.Message == "Could not find schema information for the element 'catalog'.",
                    "Exception expected to complain about schema information missing for root catalog element"
                );
                return(XCRI.Validation.XmlExceptionInterpretation.InterpretationStatus.Interpreted);
            };

            var t = base.Instantiate();

            t.AttemptSchemaLocationInjection = false;
            t.XmlExceptionInterpreters.Add(interpreter);
            t.Source = new XCRI.Validation.XmlRetrieval.StringSource(null, this.XmlResolver);
            var results = t.Validate(toValidate);

            Assert.AreEqual <int>(1, results.Count, "1 exception expected");
        }