예제 #1
0
        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>());
        }
예제 #2
0
        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>());
        }
예제 #3
0
        public void Flush_ShouldNotThrowExceptionWhenStreamDisposed()
        {
            // Arrange
            var bytes = GetRandomBytes();
            var sharedMemoryStream = new SharedMemoryStream(bytes);

            sharedMemoryStream.Dispose();

            // Act
            // Assert
            Assert.That(() => sharedMemoryStream.Flush(), Throws.Nothing);
        }
예제 #4
0
        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>());
        }
예제 #5
0
        public void Dispose()
        {
            lock (_sync)
            {
                if (_stage != null)
                {
                    _stage.Dispose();
                }

                if (_stageStorage != null)
                {
                    _stageStorage.Dispose();
                }
            }
        }
예제 #6
0
        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);
        }
예제 #7
0
        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));
        }