IsExceptionOk() public méthode

public IsExceptionOk ( Exception e, object IdsAndParams ) : void
e System.Exception
IdsAndParams object
Résultat void
        public void InitializeWithElementValidate_OtherElement_Type_Attribute(String typeToValidate)
        {
            XmlSchemaValidator val;
            XmlSchemaInfo      info    = new XmlSchemaInfo();
            XmlSchemaSet       schemas = new XmlSchemaSet();

            schemas.Add("", Path.Combine(TestData, XSDFILE_PARTIAL_VALIDATION));
            schemas.Compile();

            val = CreateValidator(schemas);
            val.Initialize(schemas.GlobalElements[new XmlQualifiedName("PartialElement")]);

            try
            {
                switch (typeToValidate)
                {
                case "other":
                    val.ValidateElement("PartialElement2", "", info);
                    break;

                case "type":
                    val.ValidateElement("foo", "", info, "PartialType", null, null, null);
                    break;

                case "attribute":
                    val.ValidateAttribute("PartialAttribute", "", StringGetter("123"), info);
                    break;

                default:
                    Assert.True(false);
                    break;
                }
            }
            catch (XmlSchemaValidationException e)
            {
                switch (typeToValidate)
                {
                case "other":
                    _exVerifier.IsExceptionOk(e, "Sch_SchemaElementNameMismatch", new string[] { "PartialElement2", "PartialElement" });
                    break;

                case "type":
                    _exVerifier.IsExceptionOk(e, "Sch_SchemaElementNameMismatch", new string[] { "foo", "PartialElement" });
                    break;

                case "attribute":
                    _exVerifier.IsExceptionOk(e, "Sch_ValidateAttributeInvalidCall");
                    break;

                default:
                    Assert.True(false);
                    break;
                }
                return;
            }

            Assert.True(false);
        }
        public void CheckThatSkipToEndElementJumpsIntoRightContext()
        {
            XmlSchemaValidator val  = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT);
            XmlSchemaInfo      info = new XmlSchemaInfo();

            val.Initialize();
            val.ValidateElement("NestedElement", "", info);
            val.ValidateEndOfAttributes(null);

            val.ValidateElement("foo", "", info);
            val.ValidateEndOfAttributes(null);

            val.ValidateElement("bar", "", info);
            val.ValidateEndOfAttributes(null);

            val.SkipToEndElement(info);
            val.SkipToEndElement(info);
            val.SkipToEndElement(info);

            try
            {
                val.SkipToEndElement(info);
            }
            catch (InvalidOperationException e)
            {
                _exVerifier.IsExceptionOk(e, "Sch_InvalidEndElementMultiple", new string[] { "SkipToEndElement" });
                return;
            }

            Assert.True(false);
        }
Exemple #3
0
 // --------------------------------------------------------------------------------------------------------------
 //  VerifyException
 //  -------------------------------------------------------------------------------------------------------------
 public bool VerifyException(Exception ex)
 {
     Type _type = ex.GetType();
     res = String.Empty;//(string)_type.InvokeMember("res", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance, null, ex, null);
     msg = (string)_nav.Evaluate("string(/exceptions/exception [@res = '" + res + "']/@message)");
     try
     {
         _exVer.IsExceptionOk(ex, res);
         return true;
     }
     catch (Exception exp)
     {
         _output.WriteLine(exp.Message);
         return false;
     }
 }
