public void ReadTest() { byte[] buf = new byte[this.length]; int counter = 0; using (MemoryStream memstream = new MemoryStream(this.buffer)) using (BandwidthLimitedStream stream = new BandwidthLimitedStream(memstream, limit: this.length)) { DateTime start = DateTime.Now; while (counter < this.length) { counter += stream.Read(buf, 0, this.length - counter); } TimeSpan duration = DateTime.Now - start; Assert.GreaterOrEqual(duration.TotalMilliseconds, 1000); Assert.AreEqual(1, duration.TotalSeconds); } counter = 0; using (MemoryStream memstream = new MemoryStream(this.buffer)) using (BandwidthLimitedStream stream = new BandwidthLimitedStream(memstream)) { DateTime start = DateTime.Now; while (counter < this.length) { counter += stream.Read(buf, 0, this.length - counter); } TimeSpan duration = DateTime.Now - start; Assert.GreaterOrEqual(duration.TotalMilliseconds, 1000); Assert.AreEqual(1, duration.TotalSeconds); } }
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)); } }