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); }
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(); }