public void TestConstructor(int length, int maxLength, bool @readonly)
        {
            var bsp = new ByteStreamProvider("Test", CreateData(length), maxLength, @readonly);

            Assert.That(bsp.UnderlyingStreamIsReadonly, Is.EqualTo(@readonly));
            Assert.That(bsp.Length, Is.EqualTo(length));
            Assert.That(bsp.MaxLength, Is.EqualTo(maxLength));

            using (var ms = (MemoryStream)bsp.OpenRead())
            {
                var data = ms.ToArray();
                Assert.That(data, Is.Not.Null);
                Assert.That(data.Length, Is.EqualTo(length));
                for (var i = 0; i < length; i++)
                {
                    Assert.That(data[i], Is.EqualTo(bsp.Buffer[i]));
                }
            }

            try
            {
                using (var ms = (MemoryStream)bsp.OpenWrite(false))
                {
                    var sw = new BinaryWriter(ms);
                    sw.BaseStream.Position = 50;
                    for (var i = 0; i < 10; i++)
                    {
                        sw.Write((byte)i);
                    }
                    sw.Flush();
                    Assert.That(ms.Length, Is.EqualTo(length + 10));
                    Assert.That(bsp.Length, Is.EqualTo(length + 10));
                    Assert.That(bsp.Buffer[59], Is.EqualTo(9));
                }
            }
            catch (Exception ex)
            {
                if (ex is AssertionException)
                {
                    throw;
                }

                if (!@readonly)
                {
                    Assert.That(ex, Is.TypeOf(typeof(NotSupportedException)));
                    Assert.That(length, Is.EqualTo(maxLength));
                }
            }
        }
        public void TestConstructorText(string constructorText, int codepage)
        {
            var encoding = codepage == 0 ? Encoding.Default : Encoding.GetEncoding(codepage);

            var bsp = new ByteStreamProvider("Test", constructorText, encoding);

            Assert.That(bsp.UnderlyingStreamIsReadonly, Is.True);
            Assert.That(bsp.Length, Is.EqualTo(constructorText.Length));
            Assert.That(bsp.Length == bsp.MaxLength, Is.True);

            using (var streamreader = new StreamReader(bsp.OpenRead(), encoding))
            {
                var streamText = streamreader.ReadToEnd();
                Assert.That(streamText, Is.EqualTo(constructorText));
            }
        }