private async Task WriteAsync(TestStream stream) { JsonSerializerOptions options = new JsonSerializerOptions { // Will likely default to 4K due to buffer pooling. DefaultBufferSize = 1 }; { LargeDataTestClass obj = new LargeDataTestClass(); obj.Initialize(); obj.Verify(); await Serializer.SerializeWrapper(stream, obj, options : options); } // Must be changed if the test classes change: Assert.Equal(551_368, stream.TestWriteBytesCount); // We should have more than one write called due to the large byte count. Assert.InRange(stream.TestWriteCount, 1, int.MaxValue); // We don't auto-flush. Assert.Equal(0, stream.TestFlushCount); }
private async Task ReadAsync(TestStream stream) { JsonSerializerOptions options = new JsonSerializerOptions { // Will likely default to 4K due to buffer pooling. DefaultBufferSize = 1 }; LargeDataTestClass obj = await Serializer.DeserializeWrapper <LargeDataTestClass>(stream, options); // Must be changed if the test classes change; may be > since last read may not have filled buffer. Assert.InRange(stream.TestRequestedReadBytesCount, 551368, int.MaxValue); // We should have more than one read called due to the large byte count. Assert.InRange(stream.TestReadCount, 1, int.MaxValue); // We don't auto-flush. Assert.Equal(0, stream.TestFlushCount); obj.Verify(); }
private static async Task ReadAsync(TestStream stream) { JsonSerializerOptions options = new JsonSerializerOptions { // Will likely default to 4K due to buffer pooling. DefaultBufferSize = 1 }; LargeDataTestClass obj = await JsonSerializer.ReadAsync <LargeDataTestClass>(stream, options); // Must be changed if the test classes change; may be > since last read may not have filled buffer. Assert.True(stream.TestRequestedReadBytesCount >= 551368); // We should have more than one read called due to the large byte count. Assert.True(stream.TestReadCount > 0); // We don't auto-flush. Assert.True(stream.TestFlushCount == 0); obj.Verify(); }
public static async Task PipeRoundTripAsync() { LargeDataTestClass objOriginal = new LargeDataTestClass(); objOriginal.Initialize(); objOriginal.Verify(); Pipe pipe = new Pipe(new PipeOptions(readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline)); Task toTask = JsonSerializer.WriteAsync(objOriginal, pipe.Writer); Task <LargeDataTestClass> fromTask = JsonSerializer.ReadAsync <LargeDataTestClass>(pipe.Reader); await toTask; pipe.Writer.Complete(); LargeDataTestClass objCopy = await fromTask; pipe.Reader.Complete(); objCopy.Verify(); }