Ejemplo n.º 1
0
        public void ReadOrWriteOneByteMoreThanLimitTakesAtMinimumOneSecond([Values(true, false)] bool read)
        {
            byte[] buf = new byte[this.length];
            using (var memstream = new MemoryStream(this.buffer))
                using (var underTest = new BandwidthLimitedStream(memstream, limit: this.limit)) {
                    var start = DateTime.Now;
                    if (read)
                    {
                        underTest.Read(buf, 0, (int)this.limit + 1);
                    }
                    else
                    {
                        underTest.Write(buf, 0, (int)this.limit + 1);
                    }

                    TimeSpan duration = DateTime.Now - start;
                    Assert.That(duration.TotalMilliseconds, Is.AtLeast(1000));
                }
        }
Ejemplo n.º 2
0
        public void WriteTest()
        {
            byte[] buf = new byte[this.length];
            using (MemoryStream memstream = new MemoryStream(this.buffer))
                using (BandwidthLimitedStream stream = new BandwidthLimitedStream(memstream, limit: this.length)) {
                    DateTime start = DateTime.Now;
                    stream.Write(buf, 0, this.length);
                    TimeSpan duration = DateTime.Now - start;
                    Assert.GreaterOrEqual(duration.TotalMilliseconds, 1000);
                    Assert.AreEqual(1, duration.TotalSeconds);
                }

            using (MemoryStream memstream = new MemoryStream(this.buffer))
                using (BandwidthLimitedStream stream = new BandwidthLimitedStream(memstream)) {
                    DateTime start = DateTime.Now;
                    stream.Write(buf, 0, this.length);
                    TimeSpan duration = DateTime.Now - start;
                    Assert.GreaterOrEqual(duration.TotalMilliseconds, 1000);
                    Assert.AreEqual(1, duration.TotalSeconds);
                }
        }