public void TestReadWithMultipleBlocks() { ITokenReaderState tokenReaderState = new JsonTokenReaderState(); ITokenReader tokenReader = new JsonTokenReader(); String expectedMessage = TestData.HelloRequest.Json; (String left, String right)messageBlocks = expectedMessage.Divide(); ReadOnlySequence <byte> firstBuffer = new ReadOnlySequence <byte>(JsonSerializationSettings.Encoding.GetBytes(messageBlocks.left)); ReadOnlySequence <byte> secondBuffer = new ReadOnlySequence <byte>(JsonSerializationSettings.Encoding.GetBytes(messageBlocks.left + messageBlocks.right)); bool firstReadResult = tokenReader.Read(ref tokenReaderState, ref firstBuffer, out _, out _); Assert.IsFalse(firstReadResult); bool secondReadResult = tokenReader.Read(ref tokenReaderState, ref secondBuffer, out ReadOnlySequence <byte> token, out _); Assert.IsTrue(secondReadResult); String actualMessage = JsonSerializationSettings.Encoding.GetString(token.ToArray()); Assert.IsTrue(JsonComparer.AreEqual(expectedMessage, actualMessage)); }
public void TestReadWithSingleBlock() { ITokenReaderState tokenReaderState = new JsonTokenReaderState(); ITokenReader tokenReader = new JsonTokenReader(); String expectedMessage = TestData.HelloRequest.Json; ReadOnlySequence <byte> buffer = new ReadOnlySequence <byte>(JsonSerializationSettings.Encoding.GetBytes(expectedMessage)); bool readResult = tokenReader.Read(ref tokenReaderState, ref buffer, out ReadOnlySequence <byte> token, out _); Assert.IsTrue(readResult); String actualMessage = JsonSerializationSettings.Encoding.GetString(token.ToArray()); Assert.IsTrue(JsonComparer.AreEqual(expectedMessage, actualMessage)); }