public void Read_ShouldThrowExceptionWhenStreamDisposed() { // Arrange var bytes = GetRandomBytes(); var sharedMemoryStream = new SharedMemoryStream(bytes); sharedMemoryStream.Dispose(); // Act // Assert Assert.That(() => sharedMemoryStream.Read(new byte[100], 0, 100), Throws.TypeOf <ObjectDisposedException>()); }
public void Seek_ShouldThrowExceptionWhenStreamDisposed() { // Arrange var bytes = GetRandomBytes(); var sharedMemoryStream = new SharedMemoryStream(bytes); sharedMemoryStream.Dispose(); // Act // Assert Assert.That(() => sharedMemoryStream.Seek(123, SeekOrigin.Begin), Throws.TypeOf <ObjectDisposedException>()); }
public void Flush_ShouldNotThrowExceptionWhenStreamDisposed() { // Arrange var bytes = GetRandomBytes(); var sharedMemoryStream = new SharedMemoryStream(bytes); sharedMemoryStream.Dispose(); // Act // Assert Assert.That(() => sharedMemoryStream.Flush(), Throws.Nothing); }
public void Position_Set_ShouldThrowExceptionWhenStreamDisposed() { // Arrange var bytes = GetRandomBytes(); var sharedMemoryStream = new SharedMemoryStream(bytes); sharedMemoryStream.Dispose(); // Act // Assert Assert.That(() => sharedMemoryStream.Position = 0, Throws.TypeOf <ObjectDisposedException>()); }
public void Dispose() { lock (_sync) { if (_stage != null) { _stage.Dispose(); } if (_stageStorage != null) { _stageStorage.Dispose(); } } }
public void CanSeek_ShouldBeTrueIfNotDisposedAndFalseIfDisposed() { // Arrange var bytes = GetRandomBytes(); var sharedMemoryStream = new SharedMemoryStream(bytes); // Assume Assume.That(sharedMemoryStream.CanSeek, Is.True); // Act sharedMemoryStream.Dispose(); // Assert Assert.That(sharedMemoryStream.CanSeek, Is.False); }
public void Dispose_ShouldNotDisposeSharedResourcesUntilAllSharedInstancesAreDisposed() { // Arrange var bytes = GetRandomBytes(); var sharedMemoryStream1 = new SharedMemoryStream(bytes); var sharedMemoryStream2 = sharedMemoryStream1.MakeShared(); // Assume Assume.That(sharedMemoryStream1.Position, Is.EqualTo(0)); Assume.That(sharedMemoryStream2.Position, Is.EqualTo(0)); // Act sharedMemoryStream1.Dispose(); // Assert Assert.That(() => sharedMemoryStream1.Seek(10, SeekOrigin.Current), Throws.TypeOf <ObjectDisposedException>()); var seek = sharedMemoryStream2.Seek(100, SeekOrigin.Current); Assert.That(seek, Is.EqualTo(100)); Assert.That(sharedMemoryStream2.Position, Is.EqualTo(100)); }