System.Xml.Tests.XmlWriterTests_InvalidSurrogate.XmlWriterChecksUpperBoundOfLowerSurrogate_newBehavior C# (CSharp) Method

XmlWriterChecksUpperBoundOfLowerSurrogate_newBehavior() private method

        public static void XmlWriterChecksUpperBoundOfLowerSurrogate_newBehavior()
        {
            // Turn the switch off to get the new behavior in case the platform has it on by default
            AppContext.SetSwitch(@"Switch.System.Xml.DontThrowOnInvalidSurrogatePairs", false);

            using (XmlWriter writer = CreateUtf8Writer())
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("test");
                char[] invalidSurrogatePair = new char[] { (char)(SurHighStart + 5), (char)(SurLowEnd + 1) };

                Assert.Throws<ArgumentException>(() =>
                {
                    writer.WriteRaw(invalidSurrogatePair, 0, invalidSurrogatePair.Length);
                });
            }
        }