Exemplo n.º 1
0
        public void ConfigureLimitsTest()
        {
            long limit = this.length;

            using (Stream memory = new MemoryStream(this.buffer))
                using (BandwidthLimitedStream limited = new BandwidthLimitedStream(memory)) {
                    Assert.Less(limited.ReadLimit, 0);
                    Assert.Less(limited.WriteLimit, 0);
                    limited.ReadLimit = limit;
                    Assert.AreEqual(limit, limited.ReadLimit);
                    Assert.Less(limited.WriteLimit, 0);
                    limited.WriteLimit = limit;
                    Assert.AreEqual(limit, limited.ReadLimit);
                    Assert.AreEqual(limit, limited.WriteLimit);
                    limited.DisableLimits();
                    Assert.Less(limited.ReadLimit, 0);
                    Assert.Less(limited.WriteLimit, 0);
                    limited.ReadLimit  = limit;
                    limited.WriteLimit = limit;
                    Assert.AreEqual(limit, limited.ReadLimit);
                    Assert.AreEqual(limit, limited.WriteLimit);
                    limited.DisableReadLimit();
                    Assert.Less(limited.ReadLimit, 0);
                    Assert.AreEqual(limit, limited.WriteLimit);
                    limited.DisableWriteLimit();
                    Assert.Less(limited.ReadLimit, 0);
                    Assert.Less(limited.WriteLimit, 0);
                }
        }
Exemplo n.º 2
0
 public void SetAndGetReadAndWriteLimits([Values(true, false)] bool limitRead, [Values(true, false)] bool limitWrite)
 {
     using (var memory = new MemoryStream(this.buffer))
         using (var underTest = new BandwidthLimitedStream(memory)) {
             Assert.That(underTest.ReadLimit, Is.Null);
             Assert.That(underTest.WriteLimit, Is.Null);
             underTest.ReadLimit = limitRead ? this.limit : (long?)null;
             Assert.That(underTest.ReadLimit, Is.EqualTo(limitRead ? this.limit : (long?)null));
             Assert.That(underTest.WriteLimit, Is.Null);
             underTest.WriteLimit = limitWrite ? this.limit : (long?)null;
             Assert.That(underTest.ReadLimit, Is.EqualTo(limitRead ? this.limit : (long?)null));
             Assert.That(underTest.WriteLimit, Is.EqualTo(limitWrite ? this.limit : (long?)null));
             underTest.DisableReadLimit();
             Assert.That(underTest.ReadLimit, Is.Null);
             Assert.That(underTest.WriteLimit, Is.EqualTo(limitWrite ? this.limit : (long?)null));
             underTest.DisableWriteLimit();
             Assert.That(underTest.ReadLimit, Is.Null);
             Assert.That(underTest.WriteLimit, Is.Null);
         }
 }