public static void ReadXmlToken_Returns_Correct_XmlToken(string xml, int expectedTokenSize, XmlTokenType tokenType, string expectedXml = null) { var xmlBytes = Encoding.UTF8.GetBytes(xml); var expectedTokenBytes = xmlBytes; if (expectedXml != null) { expectedTokenBytes = Encoding.UTF8.GetBytes(expectedXml); } var buffer = new ReadOnlySequence <byte>(xmlBytes); var expectedToken = new XmlToken(new ReadOnlySequence <byte>(expectedTokenBytes), tokenType); (int actualTokenSize, var actualToken) = XmlTokenDeserializer.Deserialize(buffer); Assert.Equal(expectedTokenSize, actualTokenSize); Assert.Equal(expectedToken.Type, actualToken.Type); Assert.Equal(expectedToken.BufferSegments.ToArray(), actualToken.BufferSegments.ToArray()); }
public static void ReadXmlToken_Throws_Exception_For_Invalid_Xml(string xml) { var buffer = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes(xml)); Assert.Throws <FormatException>(() => XmlTokenDeserializer.Deserialize(buffer)); }