Exemplo n.º 1
0
 public void AbortReadIfAbortIsCalled() {
     byte[] content = new byte[1024];
     using (var stream = new Mock<MemoryStream>(content) { CallBase = true }.Object)
     using (var underTest = new AbortableStream(stream)) {
         underTest.Abort();
         Assert.Throws<AbortException>(() => underTest.ReadByte());
         Mock.Get(stream).Verify(s => s.ReadByte(), Times.Never());
         Mock.Get(stream).Verify(s => s.Read(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Never());
     }
 }
Exemplo n.º 2
0
        public void NotificationSendOutOnAbortion() {
            bool notified = false;
            byte[] content = new byte[1024];
            using (var stream = new Mock<MemoryStream>(content) { CallBase = true }.Object)
            using (var underTest = new AbortableStream(stream)) {
                underTest.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => {
                    Assert.That(e.PropertyName, Is.EqualTo(Utils.NameOf((AbortableStream s) => s.Exception)));
                    Assert.That(underTest.Exception, Is.Not.Null);
                    notified = true;
                };
                underTest.Abort();
                Assert.Throws<AbortException>(() => underTest.ReadByte());
            }

            Assert.That(notified, Is.True);
        }