Issue incorrect exception message (#34416)
authormrj001 <62225294+mrj001@users.noreply.github.com>
Mon, 13 Apr 2020 23:26:38 +0000 (17:26 -0600)
committerGitHub <noreply@github.com>
Mon, 13 Apr 2020 23:26:38 +0000 (16:26 -0700)
* Created unit test to trigger incorrect error message.  This also covers a previously uncovered branch.

* Added string resource for the fractionDigits error, and changed the error message being thrown when the derived type has a larger fractionDigits value than the parent type.

src/libraries/System.Private.Xml/src/Resources/Strings.resx
src/libraries/System.Private.Xml/src/System/Xml/Schema/FacetChecker.cs
src/libraries/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Compile.cs

index ca4b85c..e204228 100644 (file)
@@ -1,4 +1,5 @@
-<root>
+<?xml version="1.0" encoding="utf-8"?>
+<root>
   <!-- 
     Microsoft ResX Schema 
     
   <data name="Sch_TotalDigitsMismatch" xml:space="preserve">
     <value>It is an error if the derived 'totalDigits' facet value is greater than the parent 'totalDigits' facet value.</value>
   </data>
+  <data name="Sch_FractionDigitsMismatch" xml:space="preserve">
+    <value>It is an error if the derived 'fractionDigits' facet value is greater than the parent 'fractionDigits' facet value.</value>
+  </data>
   <data name="Sch_FacetBaseFixed" xml:space="preserve">
     <value>Values that are declared as {fixed} in a base type can not be changed in a derived type.</value>
   </data>
@@ -3452,4 +3456,4 @@ Usage: dotnet {0} [--assembly &lt;assembly file path&gt;] [--type &lt;type name&
   <data name="CompilingScriptsNotSupported" xml:space="preserve">
     <value>Compiling JScript/CSharp scripts is not supported</value>
   </data>
-</root>
\ No newline at end of file
+</root>
index fd0cffa..e04a2f1 100644 (file)
@@ -338,7 +338,7 @@ namespace System.Xml.Schema
                 {
                     if (_derivedRestriction.FractionDigits > _datatype.Restriction.FractionDigits)
                     {
-                        throw new XmlSchemaException(SR.Sch_TotalDigitsMismatch, string.Empty);
+                        throw new XmlSchemaException(SR.Sch_FractionDigitsMismatch, string.Empty);
                     }
                 }
                 SetFlag(facet, RestrictionFlags.FractionDigits);
index d169d98..80842b9 100644 (file)
@@ -149,5 +149,32 @@ namespace System.Xml.Tests
                 Assert.Equal(0, errorCount);
             }
         }
+
+        [Fact]
+        public void FractionDigitsMismatch_Throws()
+        {
+            string schema = @"<?xml version='1.0' encoding='utf-8' ?>
+<xs:schema elementFormDefault='qualified'
+           xmlns:xs='http://www.w3.org/2001/XMLSchema'>
+    <xs:simpleType name='foo'>
+        <xs:restriction base='xs:decimal'>
+            <xs:fractionDigits value='8' fixed='true'/>
+        </xs:restriction>
+    </xs:simpleType>
+    <xs:simpleType name='bar'>
+        <xs:restriction base='foo'>
+            <xs:fractionDigits value='9'/>
+        </xs:restriction>
+    </xs:simpleType>
+</xs:schema>
+";
+
+            XmlSchemaSet ss = new XmlSchemaSet();
+            ss.Add(null, XmlReader.Create(new StringReader(schema)));
+
+            Exception ex = Assert.Throws<XmlSchemaException>(() => ss.Compile());
+            Assert.Contains("fractionDigits", ex.Message);
+            Assert.DoesNotContain("totalDigits", ex.Message);
+        }
     }
 }