From 5ce8eec31078e088c0fe7501b07cb656aed835a3 Mon Sep 17 00:00:00 2001 From: Huangli Wu Date: Tue, 28 Nov 2017 13:58:04 -0800 Subject: [PATCH] Add a test to verify the XmlQualifiedName "duration" of TimeSpan type. (#25277) * Add a test to verify the XmlQualifiedName "duration" for TimeSpan type. * Skip on netfx. Update test code. * Not use smartcompare. * Update verification * Update the verification. * Pull out the baseline as a variable. --- .../XmlSerializerTests.RuntimeOnly.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.RuntimeOnly.cs b/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.RuntimeOnly.cs index 0eb45820c158..dc004d5b83a0 100644 --- a/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.RuntimeOnly.cs +++ b/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.RuntimeOnly.cs @@ -2922,4 +2922,29 @@ public static void Xml_DefaultNamespaceChange_ObjectAsRoot() Assert.StrictEqual(value, actual); } + + [ConditionalFact(nameof(IsTimeSpanSerializationAvailable))] + public static void VerifyRestrictionElementForTimeSpanTest() + { + var schemas = new XmlSchemas(); + var exporter = new XmlSchemaExporter(schemas); + XmlTypeMapping mapping = new XmlReflectionImporter().ImportTypeMapping(typeof(TimeSpan)); + exporter.ExportTypeMapping(mapping); + XmlSchema schema = schemas.Where(s => s.TargetNamespace == "http://microsoft.com/wsdl/types/").FirstOrDefault(); + Assert.NotNull(schema); + var ms = new MemoryStream(); + schema.Write(ms); + ms.Position = 0; + string actualOutput = new StreamReader(ms).ReadToEnd(); + XElement element = XElement.Parse(actualOutput); + while (element.Elements().Count() != 0) + { + element = element.Elements().First(); + } + + string expectedAttribute = "xs:duration"; + string baseline = "\r\n\r\n \r\n \r\n \r\n"; + Assert.True(element.LastAttribute.Value == expectedAttribute, string.Format("{0}Test failed for wrong output from schema: {0}Expected Output: {1}{0}Actual Output: {2}", + Environment.NewLine, baseline, actualOutput)); + } }