Exemple #4
0
        // --------------------------------------------------------------------------------------------------------------
        //  VerifyException
        //  -------------------------------------------------------------------------------------------------------------
        public bool VerifyException(Exception ex)
        {
            Type _type = ex.GetType();

            res = string.Empty;
            msg = (string)_nav.Evaluate("string(/exceptions/exception [@res = '" + res + "']/@message)");
            try
            {
                _exVer.IsExceptionOk(ex, res);
                return(true);
            }
            catch (Exception exp)
            {
                _output.WriteLine(exp.Message);
                return(false);
            }
        }
        public void CallValidateTextThenValidateEndElementWithTypedValue()
        {
            XmlSchemaValidator val  = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT);
            XmlSchemaInfo      info = new XmlSchemaInfo();

            val.Initialize();
            val.ValidateElement("NumberElement", "", info);
            val.ValidateEndOfAttributes(null);

            val.ValidateText(StringGetter("1"));

            try
            {
                val.ValidateEndElement(info, "23");
            }
            catch (InvalidOperationException e)
            {
                _exVerifier.IsExceptionOk(e, "Sch_InvalidEndElementCall");
                return;
            }

            Assert.True(false);
        }
        public void ElementOnlyContent()
        {
            XmlSchemaValidator val  = CreateValidator(XSDFILE_VALIDATE_TEXT);
            XmlSchemaInfo      info = new XmlSchemaInfo();

            val.Initialize();
            val.ValidateElement("ElementOnlyElement", "", info);
            val.ValidateEndOfAttributes(null);

            try
            {
                val.ValidateText(StringGetter("some text"));
            }
            catch (XmlSchemaValidationException e)
            {
                _exVerifier.IsExceptionOk(e, new object[] { "Sch_InvalidTextInElementExpecting",
                                                            new object[] { "Sch_ElementName", "ElementOnlyElement" },
                                                            new object[] { "Sch_ElementName", "child" } });
                return;
            }

            Assert.True(false);
        }
        public void CallWithoutValidationOfRequiredAttribute()
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_ATTRIBUTE);

            val.Initialize();
            val.ValidateElement("RequiredAttributeElement", "", null);

            try
            {
                val.ValidateEndOfAttributes(null);
            }
            catch (XmlSchemaValidationException e)
            {
                _exVerifier.IsExceptionOk(e, "Sch_MissRequiredAttribute", new string[] { "RequiredAttribute" });
                return;
            }

            Assert.True(false);
        }
        public void ValidateSameAttributeTwice()
        {
            XmlSchemaValidator val  = CreateValidator(XSDFILE_VALIDATE_ATTRIBUTE);
            XmlSchemaInfo      info = new XmlSchemaInfo();

            val.Initialize();
            val.ValidateElement("RequiredAttributeElement", "", null);
            val.ValidateAttribute("RequiredAttribute", "", StringGetter("foo"), info);

            try
            {
                val.ValidateAttribute("RequiredAttribute", "", StringGetter("foo"), info);
            }
            catch (XmlSchemaValidationException e)
            {
                _exVerifier.IsExceptionOk(e, "Sch_DuplicateAttribute", new string[] { "RequiredAttribute" });
                return;
            }

            Assert.True(false);
        }
        public void WhitespaceInEmptyContent__Invalid()
        {
            XmlSchemaValidator val  = CreateValidator(XSDFILE_VALIDATE_TEXT);
            XmlSchemaInfo      info = new XmlSchemaInfo();

            val.Initialize();
            val.ValidateElement("EmptyElement", "", info);
            val.ValidateEndOfAttributes(null);

            try
            {
                val.ValidateWhitespace(" " + Environment.NewLine + "\t");
            }
            catch (XmlSchemaValidationException e)
            {
                _exVerifier.IsExceptionOk(e, "Sch_InvalidWhitespaceInEmpty");
                return;
            }

            Assert.True(false);
        }
        public void SetResolverToCustomValidateSomethingSetResolverToNullThenVerify()
        {
            CXmlTestResolver res    = new CXmlTestResolver();
            CResolverHolder  holder = new CResolverHolder();

            res.CalledResolveUri += new XmlTestResolverEventHandler(holder.CallBackResolveUri);
            res.CalledGetEntity  += new XmlTestResolverEventHandler(holder.CallBackGetEntity);

            XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable());
            XmlSchemaInfo       info    = new XmlSchemaInfo();
            XmlSchemaValidator  val     = new XmlSchemaValidator(new NameTable(),
                                                                 new XmlSchemaSet(),
                                                                 manager,
                                                                 AllFlags);

            val.XmlResolver = res;
            val.Initialize();

            val.ValidateElement("foo", "", null, "type1", null, null, Path.Combine(TestData, XSDFILE_NO_TARGET_NAMESPACE));
            val.SkipToEndElement(null);

            Assert.True(holder.IsCalledResolveUri);
            Assert.True(holder.IsCalledGetEntity);

            manager.AddNamespace("t", "uri:tempuri");
            val.XmlResolver = null;

            try
            {
                val.ValidateElement("bar", "", null, "t:type1", null, "uri:tempuri " + Path.Combine(TestData, XSDFILE_TARGET_NAMESPACE), null);
                Assert.True(false);
            }
            catch (XmlSchemaValidationException e)
            {
                _exVerifier.IsExceptionOk(e, "Sch_XsiTypeNotFound", new string[] { "uri:tempuri:type1" });
                return;
            }

            Assert.True(false);
        }
Exemple #11
0
        public void TestForRootLevelIdentityConstraints_Valid_IDREFMissingInvalid_IgnoreIdentityConstraintsIsSetInvalid(string validity)
        {
            XmlSchemaValidator val;
            XmlSchemaInfo      info = new XmlSchemaInfo();

            string[] keys    = new string[] { };
            string[] keyrefs = new string[] { };

            switch (validity)
            {
            case "valid":
                keys    = new string[] { "a1", "a2" };
                keyrefs = new string[] { "a1", "a1", "a2" };
                break;

            case "missing":
                keys    = new string[] { "a1", "a2" };
                keyrefs = new string[] { "a1", "a1", "a3" };
                break;

            case "ignore":
                keys    = new string[] { "a1", "a1" };
                keyrefs = new string[] { "a2", "a2" };
                break;

            default:
                Assert.True(false);
                break;
            }

            if (validity == "ignore")
            {
                val = CreateValidator(XSDFILE_IDENTITY_CONSTRAINS, "", XmlSchemaValidationFlags.ReportValidationWarnings | XmlSchemaValidationFlags.ProcessSchemaLocation | XmlSchemaValidationFlags.ProcessInlineSchema);
            }
            else
            {
                val = CreateValidator(XSDFILE_IDENTITY_CONSTRAINS);
            }

            val.Initialize();

            val.ValidateElement("rootIDREFs", "", info);
            val.ValidateEndOfAttributes(null);

            foreach (string str in keyrefs)
            {
                val.ValidateElement("foo", "", info);
                val.ValidateAttribute("attr", "", StringGetter(str), info);
                val.ValidateEndOfAttributes(null);
                val.ValidateEndElement(info);
            }

            val.ValidateEndElement(info);

            val.ValidateElement("rootIDs", "", info);
            val.ValidateEndOfAttributes(null);

            foreach (string str in keys)
            {
                val.ValidateElement("foo", "", info);
                val.ValidateAttribute("attr", "", StringGetter(str), info);
                val.ValidateEndOfAttributes(null);
                val.ValidateEndElement(info);
            }

            val.ValidateEndElement(info);

            if (validity == "missing")
            {
                try
                {
                    val.EndValidation();
                    Assert.True(false);
                }
                catch (XmlSchemaValidationException e)
                {
                    _exVerifier.IsExceptionOk(e, "Sch_UndeclaredId", new string[] { "a3" });
                    return;
                }
            }
            else
            {
                val.EndValidation();
            }

            return;
        }