This library provides a collection of fake stream for testing. A constant stream is an lazy stream (not backed by a base stream) and provide a basic reading operations of a stream of bytes (the same byte or stride of bytes). The streams imitate a NetworkStream by providing only the "Read" operation and not "Seek", "Length" or "Write".
$ dotnet add package ConstantStreamA collection of fake streams for testing purposes.
The library have three fake stream types:
One util Stream:
For example:
// The constant byte stream
var cbs = ConstantByteStream(5, (byte) 'A');
(new StreamReader(cbs).ReadToEnd() // Should return "AAAAA"
// The constant stride stream
ConstantStrideStream(10, Encoding.UTF8.GetBytes("ABC")); // Should read as "ABCABCABCA"
// The TimedStream
var timedStream = new TimedStream(1024, (byte)'c'); // Just like a constant byte stream
timedStream.Delays.Add(0, TimeSpan.FromMilliseconds(200)); // add a wait in position 0 of 200 ms
timedStream.Delays.Add(15, TimeSpan.FromMilliseconds(250)); // add a wait in position 15 of 250 ms
timedStream.Delays.Add(1000, TimeSpan.FromMinutes(1)); // add a wait in position 1000 of 1 min
// the timedStream should take about 1 minute + 450 ms + reading overhead(ms) to read in total
using ConstantStream;
// Creates a 1 Mb stream of zeroes.
var zeroesStream = new ConstantByteStream(1024*1024, (byte)0);
// Creates a 1 Gb stream full of 's'.
var sStream = new ConstantByteStream(1024*1024*1024, (byte)'s');
// Handy factory methods (From*) for ConstantByteStream
var zeroesStreamEasy = ConstantByteStream.FromZeroes(1024*1024); // 1 Mb of zeroes
var onesStreamEasy = ConstantByteStream.FromOnes(1024); // 1 Kb of ones
var onesStreamEasy = ConstantByteStream.FromFromA(42); // 42 bytes of 'a'
// Handy factory methods (From*) for ConstantStrideStream
var zeroesStreamEasy = ConstantStrideStream.FromNumbers(1024*1024); // 01234567890123456... numbers from 0 to 9 in a loop
var zeroesStreamEasy = ConstantStrideStream.FromAlphabet(1024); // abcdefghijkl.... alphabet in a loop
The Stream doesnt have a base stream. Its a fake generator and provide a simple Stream that generates large amounts of data. It can be used with stream readers like TextReader, copyTo(file), HttpBody, crypto readers, and compression readers.