public void AbortWriteIfAbortIsCalled() { using (var inputStream = new MemoryStream(new byte[1024 * 1024 * 10])) using (var stream = new Mock <MemoryStream>() { CallBase = true }.Object) using (var underTest = new AbortableStream(stream)) { underTest.Abort(); Assert.Throws <AbortException>(() => inputStream.CopyTo(underTest)); Mock.Get(stream).Verify(s => s.WriteByte(It.IsAny <byte>()), Times.Never()); Mock.Get(stream).Verify(s => s.Write(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Never()); } }
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()); } }
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); }