private void TestSimpleSequence3(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult  actual            = new ValidationResult();

            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            Divs           divs = new Divs();
            OpenXmlElement errorChild;

            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(divs).ParticleConstraint;
            var target             = particleConstraint.ParticleValidator as SequenceParticleValidator;

            validationContext.Element = divs;
            var expected = divs;

            //<xsd:complexType name="CT_Divs">
            //  <xsd:sequence minOccurs="1" maxOccurs="unbounded">
            //    <xsd:element name="div" type="CT_Div">
            //  </xsd:sequence>
            //</xsd:complexType

            // ***** good case ******
            divs.AppendChild(new Div());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            divs.AppendChild(new Div());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            divs.AppendChild(new Div());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // 1st child is invalid
            errorChild = divs.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":div"));

            actual.Clear();
            // last child is invalid
            divs.RemoveChild(errorChild);
            errorChild = divs.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":div"));

            actual.Clear();
            // 2nd child is invalid
            divs.RemoveChild(errorChild);
            errorChild = divs.InsertAfter(new Paragraph(), divs.FirstChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":div"));

            actual.Clear();
            // 3rd child is invalid
            divs.RemoveChild(errorChild);
            errorChild = divs.InsertBefore(new Paragraph(), divs.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":div"));

            actual.Clear();
            // empty,
            divs.RemoveAllChildren();
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_IncompleteContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":div"));

            actual.Clear();
            // only one invalid child
            errorChild = divs.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":div"));
        }
        public void TestSimpleSequence3()
        {
            ValidationContext validationContext = new ValidationContext();
            Divs           divs = new Divs();
            OpenXmlElement errorChild;

            var particleConstraint = divs.ParticleConstraint.Build(Version);
            var target             = particleConstraint.ParticleValidator as SequenceParticleValidator;

            validationContext.Element = divs;
            var expected = divs;

            //<xsd:complexType name="CT_Divs">
            //  <xsd:sequence minOccurs="1" maxOccurs="unbounded">
            //    <xsd:element name="div" type="CT_Div">
            //  </xsd:sequence>
            //</xsd:complexType

            // ***** good case ******
            divs.AppendChild(new Div());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            divs.AppendChild(new Div());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            divs.AppendChild(new Div());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            // ***** error case ******

            // 1st child is invalid
            errorChild = divs.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.Contains(":div", validationContext.Errors[0].Description);

            validationContext.Clear();

            // last child is invalid
            divs.RemoveChild(errorChild);
            errorChild = divs.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.Contains(":div", validationContext.Errors[0].Description);

            validationContext.Clear();

            // 2nd child is invalid
            divs.RemoveChild(errorChild);
            errorChild = divs.InsertAfter(new Paragraph(), divs.FirstChild);
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.Contains(":div", validationContext.Errors[0].Description);

            validationContext.Clear();

            // 3rd child is invalid
            divs.RemoveChild(errorChild);
            errorChild = divs.InsertBefore(new Paragraph(), divs.LastChild);
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.Contains(":div", validationContext.Errors[0].Description);

            validationContext.Clear();

            // empty,
            divs.RemoveAllChildren();
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_IncompleteContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.Contains(":div", validationContext.Errors[0].Description);

            validationContext.Clear();

            // only one invalid child
            errorChild = divs.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.Contains(":div", validationContext.Errors[0].Description);
        }
        private void TestSimpleSequence3(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            Divs divs = new Divs();
            OpenXmlElement errorChild;

            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(divs).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as SequenceParticleValidator;
            validationContext.Element = divs;
            var expected = divs;
       
              //<xsd:complexType name="CT_Divs">
              //  <xsd:sequence minOccurs="1" maxOccurs="unbounded">
              //    <xsd:element name="div" type="CT_Div">
              //  </xsd:sequence>
              //</xsd:complexType

            // ***** good case ******
            divs.AppendChild(new Div());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            divs.AppendChild(new Div());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            divs.AppendChild(new Div());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // 1st child is invalid
            errorChild = divs.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":div"));

            actual.Clear();
            // last child is invalid
            divs.RemoveChild(errorChild);
            errorChild = divs.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":div"));

            actual.Clear();
            // 2nd child is invalid
            divs.RemoveChild(errorChild);
            errorChild = divs.InsertAfter(new Paragraph(), divs.FirstChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":div"));

            actual.Clear();
            // 3rd child is invalid
            divs.RemoveChild(errorChild);
            errorChild = divs.InsertBefore(new Paragraph(), divs.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":div"));

            actual.Clear();
            // empty,
            divs.RemoveAllChildren();
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_IncompleteContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":div"));

            actual.Clear();
            // only one invalid child
            errorChild = divs.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":div"));
        }