public void TestSimpleChoice() { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; FieldChar fldChar = new FieldChar(); var particleConstraint = fldChar.ParticleConstraint.Build(Version); var target = particleConstraint.ParticleValidator as ChoiceParticleValidator; validationContext.Element = fldChar; var expected = fldChar; //<xsd:complexType name="CT_FldChar"> // <xsd:choice> // <xsd:element name="fldData" type="CT_Text" minOccurs="0" maxOccurs="1"> // <xsd:element name="ffData" type="CT_FFData" minOccurs="0" maxOccurs="1"> // <xsd:element name="numberingChange" type="CT_TrackChangeNumbering" minOccurs="0"> // </xsd:choice> //</xsd:complexType> // ***** good case ****** target.Validate(validationContext); Assert.True(validationContext.Valid); fldChar.AppendChild(new FieldData()); target.Validate(validationContext); Assert.True(validationContext.Valid); fldChar.RemoveAllChildren(); fldChar.AppendChild(new FormFieldData()); target.Validate(validationContext); Assert.True(validationContext.Valid); fldChar.RemoveAllChildren(); fldChar.AppendChild(new NumberingChange()); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** // 1st is invalid errorChild = fldChar.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(":fldData", validationContext.Errors[0].Description); Assert.Contains(":ffData", validationContext.Errors[0].Description); Assert.Contains(":numberingChange", validationContext.Errors[0].Description); validationContext.Clear(); // second is invalid fldChar.RemoveChild(errorChild); errorChild = fldChar.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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); validationContext.Clear(); // dup first child fldChar.RemoveAllChildren(); fldChar.Append(new FieldData(), new FieldData()); errorChild = fldChar.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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); validationContext.Clear(); // two different fldChar.RemoveAllChildren(); fldChar.Append(new FieldData(), new FormFieldData()); errorChild = fldChar.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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); validationContext.Clear(); // two different fldChar.RemoveAllChildren(); fldChar.Append(new FormFieldData(), new FieldData()); errorChild = fldChar.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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); }
public void TestSimpleChoice4() { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; RevisionRowColumn rRowColumn = new RevisionRowColumn(); var particleConstraint = rRowColumn.ParticleConstraint.Build(FileFormatVersions.Office2007); var target = particleConstraint.ParticleValidator as ChoiceParticleValidator; validationContext.Element = rRowColumn; var expected = rRowColumn; //<xsd:complexType name="CT_RevisionRowColumn"> // <xsd:choice minOccurs="0" maxOccurs="unbounded"> // <xsd:element name="undo" type="CT_UndoInfo" minOccurs="0" maxOccurs="unbounded"> // <xsd:element name="rcc" type="CT_RevisionCellChange" minOccurs="0" maxOccurs="unbounded"> // <xsd:element name="rfmt" type="CT_RevisionFormatting" minOccurs="0" maxOccurs="unbounded"> // </xsd:choice> //</xsd:complexType> // ***** good case ****** // empty is OK target.Validate(validationContext); Assert.True(validationContext.Valid); rRowColumn.AppendChild(new RevisionCellChange()); target.Validate(validationContext); Assert.True(validationContext.Valid); // duplicate is ok rRowColumn.AppendChild(new RevisionCellChange()); target.Validate(validationContext); Assert.True(validationContext.Valid); // more is ok rRowColumn.AppendChild(new RevisionFormat()); target.Validate(validationContext); Assert.True(validationContext.Valid); // more is ok rRowColumn.AppendChild(new Undo()); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** //first is invalid errorChild = rRowColumn.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(":undo", validationContext.Errors[0].Description); Assert.Contains(":rfmt", validationContext.Errors[0].Description); validationContext.Clear(); //invalid child in middle rRowColumn.RemoveChild(errorChild); errorChild = rRowColumn.InsertBefore(new Paragraph(), rRowColumn.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(":undo", validationContext.Errors[0].Description); Assert.Contains(":rfmt", validationContext.Errors[0].Description); validationContext.Clear(); //invalid child in last rRowColumn.RemoveChild(errorChild); errorChild = rRowColumn.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(":undo", validationContext.Errors[0].Description); Assert.Contains(":rfmt", validationContext.Errors[0].Description); }
public void TestSimpleChoice2() { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; BuildSubElement bldSub = new BuildSubElement(); var particleConstraint = bldSub.ParticleConstraint.Build(Version); var target = particleConstraint.ParticleValidator as ChoiceParticleValidator; validationContext.Element = bldSub; var expected = bldSub; //<xsd:complexType name="CT_AnimationGraphicalObjectBuildProperties"> // <xsd:choice> // <xsd:element name="bldDgm" type="CT_AnimationDgmBuildProperties"> // <xsd:element name="bldChart" type="CT_AnimationChartBuildProperties"> // </xsd:choice> //</xsd:complexType> // ***** good case ****** bldSub.AppendChild(new Drawing.BuildChart()); target.Validate(validationContext); Assert.True(validationContext.Valid); bldSub.RemoveAllChildren(); bldSub.AppendChild(new Drawing.BuildDiagram()); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** // empty bldSub.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(":bldDgm", validationContext.Errors[0].Description); Assert.Contains(":bldChart", validationContext.Errors[0].Description); validationContext.Clear(); // both element are exist bldSub.Append(new Drawing.BuildChart(), new Drawing.BuildDiagram()); errorChild = bldSub.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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); validationContext.Clear(); //first is invalid errorChild = bldSub.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(":bldDgm", validationContext.Errors[0].Description); Assert.Contains(":bldChart", validationContext.Errors[0].Description); }
private void ValidateBlip(SdbSchemaDatas sdbSchemaDatas) { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; Drawing.Blip blip = new Drawing.Blip(); var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(blip).ParticleConstraint; var target = particleConstraint.ParticleValidator as ParticleValidator; validationContext.Element = blip; var expected = blip; //<xsd:complexType name="CT_Blip"> // <xsd:sequence> // <xsd:choice minOccurs="0" maxOccurs="unbounded"> // <xsd:element name="alphaBiLevel" type="CT_AlphaBiLevelEffect" minOccurs="1" maxOccurs="1"> // <xsd:element name="alphaCeiling" type="CT_AlphaCeilingEffect" minOccurs="1" maxOccurs="1" /> // <xsd:element name="alphaFloor" type="CT_AlphaFloorEffect" minOccurs="1" maxOccurs="1" /> // <xsd:element name="alphaInv" type="CT_AlphaInverseEffect" minOccurs="1" maxOccurs="1" /> // <xsd:element name="alphaMod" type="CT_AlphaModulateEffect" minOccurs="1" maxOccurs="1" /> // <xsd:element name="alphaModFix" type="CT_AlphaModulateFixedEffect" minOccurs="1" maxOccurs="1"> // <xsd:element name="alphaRepl" type="CT_AlphaReplaceEffect" minOccurs="1" maxOccurs="1" /> // <xsd:element name="biLevel" type="CT_BiLevelEffect" minOccurs="1" maxOccurs="1"> // <xsd:element name="blur" type="CT_BlurEffect" minOccurs="1" maxOccurs="1" /> // <xsd:element name="clrChange" type="CT_ColorChangeEffect" minOccurs="1" maxOccurs="1" /> // <xsd:element name="clrRepl" type="CT_ColorReplaceEffect" minOccurs="1" maxOccurs="1"> // <xsd:element name="duotone" type="CT_DuotoneEffect" minOccurs="1" maxOccurs="1" /> // <xsd:element name="fillOverlay" type="CT_FillOverlayEffect" minOccurs="1" maxOccurs="1" /> // <xsd:element name="grayscl" type="CT_GrayscaleEffect" minOccurs="1" maxOccurs="1" /> // <xsd:element name="hsl" type="CT_HSLEffect" minOccurs="1" maxOccurs="1" /> // <xsd:element name="lum" type="CT_LuminanceEffect" minOccurs="1" maxOccurs="1"> // <xsd:element name="tint" type="CT_TintEffect" minOccurs="1" maxOccurs="1"> // </xsd:choice> // <xsd:element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1"></xsd:element> // </xsd:sequence> // <xsd:attributeGroup ref="AG_Blob"></xsd:attributeGroup> // <xsd:attribute name="cstate" type="ST_BlipCompression" use="optional" default="none"> //</xsd:complexType> // ***** good case ****** // empty is ok target.Validate(validationContext); Assert.True(validationContext.Valid); // blip.AppendChild(new Drawing.LuminanceEffect()); target.Validate(validationContext); Assert.True(validationContext.Valid); blip.AppendChild(new Drawing.LuminanceEffect()); target.Validate(validationContext); Assert.True(validationContext.Valid); blip.AppendChild(new Drawing.AlphaBiLevel()); target.Validate(validationContext); Assert.True(validationContext.Valid); blip.AppendChild(new Drawing.Blur()); target.Validate(validationContext); Assert.True(validationContext.Valid); blip.AppendChild(new Drawing.BiLevel()); target.Validate(validationContext); Assert.True(validationContext.Valid); blip.AppendChild(new Drawing.BlipExtensionList()); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** // ExtensionList can not be the first errorChild = blip.FirstChild; blip.PrependChild(new Drawing.BlipExtensionList()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); blip.RemoveChild(blip.FirstChild); validationContext.Clear(); // can only have one ExtensionList at last errorChild = blip.AppendChild(new Drawing.BlipExtensionList()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); blip.RemoveChild(errorChild); }
public void TestSimpleChoice3() { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; FormFieldData ffData = new FormFieldData(); var particleConstraint = ffData.ParticleConstraint.Build(Version); var target = particleConstraint.ParticleValidator as ChoiceParticleValidator; validationContext.Element = ffData; var expected = ffData; //<xs:complexType name="CT_FFData"> // <xs:choice maxOccurs="unbounded"> // <xs:element name="name" type="CT_FFName"> // <xs:element name="enabled" type="CT_OnOff"> // <xs:element name="calcOnExit" type="CT_OnOff"> // <xs:element name="entryMacro" type="CT_MacroName" minOccurs="0" maxOccurs="1"> // <xs:element name="exitMacro" type="CT_MacroName" minOccurs="0" maxOccurs="1"> // <xs:element name="helpText" type="CT_FFHelpText" minOccurs="0" maxOccurs="1"> // <xs:element name="statusText" type="CT_FFStatusText" minOccurs="0" maxOccurs="1"> // <xs:choice> // <xs:element name="checkBox" type="CT_FFCheckBox"> // <xs:element name="ddList" type="CT_FFDDList"> // <xs:element name="textInput" type="CT_FFTextInput"> // </xs:choice> // </xs:choice> //</xs:complexType> // ***** good case ****** // empty is ok, as there are child with minOccurs="0" target.Validate(validationContext); Assert.True(validationContext.Valid); ffData.AppendChild(new FormFieldName()); target.Validate(validationContext); Assert.True(validationContext.Valid); // dup element ffData.AppendChild(new FormFieldName()); target.Validate(validationContext); Assert.True(validationContext.Valid); ffData.RemoveAllChildren(); ffData.AppendChild(new StatusText()); target.Validate(validationContext); Assert.True(validationContext.Valid); // 2 element ffData.AppendChild(new HelpText()); target.Validate(validationContext); Assert.True(validationContext.Valid); // dup element ffData.AppendChild(new HelpText()); target.Validate(validationContext); Assert.True(validationContext.Valid); // more element ffData.AppendChild(new Enabled()); target.Validate(validationContext); Assert.True(validationContext.Valid); // more element ffData.AppendChild(new CheckBox()); target.Validate(validationContext); Assert.True(validationContext.Valid); // more element ffData.AppendChild(new TextInput()); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** ffData.RemoveAllChildren(); ffData.AppendChild(new HelpText()); ffData.AppendChild(new CheckBox()); //first is invalid errorChild = ffData.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(":name", validationContext.Errors[0].Description); Assert.Contains(":textInput", validationContext.Errors[0].Description); validationContext.Clear(); //invalid child in middle ffData.RemoveChild(errorChild); errorChild = ffData.InsertBefore(new Paragraph(), ffData.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(":name", validationContext.Errors[0].Description); Assert.Contains(":textInput", validationContext.Errors[0].Description); validationContext.Clear(); //invalid child in last ffData.RemoveChild(errorChild); errorChild = ffData.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(":name", validationContext.Errors[0].Description); Assert.Contains(":textInput", validationContext.Errors[0].Description); }
private void ValidateBody(SdbSchemaDatas sdbSchemaDatas) { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; Body body = new Body(); var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(body).ParticleConstraint; var target = particleConstraint.ParticleValidator as ParticleValidator; validationContext.Element = body; var expected = body; //<xsd:complexType name="CT_Body"> // <xsd:sequence> // <xsd:group ref="EG_BlockLevelElts" minOccurs="0" maxOccurs="unbounded" /> // <xsd:element name="sectPr" minOccurs="0" maxOccurs="1" type="CT_SectPr"> // </xsd:sequence> //</xsd:complexType> //<xs:group name="EG_BlockLevelEltsBase"> // <xs:choice> // <xs:element name="altChunk" type="CT_AltChunk" minOccurs="0" maxOccurs="unbounded"></xs:element> // </xs:choice> //</xs:group> //<xs:group name="EG_BlockLevelElts"> // <xs:choice> // <xs:group ref="EG_BlockLevelEltsBase" minOccurs="0" maxOccurs="unbounded" /> // <xs:group ref="EG_BlockLevelChunkElts" minOccurs="0" maxOccurs="unbounded" /> // </xs:choice> //</xs:group> //<xsd:group name="EG_BlockLevelChunkElts"> // <xsd:choice> // <xsd:group ref="EG_ContentBlockContent" minOccurs="0" maxOccurs="unbounded" /> // </xsd:choice> //</xsd:group> //<xs:group name="EG_ContentBlockContent"> // <xs:choice> // <xs:group ref="EG_ContentBlockContentBase" minOccurs="0" maxOccurs="unbounded" /> // <xs:group ref="EG_RunLevelElts" minOccurs="0" maxOccurs="unbounded" /> // </xs:choice> //</xs:group> //<xs:group name="EG_ContentBlockContentBase"> // <xs:choice> // <xs:element name="customXml" type="CT_CustomXmlBlock"></xs:element> // <xs:element name="sdt" type="CT_SdtBlock"></xs:element> // <xs:element name="p" type="CT_P" minOccurs="0" maxOccurs="unbounded"></xs:element> // <xs:element name="tbl" type="CT_Tbl" minOccurs="0" maxOccurs="unbounded"></xs:element> // </xs:choice> //</xs:group> //<xs:group name="EG_RunLevelElts"> // <xs:choice> // <xs:group ref="EG_RunLevelEltsBase" minOccurs="0" maxOccurs="unbounded" /> // <xs:group ref="EG_RangeMarkupElements" minOccurs="0" maxOccurs="unbounded"></xs:group> // <xs:element name="ins" type="CT_RunTrackChange" minOccurs="0"> // <xs:element name="del" type="CT_RunTrackChange" minOccurs="0"> // <xs:element name="moveFrom" type="CT_RunTrackChange"> // <xs:element name="moveTo" type="CT_RunTrackChange"> // <xs:element name="contentPart" type="CT_ContentPart" minOccurs="0" maxOccurs="unbounded" ofapi:available="o14" /> // <xs:group ref="w14:EG_RunLevelConflicts" minOccurs="0" /> // </xs:choice> //</xs:group> //<xs:group name="EG_RunLevelEltsBase"> // <xs:choice> // <xs:element name="proofErr" minOccurs="0" type="CT_ProofErr"></xs:element> // <xs:element name="permStart" minOccurs="0" type="CT_PermStart"></xs:element> // <xs:element name="permEnd" minOccurs="0" type="CT_Perm"></xs:element> // </xs:choice> //</xs:group> //<xs:group name="EG_RangeMarkupElements"> // <xs:choice> // <xs:group ref="EG_RangeMarkupElementsNoRev" minOccurs="0" maxOccurs="unbounded" /> // <xs:group ref="EG_RangeMarkupElementsRev" minOccurs="0" maxOccurs="unbounded" /> // <xs:element ref="w14:customXmlConflictInsRangeStart" minOccurs="0" /> // <xs:element ref="w14:customXmlConflictInsRangeEnd" minOccurs="0" /> // <xs:element ref="w14:customXmlConflictDelRangeStart" minOccurs="0" /> // <xs:element ref="w14:customXmlConflictDelRangeEnd" minOccurs="0" /> // </xs:choice> //</xs:group> //<xsd:group name="EG_MathContent"> // <xsd:choice> // <xsd:element ref="m:oMathPara"></xsd:element> // <xsd:element ref="m:oMath"></xsd:element> // </xsd:choice> //</xsd:group> // ################ the above schema has been changed by EcmaD ############## // ***** good case ****** // empty is ok target.Validate(validationContext); Assert.True(validationContext.Valid); // body.AppendChild(new SectionProperties()); target.Validate(validationContext); Assert.True(validationContext.Valid); body.PrependChild(new AltChunk()); target.Validate(validationContext); Assert.True(validationContext.Valid); // multiple AltChunk is ok body.PrependChild(new AltChunk()); target.Validate(validationContext); Assert.True(validationContext.Valid); body.InsertAfter(new Paragraph(), body.FirstChild); target.Validate(validationContext); Assert.True(validationContext.Valid); body.PrependChild(new MoveFromRangeStart()); target.Validate(validationContext); Assert.True(validationContext.Valid); body.PrependChild(new MoveFromRun()); target.Validate(validationContext); Assert.True(validationContext.Valid); body.PrependChild(new MoveFromRun()); target.Validate(validationContext); Assert.True(validationContext.Valid); body.PrependChild(new MoveFromRangeStart()); target.Validate(validationContext); Assert.True(validationContext.Valid); body.InsertAfter(new Paragraph(), body.FirstChild); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** // sectProperties can not be the first errorChild = body.FirstChild; body.PrependChild(new SectionProperties()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); body.RemoveChild(body.FirstChild); validationContext.Clear(); // can only have one sectProperties at last errorChild = body.AppendChild(new SectionProperties()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); body.RemoveChild(errorChild); validationContext.Clear(); // paragrap can be after sectProperties at last errorChild = body.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_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id); Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); body.RemoveChild(errorChild); validationContext.Clear(); // first is invalid errorChild = body.PrependChild(new Run()); 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(":altChunk", validationContext.Errors[0].Description); body.RemoveChild(errorChild); validationContext.Clear(); // invalid child in middle errorChild = body.InsertBefore(new Run(), body.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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); body.RemoveChild(errorChild); }
private void ValidatePpr(SdbSchemaDatas sdbSchemaDatas) { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; ParagraphProperties pPr = new ParagraphProperties(); var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(pPr).ParticleConstraint; var target = particleConstraint.ParticleValidator as ParticleValidator; validationContext.Element = pPr; var expected = pPr; //<xsd:complexType name="CT_PPr"> // <xsd:complexContent> // <xsd:extension base="CT_PPrBase"> // <xsd:sequence> // <xsd:element name="rPr" type="CT_ParaRPr" minOccurs="0"> // <xsd:element name="sectPr" type="CT_SectPr" minOccurs="0"> // <xsd:element name="pPrChange" type="CT_PPrChange" minOccurs="0"> // </xsd:sequence> // </xsd:extension> // </xsd:complexContent> //</xsd:complexType> //<xsd:complexType name="CT_PPrBase"> // <xsd:sequence> // <xsd:element name="pStyle" type="CT_String" minOccurs="0"> // <xsd:element name="keepNext" type="CT_OnOff" minOccurs="0"> // <xsd:element name="keepLines" type="CT_OnOff" minOccurs="0"> // <xsd:element name="pageBreakBefore" type="CT_OnOff" minOccurs="0"> // <xsd:element name="framePr" type="CT_FramePr" minOccurs="0"> // <xsd:element name="widowControl" type="CT_OnOff" minOccurs="0"> // <xsd:element name="numPr" type="CT_NumPr" minOccurs="0"> // <xsd:element name="suppressLineNumbers" type="CT_OnOff" minOccurs="0"> // <xsd:element name="pBdr" type="CT_PBdr" minOccurs="0"> // <xsd:element name="shd" type="CT_Shd" minOccurs="0"> // <xsd:element name="tabs" type="CT_Tabs" minOccurs="0"> // <xsd:element name="suppressAutoHyphens" type="CT_OnOff" minOccurs="0"> // <xsd:element name="kinsoku" type="CT_OnOff" minOccurs="0"> // <xsd:element name="wordWrap" type="CT_OnOff" minOccurs="0"> // <xsd:element name="overflowPunct" type="CT_OnOff" minOccurs="0"> // <xsd:element name="topLinePunct" type="CT_OnOff" minOccurs="0"> // <xsd:element name="autoSpaceDE" type="CT_OnOff" minOccurs="0"> // <xsd:element name="autoSpaceDN" type="CT_OnOff" minOccurs="0"> // <xsd:element name="bidi" type="CT_OnOff" minOccurs="0"> // <xsd:element name="adjustRightInd" type="CT_OnOff" minOccurs="0"> // <xsd:element name="snapToGrid" type="CT_OnOff" minOccurs="0"> // <xsd:element name="spacing" type="CT_Spacing" minOccurs="0"> // <xsd:element name="ind" type="CT_Ind" minOccurs="0"> // <xsd:element name="contextualSpacing" type="CT_OnOff" minOccurs="0"> // <xsd:element name="mirrorIndents" type="CT_OnOff" minOccurs="0"> // <xsd:element name="suppressOverlap" type="CT_OnOff" minOccurs="0"> // <xsd:element name="jc" type="CT_Jc" minOccurs="0"> // <xsd:element name="textDirection" type="CT_TextDirection" minOccurs="0"> // <xsd:element name="textAlignment" type="CT_TextAlignment" minOccurs="0"> // <xsd:element name="textboxTightWrap" type="CT_TextboxTightWrap" minOccurs="0"> // <xsd:element name="outlineLvl" type="CT_DecimalNumber" minOccurs="0"> // <xsd:element name="divId" type="CT_DecimalNumber" minOccurs="0"> // <xsd:element name="cnfStyle" type="CT_Cnf" minOccurs="0" maxOccurs="1"> // </xsd:sequence> //</xsd:complexType> // ***** good case ****** // empty is ok target.Validate(validationContext); Assert.True(validationContext.Valid); // pPr.AppendChild(new KeepLines()); target.Validate(validationContext); Assert.True(validationContext.Valid); // pPr.AppendChild(new Tabs()); target.Validate(validationContext); Assert.True(validationContext.Valid); // pPr.AppendChild(new Kinsoku()); target.Validate(validationContext); Assert.True(validationContext.Valid); // pPr.AppendChild(new OutlineLevel()); target.Validate(validationContext); Assert.True(validationContext.Valid); // pPr.AppendChild(new ConditionalFormatStyle()); target.Validate(validationContext); Assert.True(validationContext.Valid); // pPr.AppendChild(new ParagraphMarkRunProperties()); target.Validate(validationContext); Assert.True(validationContext.Valid); // pPr.AppendChild(new SectionProperties()); target.Validate(validationContext); Assert.True(validationContext.Valid); // pPr.AppendChild(new ParagraphPropertiesChange()); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** // SectionProperties dup error errorChild = pPr.AppendChild(new SectionProperties()); 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_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id); Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); pPr.RemoveChild(errorChild); validationContext.Clear(); // SectionProperties order wrong errorChild = pPr.FirstChild; pPr.PrependChild(new SectionProperties()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); pPr.RemoveChild(pPr.FirstChild); }
private void TestSimpleAll2(SdbSchemaDatas sdbSchemaDatas) { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; ShapeLayout shapeLayout = new ShapeLayout(); var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(shapeLayout).ParticleConstraint; var target = particleConstraint.ParticleValidator as AllParticleValidator; validationContext.Element = shapeLayout; var expected = shapeLayout; //<xsd:complexType name="CT_ShapeLayout"> // <xsd:all> // <xsd:element name="idmap" type="CT_IdMap" minOccurs="0"> // <xsd:element name="regrouptable" type="CT_RegroupTable" minOccurs="0"> // <xsd:element name="rules" type="CT_Rules" minOccurs="0"> // </xsd:all> // <xsd:attributeGroup ref="v:AG_Ext" /> //</xsd:complexType> // ***** good case ****** // empty is ok target.Validate(validationContext); Assert.True(validationContext.Valid); // any one is ok shapeLayout.AppendChild(new RegroupTable()); target.Validate(validationContext); Assert.True(validationContext.Valid); // any order is ok shapeLayout.AppendChild(new ShapeIdMap()); target.Validate(validationContext); Assert.True(validationContext.Valid); // any order is ok shapeLayout.AppendChild(new Rules()); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** // first is invlaid errorChild = shapeLayout.PrependChild(new Paragraphs()); 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(":idmap", validationContext.Errors[0].Description); Assert.Contains(":rules", validationContext.Errors[0].Description); shapeLayout.RemoveChild(errorChild); validationContext.Clear(); //invalid child in middle errorChild = shapeLayout.InsertBefore(new Paragraphs(), shapeLayout.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(":rules", validationContext.Errors[0].Description); shapeLayout.RemoveChild(errorChild); validationContext.Clear(); // dup errorChild = shapeLayout.FirstChild; shapeLayout.PrependChild(new RegroupTable()); 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_AllElement", validationContext.Errors[0].Id); Assert.Same(errorChild, validationContext.Errors[0].RelatedNode); shapeLayout.RemoveChild(errorChild); }
private void TestSimpleAll(SdbSchemaDatas sdbSchemaDatas) { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; Properties properties = new Properties(); var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(properties).ParticleConstraint; var target = particleConstraint.ParticleValidator as AllParticleValidator; validationContext.Element = properties; var expected = properties; //<xsd:complexType name="CT_Properties"> // <xsd:all> // <xsd:element name="Template" minOccurs="0" maxOccurs="1" type="xsd:string"> // <xsd:element name="Manager" minOccurs="0" maxOccurs="1" type="xsd:string"> // <xsd:element name="Company" minOccurs="0" maxOccurs="1" type="xsd:string"> // <xsd:element name="Pages" minOccurs="0" maxOccurs="1" type="xsd:int"> // <xsd:element name="Words" minOccurs="0" maxOccurs="1" type="xsd:int"> // <xsd:element name="Characters" minOccurs="0" maxOccurs="1" type="xsd:int"> // <xsd:element name="PresentationFormat" minOccurs="0" maxOccurs="1" type="xsd:string"> // <xsd:element name="Lines" minOccurs="0" maxOccurs="1" type="xsd:int"> // <xsd:element name="Paragraphs" minOccurs="0" maxOccurs="1" type="xsd:int"> // <xsd:element name="Slides" minOccurs="0" maxOccurs="1" type="xsd:int"> // <xsd:element name="Notes" minOccurs="0" maxOccurs="1" type="xsd:int"> // <xsd:element name="TotalTime" minOccurs="0" maxOccurs="1" type="xsd:int"> // <xsd:element name="HiddenSlides" minOccurs="0" maxOccurs="1" type="xsd:int"> // <xsd:element name="MMClips" minOccurs="0" maxOccurs="1" type="xsd:int"> // <xsd:element name="ScaleCrop" minOccurs="0" maxOccurs="1" type="xsd:boolean"> // <xsd:element name="HeadingPairs" minOccurs="0" maxOccurs="1" type="CT_VectorVariant"> // <xsd:element name="TitlesOfParts" minOccurs="0" maxOccurs="1" type="CT_VectorLpstr"> // <xsd:element name="LinksUpToDate" minOccurs="0" maxOccurs="1" type="xsd:boolean"> // <xsd:element name="CharactersWithSpaces" minOccurs="0" maxOccurs="1" type="xsd:int"> // <xsd:element name="SharedDoc" minOccurs="0" maxOccurs="1" type="xsd:boolean"> // <xsd:element name="HyperlinkBase" minOccurs="0" maxOccurs="1" type="xsd:string"> // <xsd:element name="HLinks" minOccurs="0" maxOccurs="1" type="CT_VectorVariant"> // <xsd:element name="HyperlinksChanged" minOccurs="0" maxOccurs="1" type="xsd:boolean"> // <xsd:element name="DigSig" minOccurs="0" maxOccurs="1" type="CT_DigSigBlob"> // <xsd:element name="Application" minOccurs="0" maxOccurs="1" type="xsd:string"> // <xsd:element name="AppVersion" minOccurs="0" maxOccurs="1" type="xsd:string"> // <xsd:element name="DocSecurity" minOccurs="0" maxOccurs="1" type="xsd:int"> // </xsd:all> //</xsd:complexType> // ***** good case ****** // empty is ok target.Validate(validationContext); Assert.True(validationContext.Valid); // any one is ok properties.AppendChild(new Company()); target.Validate(validationContext); Assert.True(validationContext.Valid); // any order is ok properties.AppendChild(new Template()); target.Validate(validationContext); Assert.True(validationContext.Valid); // any order is ok properties.AppendChild(new DocumentSecurity()); target.Validate(validationContext); Assert.True(validationContext.Valid); // any order is ok properties.AppendChild(new HyperlinkBase()); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** // first is invlaid errorChild = properties.PrependChild(new Properties()); 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(":Template", validationContext.Errors[0].Description); Assert.Contains(":DocSecurity", validationContext.Errors[0].Description); properties.RemoveChild(errorChild); validationContext.Clear(); //invalid child in middle errorChild = properties.InsertBefore(new Properties(), properties.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.DoesNotContain(":Template", validationContext.Errors[0].Description); Assert.Contains(":AppVersion", validationContext.Errors[0].Description); properties.RemoveChild(errorChild); validationContext.Clear(); // dup errorChild = properties.FirstChild; properties.PrependChild(new Company()); 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_AllElement", validationContext.Errors[0].Id); Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); properties.RemoveChild(errorChild); }
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); }
public void TestSimpleSequence() { ValidationContext validationContext = new ValidationContext(); //<xsd:complexType name="CT_FFDDList"> // <xsd:sequence> // <xsd:element name="result" type="CT_DecimalNumber" minOccurs="0"> // <xsd:element name="default" type="CT_DecimalNumber" minOccurs="0"> // <xsd:element name="listEntry" type="CT_String" minOccurs="0" maxOccurs="unbounded"> // </xsd:sequence> //</xsd:complexType> DropDownListFormField ddList = new DropDownListFormField(); var particleConstraint = ddList.ParticleConstraint.Build(Version); var target = particleConstraint.ParticleValidator as SequenceParticleValidator; validationContext.Element = ddList; // ***** good case ****** target.Validate(validationContext); Assert.True(validationContext.Valid); ddList.AppendChild(new DropDownListSelection()); target.Validate(validationContext); Assert.True(validationContext.Valid); ddList.AppendChild(new DefaultDropDownListItemIndex()); target.Validate(validationContext); Assert.True(validationContext.Valid); ddList.AppendChild(new ListEntryFormField()); target.Validate(validationContext); Assert.True(validationContext.Valid); ddList.AppendChild(new ListEntryFormField()); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** ddList = new DropDownListFormField(); validationContext.Element = ddList; var expected = ddList; // invalid child OpenXmlElement errorChild = ddList.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(":result", validationContext.Errors[0].Description); validationContext.Clear(); // 2nd child is invalid ddList.PrependChild(new DropDownListSelection()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); validationContext.Clear(); // the sequence of the first 2 children are wrong errorChild = ddList.FirstChild; ddList.PrependChild(new DefaultDropDownListItemIndex()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); validationContext.Clear(); // 1st and 2nd are same type, maxOccurs error errorChild = ddList.FirstChild; ddList.PrependChild(new DefaultDropDownListItemIndex()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); validationContext.Clear(); // the 2nd and 3rd are same type, maxOccurs error ddList.PrependChild(new DropDownListSelection()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); validationContext.Clear(); // expectedNode are now the 4th, the first 3 are OK. ddList.InsertAfter(new ListEntryFormField(), errorChild); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); }
public void TestSimpleSequence4() { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; ColorTransformCategories categories = new ColorTransformCategories(); var expected = categories; var particleConstraint = categories.ParticleConstraint.Build(Version); var target = particleConstraint.ParticleValidator as SequenceParticleValidator; validationContext.Element = categories; //<xsd:complexType name="CT_CTCategories"> // <xsd:sequence minOccurs="0" maxOccurs="unbounded"> // <xsd:element name="cat" type="CT_CTCategory" minOccurs="0" maxOccurs="unbounded"> // </xsd:sequence> //</xsd:complexType> // ***** good case ****** // empty is OK target.Validate(validationContext); Assert.True(validationContext.Valid); categories.AppendChild(new ColorTransformCategory()); target.Validate(validationContext); Assert.True(validationContext.Valid); categories.AppendChild(new ColorTransformCategory()); target.Validate(validationContext); Assert.True(validationContext.Valid); categories.AppendChild(new ColorTransformCategory()); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** // 1st child is invalid errorChild = categories.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(":cat", validationContext.Errors[0].Description); validationContext.Clear(); // last child is invalid categories.RemoveChild(errorChild); errorChild = categories.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(":cat", validationContext.Errors[0].Description); validationContext.Clear(); // 2nd child is invalid categories.RemoveChild(errorChild); errorChild = categories.InsertAfter(new Paragraph(), categories.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(":cat", validationContext.Errors[0].Description); validationContext.Clear(); // 3rd child is invalid categories.RemoveChild(errorChild); errorChild = categories.InsertBefore(new Paragraph(), categories.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(":cat", validationContext.Errors[0].Description); validationContext.Clear(); // only one invalid child categories.RemoveAllChildren(); errorChild = categories.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(":cat", validationContext.Errors[0].Description); }
private void TestSimpleGroup(SdbSchemaDatas sdbSchemaDatas) { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; Header header = new Header(); var expected = header; var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(header).ParticleConstraint; // the complex type contains a <xsd:group .../> as child var target = particleConstraint.ParticleValidator as GroupParticleValidator; validationContext.Element = header; //<xsd:complexType name="CT_HdrFtr"> // <xsd:group ref="EG_BlockLevelElts" minOccurs="1" maxOccurs="unbounded" /> //</xsd:complexType> //<xs:group name="EG_BlockLevelElts"> // <xs:choice> // <xs:group ref="EG_BlockLevelEltsBase" minOccurs="0" maxOccurs="unbounded" /> // <xs:group ref="EG_BlockLevelChunkElts" minOccurs="0" maxOccurs="unbounded" /> // </xs:choice> //</xs:group> //<xs:group name="EG_BlockLevelEltsBase"> // <xs:choice> // <xs:element name="altChunk" type="CT_AltChunk" minOccurs="0" maxOccurs="unbounded"></xs:element> // </xs:choice> //</xs:group> //<xsd:group name="EG_BlockLevelChunkElts"> // <xsd:choice> // <xsd:group ref="EG_ContentBlockContent" minOccurs="0" maxOccurs="unbounded" /> // </xsd:choice> //</xsd:group> //<xs:group name="EG_ContentBlockContent"> // <xs:choice> // <xs:group ref="EG_ContentBlockContentBase" minOccurs="0" maxOccurs="unbounded" /> // <xs:group ref="EG_RunLevelElts" minOccurs="0" maxOccurs="unbounded" /> // </xs:choice> //</xs:group> //<xs:group name="EG_ContentBlockContentBase"> // <xs:choice> // <xs:element name="customXml" type="CT_CustomXmlBlock"></xs:element> // <xs:element name="sdt" type="CT_SdtBlock"></xs:element> // <xs:element name="p" type="CT_P" minOccurs="0" maxOccurs="unbounded"></xs:element> // <xs:element name="tbl" type="CT_Tbl" minOccurs="0" maxOccurs="unbounded"></xs:element> // </xs:choice> //</xs:group> // ***** good case ****** // empty is ok target.Validate(validationContext); Assert.True(validationContext.Valid); // Paragraph is ok header.Append(new Paragraph()); target.Validate(validationContext); Assert.True(validationContext.Valid); // Table is ok header.Append(new Table()); target.Validate(validationContext); Assert.True(validationContext.Valid); // more Paragraph is ok header.Append(new Paragraph()); target.Validate(validationContext); Assert.True(validationContext.Valid); // Sdt is ok header.Append(new SdtBlock()); target.Validate(validationContext); Assert.True(validationContext.Valid); // altChunk is ok header.Append(new AltChunk()); target.Validate(validationContext); Assert.True(validationContext.Valid); // altChunk is ok header.Append(new AltChunk()); target.Validate(validationContext); Assert.True(validationContext.Valid); // more Paragraph is ok header.Append(new Paragraph()); target.Validate(validationContext); Assert.True(validationContext.Valid); // ***** error case ****** //first is invalid errorChild = header.PrependChild(new Run()); 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(":altChunk", validationContext.Errors[0].Description); Assert.Contains(":tbl", validationContext.Errors[0].Description); header.RemoveChild(errorChild); validationContext.Clear(); //last is invalid errorChild = header.AppendChild(new Run()); 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(":altChunk", validationContext.Errors[0].Description); Assert.Contains(":tbl", validationContext.Errors[0].Description); header.RemoveChild(errorChild); }
private void TestSimpleGroup2(SdbSchemaDatas sdbSchemaDatas) { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; SectionProperties sectPr = new SectionProperties(); var expected = sectPr; var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(sectPr).ParticleConstraint; var target = particleConstraint.ParticleValidator as SequenceParticleValidator; validationContext.Element = sectPr; //<xsd:complexType name="CT_SectPr"> // <xsd:sequence> // <xsd:group ref="EG_HdrFtrReferences" minOccurs="0" maxOccurs="6"></xsd:group> // <xsd:group ref="EG_SectPrContents" minOccurs="0"></xsd:group> // <xsd:element name="sectPrChange" type="CT_SectPrChange" minOccurs="0"> // </xsd:sequence> // <xsd:attributeGroup ref="AG_SectPrAttributes"></xsd:attributeGroup> //</xsd:complexType> //<xsd:group name="EG_HdrFtrReferences"> // <xsd:choice> // <xsd:element name="headerReference" type="CT_HdrFtrRef" minOccurs="0"> // <xsd:element name="footerReference" type="CT_HdrFtrRef" minOccurs="0"> // </xsd:choice> //</xsd:group> //<xsd:group name="EG_SectPrContents"> // <xsd:sequence> // <xsd:element name="footnotePr" type="CT_FtnProps" minOccurs="0"> // <xsd:element name="endnotePr" type="CT_EdnProps" minOccurs="0"> // <xsd:element name="type" type="CT_SectType" minOccurs="0"> // <xsd:element name="pgSz" type="CT_PageSz" minOccurs="0"> // <xsd:element name="pgMar" type="CT_PageMar" minOccurs="0"> // <xsd:element name="paperSrc" type="CT_PaperSource" minOccurs="0"> // <xsd:element name="pgBorders" type="CT_PageBorders" minOccurs="0"> // <xsd:element name="lnNumType" type="CT_LineNumber" minOccurs="0"> // <xsd:element name="pgNumType" type="CT_PageNumber" minOccurs="0"> // <xsd:element name="cols" type="CT_Columns" minOccurs="0"> // <xsd:element name="formProt" type="CT_OnOff" minOccurs="0"> // <xsd:element name="vAlign" type="CT_VerticalJc" minOccurs="0"> // <xsd:element name="noEndnote" type="CT_OnOff" minOccurs="0"> // <xsd:element name="titlePg" type="CT_OnOff" minOccurs="0"> // <xsd:element name="textDirection" type="CT_TextDirection" minOccurs="0"> // <xsd:element name="bidi" type="CT_OnOff" minOccurs="0"> // <xsd:element name="rtlGutter" type="CT_OnOff" minOccurs="0"> // <xsd:element name="docGrid" type="CT_DocGrid" minOccurs="0"> // <xsd:element name="printerSettings" type="CT_Rel" minOccurs="0"> // </xsd:sequence> //</xsd:group> // ***** good case ****** // empty is ok target.Validate(validationContext); Assert.True(validationContext.Valid); // headerReference is ok sectPr.Append(new HeaderReference()); target.Validate(validationContext); Assert.True(validationContext.Valid); // headerReference and footerReference sectPr.Append(new FooterReference()); target.Validate(validationContext); Assert.True(validationContext.Valid); // footerReference sectPr.RemoveChild(sectPr.FirstChild); target.Validate(validationContext); Assert.True(validationContext.Valid); // 3 group <= 6, ok sectPr.Append(new HeaderReference(), new HeaderReference()); target.Validate(validationContext); Assert.True(validationContext.Valid); // 5 group <= 6, ok sectPr.Append(new HeaderReference(), new HeaderReference()); target.Validate(validationContext); Assert.True(validationContext.Valid); // 6 group <= 6, ok sectPr.Append(new HeaderReference()); target.Validate(validationContext); Assert.True(validationContext.Valid); // no EG_SectPrContents is ok sectPr.RemoveAllChildren(); sectPr.Append(new HeaderReference(), new FooterReference(), new SectionPropertiesChange()); Assert.True(validationContext.Valid); // test EG_SectPrContents sectPr.RemoveAllChildren(); sectPr.Append(new HeaderReference(), new FooterReference(), new SectionType()); Assert.True(validationContext.Valid); // sectPr.AppendChild(new PaperSource()); Assert.True(validationContext.Valid); sectPr.AppendChild(new TitlePage()); Assert.True(validationContext.Valid); sectPr.AppendChild(new PrinterSettingsReference()); Assert.True(validationContext.Valid); sectPr.AppendChild(new SectionPropertiesChange()); Assert.True(validationContext.Valid); sectPr.RemoveAllChildren(); sectPr.Append(new SectionPropertiesChange()); Assert.True(validationContext.Valid); // ***** error case ****** // 7 group > 6, error sectPr.RemoveAllChildren(); sectPr.Append(new HeaderReference(), new HeaderReference(), new FooterReference(), new FooterReference(), new HeaderReference(), new HeaderReference()); errorChild = sectPr.AppendChild(new HeaderReference()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); sectPr.RemoveChild(errorChild); validationContext.Clear(); //first is invalid errorChild = sectPr.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(":headerReference", validationContext.Errors[0].Description); Assert.Contains(":footerReference", validationContext.Errors[0].Description); Assert.DoesNotContain(":footnotePr", validationContext.Errors[0].Description); Assert.DoesNotContain(":sectPrChange", validationContext.Errors[0].Description); sectPr.RemoveChild(errorChild); validationContext.Clear(); //invalid child in middle errorChild = sectPr.InsertBefore(new Paragraph(), sectPr.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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); sectPr.RemoveChild(errorChild); validationContext.Clear(); // order wrong errorChild = sectPr.FirstChild; sectPr.PrependChild(new SectionType()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); validationContext.Clear(); // dup error sectPr.RemoveAllChildren(); sectPr.Append(new HeaderReference(), new PaperSource()); errorChild = sectPr.AppendChild(new PaperSource()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); sectPr.RemoveChild(errorChild); validationContext.Clear(); // out of order error errorChild = sectPr.AppendChild(new SectionType()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); sectPr.RemoveChild(errorChild); validationContext.Clear(); // out of order error sectPr.AppendChild(new SectionPropertiesChange()); errorChild = sectPr.AppendChild(new SectionType()); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); }
private void TestSimpleSequence3(SdbSchemaDatas sdbSchemaDatas) { ValidationContext validationContext = new ValidationContext(); 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(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); }
public void AnyParticleValidateTest() { ValidationContext validationContext = new ValidationContext(); OpenXmlElement errorChild; TextBox textBox = new TextBox(); var particleConstraint = textBox.ParticleConstraint.Build(FileFormatVersions.Office2007); var target = particleConstraint.ParticleValidator as ChoiceParticleValidator; validationContext.Element = textBox; var expected = textBox; //<xsd:complexType name="CT_Textbox"> // <xsd:choice> // <xsd:element ref="w:txbxContent" minOccurs="0" /> // <xsd:any namespace="##local" processContents="skip" /> // </xsd:choice> //</xsd:complexType> // ***** good case ****** // empty is OK target.Validate(validationContext); Assert.True(validationContext.Valid); // any element without namespace is ok errorChild = textBox.AppendChild(new OpenXmlUnknownElement("test")); Assert.True(string.IsNullOrEmpty(errorChild.NamespaceUri)); target.Validate(validationContext); Assert.True(validationContext.Valid); textBox.RemoveChild(errorChild); // ***** error case ****** // any element with namespace is invalid errorChild = textBox.AppendChild(new TextBox()); 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(":txbxContent", validationContext.Errors[0].Description); Assert.Contains("##local", validationContext.Errors[0].Description); textBox.RemoveChild(errorChild); validationContext.Clear(); // any element with namespace is invalid errorChild = textBox.AppendChild(new OpenXmlUnknownElement(string.Empty, "test", "http://test")); 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(":txbxContent", validationContext.Errors[0].Description); Assert.Contains("##local", validationContext.Errors[0].Description); textBox.RemoveChild(errorChild); validationContext.Clear(); // any element with namespace is invalid errorChild = textBox.AppendChild(new OpenXmlUnknownElement("t", "test", "http://test")); 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(":txbxContent", validationContext.Errors[0].Description); Assert.Contains("##local", validationContext.Errors[0].Description); textBox.RemoveChild(errorChild); validationContext.Clear(); // only one element without namespace is allowed textBox.AppendChild(new OpenXmlUnknownElement("test")); errorChild = textBox.AppendChild(new OpenXmlUnknownElement("errorElement")); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); textBox.RemoveAllChildren(); validationContext.Clear(); // only one element without namespace is allowed textBox.AppendChild(new OpenXmlUnknownElement("test")); errorChild = textBox.AppendChild(new OpenXmlUnknownElement("test")); 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.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description); textBox.RemoveAllChildren(); }