コード例 #1
0
        public void Bug743591(FileFormatVersions version)
        {
            var validator = new OpenXmlValidator(version);

            //<xsd:complexType name="CT_ColorScale">
            //  <xsd:sequence>
            //    <xsd:element name="cfvo" type="CT_Cfvo" minOccurs="2" maxOccurs="unbounded">
            //    <xsd:element name="color" type="x:CT_Color" minOccurs="2" maxOccurs="unbounded">
            //  </xsd:sequence>
            //</xsd:complexType>
            DocumentFormat.OpenXml.Spreadsheet.ColorScale colorScale = new DocumentFormat.OpenXml.Spreadsheet.ColorScale(
                "<x:colorScale xmlns:x=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">" +
                "    <x:cfvo type=\"min\" val=\"0\" />" +
                "    <x:color theme=\"4\" />" +
                "    <x:color theme=\"6\" />" +
                "</x:colorScale>");

            var results = validator.Validate(colorScale);

            Assert.Single(results);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", results.First().Id);
            Assert.EndsWith(":cfvo>.", results.First().Description);

            colorScale.PrependChild(new DocumentFormat.OpenXml.Spreadsheet.ConditionalFormatValueObject()
            {
                Type = DocumentFormat.OpenXml.Spreadsheet.ConditionalFormatValueObjectValues.Min
            });
            results = validator.Validate(colorScale);
            Assert.Empty(results);

            colorScale.PrependChild(new DocumentFormat.OpenXml.Spreadsheet.ConditionalFormatValueObject()
            {
                Type = DocumentFormat.OpenXml.Spreadsheet.ConditionalFormatValueObjectValues.Max
            });
            results = validator.Validate(colorScale);
            Assert.Empty(results);

            colorScale.LastChild.Remove();
            results = validator.Validate(colorScale);
            Assert.Single(results);
            Assert.Equal("Sch_IncompleteContentExpectingComplex", results.First().Id);
            Assert.EndsWith(":color>.", results.First().Description);

            colorScale.Append(new DocumentFormat.OpenXml.Spreadsheet.Color());
            colorScale.Append(new DocumentFormat.OpenXml.Spreadsheet.Color());
            results = validator.Validate(colorScale);
            Assert.Empty(results);
        }
コード例 #2
0
        private void Bug743591(OpenXmlValidator validator)
        {
              //<xsd:complexType name="CT_ColorScale">
              //  <xsd:sequence>
              //    <xsd:element name="cfvo" type="CT_Cfvo" minOccurs="2" maxOccurs="unbounded">
              //    <xsd:element name="color" type="x:CT_Color" minOccurs="2" maxOccurs="unbounded">
              //  </xsd:sequence>
              //</xsd:complexType>

            DocumentFormat.OpenXml.Spreadsheet.ColorScale colorScale = new DocumentFormat.OpenXml.Spreadsheet.ColorScale(
"<x:colorScale xmlns:x=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">" +
"    <x:cfvo type=\"min\" val=\"0\" />" +
"    <x:color theme=\"4\" />" +
"    <x:color theme=\"6\" />" +
"</x:colorScale>");

            var results = validator.Validate( colorScale);
            Assert.Equal(1, results.Count());
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", results.First().Id);
            Assert.True(results.First().Description.EndsWith(":cfvo>."));

            colorScale.PrependChild(new DocumentFormat.OpenXml.Spreadsheet.ConditionalFormatValueObject() { Type = DocumentFormat.OpenXml.Spreadsheet.ConditionalFormatValueObjectValues.Min });
            results = validator.Validate(colorScale);
            Assert.Equal(0, results.Count());

            colorScale.PrependChild(new DocumentFormat.OpenXml.Spreadsheet.ConditionalFormatValueObject() { Type = DocumentFormat.OpenXml.Spreadsheet.ConditionalFormatValueObjectValues.Max });
            results = validator.Validate(colorScale);
            Assert.Equal(0, results.Count());

            colorScale.LastChild.Remove();
            results = validator.Validate(colorScale);
            Assert.Equal(1, results.Count());
            Assert.Equal("Sch_IncompleteContentExpectingComplex", results.First().Id);
            Assert.True(results.First().Description.EndsWith(":color>."));

            colorScale.Append(new DocumentFormat.OpenXml.Spreadsheet.Color());
            colorScale.Append(new DocumentFormat.OpenXml.Spreadsheet.Color());
            results = validator.Validate(colorScale);
            Assert.Equal(0, results.Count());

        }