private void TestSimpleSequence2(SdbSchemaDatas sdbSchemaDatas) { ValidationContext validationContext = new ValidationContext(); ValidationResult actual = new ValidationResult(); validationContext.ValidationErrorEventHandler += actual.OnValidationError; Ruby ruby = new Ruby(); OpenXmlElement errorChild; var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(ruby).ParticleConstraint; var target = particleConstraint.ParticleValidator as SequenceParticleValidator; validationContext.Element = ruby; var expected = ruby; //<xsd:complexType name="CT_Ruby"> // <xsd:sequence> // <xsd:element name="rubyPr" type="CT_RubyPr"> // <xsd:element name="rt" type="CT_RubyContent"> // <xsd:element name="rubyBase" type="CT_RubyContent"> // </xsd:sequence> //</xsd:complexType>} // ***** good case ****** ruby.Append(new RubyProperties(), new RubyContent(), new RubyBase()); target.Validate(validationContext); Assert.True(actual.Valid); // ***** error case ****** // No RubyBase child, incomplete error ruby.RemoveChild(ruby.LastChild); 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(":rubyBase")); actual.Clear(); // No RubyContent child, incomplete error ruby.RemoveChild(ruby.LastChild); 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(":rt")); actual.Clear(); // Empty, incomplete error ruby.RemoveChild(ruby.LastChild); 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(":rubyPr")); actual.Clear(); // No RubyContent child, incomplete error ruby.Append(new RubyProperties(), new RubyBase()); errorChild = ruby.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_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id); Assert.True(actual.Errors[0].Description.Contains(":rt")); actual.Clear(); // No RubyProperties child, incomplete error ruby.RemoveAllChildren(); ruby.Append(new RubyContent(), new RubyBase()); errorChild = ruby.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_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id); Assert.True(actual.Errors[0].Description.Contains(":rubyPr")); actual.Clear(); // first should be RubyProperties() ruby.PrependChild(new RubyContent()); errorChild = ruby.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_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id); Assert.True(actual.Errors[0].Description.Contains(":rubyPr")); actual.Clear(); // 2nd and 3rd are same element, error errorChild = ruby.FirstChild.NextSibling(); ruby.PrependChild(new RubyProperties()); 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_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id); Assert.True(actual.Errors[0].Description.Contains(":rt")); }
public void TestSimpleSequence2() { ValidationContext validationContext = new ValidationContext(); Ruby ruby = new Ruby(); OpenXmlElement errorChild; var particleConstraint = ruby.ParticleConstraint.Build(Version); var target = particleConstraint.ParticleValidator as SequenceParticleValidator; validationContext.Element = ruby; var expected = ruby; //<xsd:complexType name="CT_Ruby"> // <xsd:sequence> // <xsd:element name="rubyPr" type="CT_RubyPr"> // <xsd:element name="rt" type="CT_RubyContent"> // <xsd:element name="rubyBase" type="CT_RubyContent"> // </xsd:sequence> //</xsd:complexType>} // ***** good case ****** ruby.Append(new RubyProperties(), new RubyContent(), new RubyBase()); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** // No RubyBase child, incomplete error ruby.RemoveChild(ruby.LastChild); 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(":rubyBase", validationContext.Errors[0].Description); validationContext.Clear(); // No RubyContent child, incomplete error ruby.RemoveChild(ruby.LastChild); 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(":rt", validationContext.Errors[0].Description); validationContext.Clear(); // Empty, incomplete error ruby.RemoveChild(ruby.LastChild); 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(":rubyPr", validationContext.Errors[0].Description); validationContext.Clear(); // No RubyContent child, incomplete error ruby.Append(new RubyProperties(), new RubyBase()); errorChild = ruby.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_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id); Assert.Contains(":rt", validationContext.Errors[0].Description); validationContext.Clear(); // No RubyProperties child, incomplete error ruby.RemoveAllChildren(); ruby.Append(new RubyContent(), new RubyBase()); errorChild = ruby.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_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id); Assert.Contains(":rubyPr", validationContext.Errors[0].Description); validationContext.Clear(); // first should be RubyProperties() ruby.PrependChild(new RubyContent()); errorChild = ruby.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_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id); Assert.Contains(":rubyPr", validationContext.Errors[0].Description); validationContext.Clear(); // 2nd and 3rd are same element, error errorChild = ruby.FirstChild.NextSibling(); ruby.PrependChild(new RubyProperties()); 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_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id); Assert.Contains(":rt", validationContext.Errors[0].Description); }