Esempio n. 1
0
        public async Task RoundTripAsync()
        {
            byte[] buffer;

            using (TestStream stream = new TestStream(1))
            {
                await WriteAsync(stream);

                // Make a copy
                buffer = stream.ToArray();
            }

            using (TestStream stream = new TestStream(buffer))
            {
                await ReadAsync(stream);
            }
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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();
        }