diff --git a/Tests/FluentAssertions.Specs/Streams/BufferedStreamAssertionSpecs.cs b/Tests/FluentAssertions.Specs/Streams/BufferedStreamAssertionSpecs.cs index ae314b98be..14415d13bf 100644 --- a/Tests/FluentAssertions.Specs/Streams/BufferedStreamAssertionSpecs.cs +++ b/Tests/FluentAssertions.Specs/Streams/BufferedStreamAssertionSpecs.cs @@ -11,103 +11,105 @@ namespace FluentAssertions.Specs.Streams public class BufferedStreamAssertionSpecs { #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1 - #region HaveBufferSize / NotHaveBufferSize - - [Fact] - public void When_a_stream_has_the_expected_buffer_size_it_should_succeed() + public class HaveBufferSize { - // Arrange - using var stream = new BufferedStream(new MemoryStream(), 10); + [Fact] + public void When_a_stream_has_the_expected_buffer_size_it_should_succeed() + { + // Arrange + using var stream = new BufferedStream(new MemoryStream(), 10); - // Act - Action act = () => - stream.Should().HaveBufferSize(10); + // Act + Action act = () => + stream.Should().HaveBufferSize(10); - // Assert - act.Should().NotThrow(); - } - - [Fact] - public void When_a_stream_has_an_unexpected_buffer_size_should_fail() - { - // Arrange - using var stream = new BufferedStream(new MemoryStream(), 1); + // Assert + act.Should().NotThrow(); + } - // Act - Action act = () => - stream.Should().HaveBufferSize(10, "we want to test the failure {0}", "message"); + [Fact] + public void When_a_stream_has_an_unexpected_buffer_size_should_fail() + { + // Arrange + using var stream = new BufferedStream(new MemoryStream(), 1); - // Assert - act.Should().Throw() - .WithMessage("Expected the buffer size of stream to be 10 *failure message*, but it was 1."); - } + // Act + Action act = () => + stream.Should().HaveBufferSize(10, "we want to test the failure {0}", "message"); - [Fact] - public void When_null_have_buffer_size_should_fail() - { - // Arrange - BufferedStream stream = null; + // Assert + act.Should().Throw() + .WithMessage("Expected the buffer size of stream to be 10 *failure message*, but it was 1."); + } - // Act - Action act = () => + [Fact] + public void When_null_have_buffer_size_should_fail() { - using var _ = new AssertionScope(); - stream.Should().HaveBufferSize(10, "we want to test the failure {0}", "message"); - }; - - // Assert - act.Should().Throw() - .WithMessage("Expected the buffer size of stream to be 10 *failure message*, but found a reference."); + // Arrange + BufferedStream stream = null; + + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().HaveBufferSize(10, "we want to test the failure {0}", "message"); + }; + + // Assert + act.Should().Throw() + .WithMessage("Expected the buffer size of stream to be 10 *failure message*, but found a reference."); + } } - [Fact] - public void When_a_stream_does_not_have_an_unexpected_buffer_size_it_should_succeed() + public class NotHaveBufferSize { - // Arrange - using var stream = new BufferedStream(new MemoryStream(), 1); + [Fact] + public void When_a_stream_does_not_have_an_unexpected_buffer_size_it_should_succeed() + { + // Arrange + using var stream = new BufferedStream(new MemoryStream(), 1); - // Act - Action act = () => - stream.Should().NotHaveBufferSize(10); + // Act + Action act = () => + stream.Should().NotHaveBufferSize(10); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().NotThrow(); + } - [Fact] - public void When_a_stream_does_have_the_unexpected_buffer_size_it_should_fail() - { - // Arrange - using var stream = new BufferedStream(new MemoryStream(), 10); + [Fact] + public void When_a_stream_does_have_the_unexpected_buffer_size_it_should_fail() + { + // Arrange + using var stream = new BufferedStream(new MemoryStream(), 10); - // Act - Action act = () => - stream.Should().NotHaveBufferSize(10, "we want to test the failure {0}", "message"); + // Act + Action act = () => + stream.Should().NotHaveBufferSize(10, "we want to test the failure {0}", "message"); - // Assert - act.Should().Throw() - .WithMessage("Expected the buffer size of stream not to be 10 *failure message*, but it was."); - } + // Assert + act.Should().Throw() + .WithMessage("Expected the buffer size of stream not to be 10 *failure message*, but it was."); + } - [Fact] - public void When_null_not_have_buffer_size_should_fail() - { - // Arrange - BufferedStream stream = null; - - // Act - Action act = () => + [Fact] + public void When_null_not_have_buffer_size_should_fail() { - using var _ = new AssertionScope(); - stream.Should().NotHaveBufferSize(10, "we want to test the failure {0}", "message"); - }; - - // Assert - act.Should().Throw() - .WithMessage("Expected the buffer size of stream not to be 10 *failure message*, but found a reference."); + // Arrange + BufferedStream stream = null; + + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().NotHaveBufferSize(10, "we want to test the failure {0}", "message"); + }; + + // Assert + act.Should().Throw() + .WithMessage("Expected the buffer size of stream not to be 10 *failure message*, but found a reference."); + } } - - #endregion #endif } } diff --git a/Tests/FluentAssertions.Specs/Streams/StreamAssertionSpecs.cs b/Tests/FluentAssertions.Specs/Streams/StreamAssertionSpecs.cs index 65f2d17941..83734545a0 100644 --- a/Tests/FluentAssertions.Specs/Streams/StreamAssertionSpecs.cs +++ b/Tests/FluentAssertions.Specs/Streams/StreamAssertionSpecs.cs @@ -9,833 +9,847 @@ namespace FluentAssertions.Specs.Streams { public class StreamAssertionSpecs { - #region BeWritable / NotBeWritable - - [Fact] - public void When_having_a_writable_stream_be_writable_should_succeed() + public class BeWritable { - // Arrange - using var stream = new TestStream { Writable = true }; + [Fact] + public void When_having_a_writable_stream_be_writable_should_succeed() + { + // Arrange + using var stream = new TestStream { Writable = true }; - // Act - Action act = () => - stream.Should().BeWritable(); + // Act + Action act = () => + stream.Should().BeWritable(); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().NotThrow(); + } - [Fact] - public void When_having_a_non_writable_stream_be_writable_should_fail() - { - // Arrange - using var stream = new TestStream { Writable = false }; + [Fact] + public void When_having_a_non_writable_stream_be_writable_should_fail() + { + // Arrange + using var stream = new TestStream { Writable = false }; - // Act - Action act = () => - stream.Should().BeWritable("we want to test the failure {0}", "message"); + // Act + Action act = () => + stream.Should().BeWritable("we want to test the failure {0}", "message"); - // Assert - act.Should().Throw() - .WithMessage("Expected stream to be writable *failure message*, but it was not."); - } + // Assert + act.Should().Throw() + .WithMessage("Expected stream to be writable *failure message*, but it was not."); + } - [Fact] - public void When_null_be_writable_should_fail() - { - // Arrange - TestStream stream = null; - - // Act - Action act = () => + [Fact] + public void When_null_be_writable_should_fail() { - using var _ = new AssertionScope(); - stream.Should().BeWritable("we want to test the failure {0}", "message"); - }; + // Arrange + TestStream stream = null; - // Assert - act.Should().Throw() - .WithMessage("Expected stream to be writable *failure message*, but found a reference."); - } - - [Fact] - public void When_having_a_non_writable_stream_be_not_writable_should_succeed() - { - // Arrange - using var stream = new TestStream { Writable = false }; + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().BeWritable("we want to test the failure {0}", "message"); + }; - // Act - Action act = () => - stream.Should().NotBeWritable(); - - // Assert - act.Should().NotThrow(); + // Assert + act.Should().Throw() + .WithMessage("Expected stream to be writable *failure message*, but found a reference."); + } } - [Fact] - public void When_having_a_writable_stream_be_not_writable_should_fail() + public class NotBeWritable { - // Arrange - using var stream = new TestStream { Writable = true }; + [Fact] + public void When_having_a_non_writable_stream_be_not_writable_should_succeed() + { + // Arrange + using var stream = new TestStream { Writable = false }; - // Act - Action act = () => - stream.Should().NotBeWritable("we want to test the failure {0}", "message"); + // Act + Action act = () => + stream.Should().NotBeWritable(); - // Assert - act.Should().Throw() - .WithMessage("Expected stream not to be writable *failure message*, but it was."); - } - - [Fact] - public void When_null_not_be_writable_should_fail() - { - // Arrange - TestStream stream = null; + // Assert + act.Should().NotThrow(); + } - // Act - Action act = () => + [Fact] + public void When_having_a_writable_stream_be_not_writable_should_fail() { - using var _ = new AssertionScope(); - stream.Should().NotBeWritable("we want to test the failure {0}", "message"); - }; + // Arrange + using var stream = new TestStream { Writable = true }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream not to be writable *failure message*, but found a reference."); - } - - #endregion + // Act + Action act = () => + stream.Should().NotBeWritable("we want to test the failure {0}", "message"); - #region BeSeekable / NotBeSeekable + // Assert + act.Should().Throw() + .WithMessage("Expected stream not to be writable *failure message*, but it was."); + } - [Fact] - public void When_having_a_seekable_stream_be_seekable_should_succeed() - { - // Arrange - using var stream = new TestStream { Seekable = true }; + [Fact] + public void When_null_not_be_writable_should_fail() + { + // Arrange + TestStream stream = null; - // Act - Action act = () => - stream.Should().BeSeekable(); + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().NotBeWritable("we want to test the failure {0}", "message"); + }; - // Assert - act.Should().NotThrow(); + // Assert + act.Should().Throw() + .WithMessage("Expected stream not to be writable *failure message*, but found a reference."); + } } - [Fact] - public void When_having_a_non_seekable_stream_be_seekable_should_fail() + public class BeSeekable { - // Arrange - using var stream = new TestStream { Seekable = false }; - - // Act - Action act = () => - stream.Should().BeSeekable("we want to test the failure {0}", "message"); + [Fact] + public void When_having_a_seekable_stream_be_seekable_should_succeed() + { + // Arrange + using var stream = new TestStream { Seekable = true }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream to be seekable *failure message*, but it was not."); - } + // Act + Action act = () => + stream.Should().BeSeekable(); - [Fact] - public void When_null_be_seekable_should_fail() - { - // Arrange - TestStream stream = null; + // Assert + act.Should().NotThrow(); + } - // Act - Action act = () => + [Fact] + public void When_having_a_non_seekable_stream_be_seekable_should_fail() { - using var _ = new AssertionScope(); - stream.Should().BeSeekable("we want to test the failure {0}", "message"); - }; + // Arrange + using var stream = new TestStream { Seekable = false }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream to be seekable *failure message*, but found a reference."); - } - - [Fact] - public void When_having_a_non_seekable_stream_be_not_seekable_should_succeed() - { - // Arrange - using var stream = new TestStream { Seekable = false }; + // Act + Action act = () => + stream.Should().BeSeekable("we want to test the failure {0}", "message"); - // Act - Action act = () => - stream.Should().NotBeSeekable(); + // Assert + act.Should().Throw() + .WithMessage("Expected stream to be seekable *failure message*, but it was not."); + } - // Assert - act.Should().NotThrow(); - } - - [Fact] - public void When_having_a_seekable_stream_be_not_seekable_should_fail() - { - // Arrange - using var stream = new TestStream { Seekable = true }; + [Fact] + public void When_null_be_seekable_should_fail() + { + // Arrange + TestStream stream = null; - // Act - Action act = () => - stream.Should().NotBeSeekable("we want to test the failure {0}", "message"); + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().BeSeekable("we want to test the failure {0}", "message"); + }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream not to be seekable *failure message*, but it was."); + // Assert + act.Should().Throw() + .WithMessage("Expected stream to be seekable *failure message*, but found a reference."); + } } - [Fact] - public void When_null_not_be_seekable_should_fail() + public class NotBeSeekable { - // Arrange - TestStream stream = null; - - // Act - Action act = () => + [Fact] + public void When_having_a_non_seekable_stream_be_not_seekable_should_succeed() { - using var _ = new AssertionScope(); - stream.Should().NotBeSeekable("we want to test the failure {0}", "message"); - }; + // Arrange + using var stream = new TestStream { Seekable = false }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream not to be seekable *failure message*, but found a reference."); - } - - #endregion + // Act + Action act = () => + stream.Should().NotBeSeekable(); - #region BeReadable / NotBeReadable + // Assert + act.Should().NotThrow(); + } - [Fact] - public void When_having_a_readable_stream_be_readable_should_succeed() - { - // Arrange - using var stream = new TestStream { Readable = true }; + [Fact] + public void When_having_a_seekable_stream_be_not_seekable_should_fail() + { + // Arrange + using var stream = new TestStream { Seekable = true }; - // Act - Action act = () => - stream.Should().BeReadable(); + // Act + Action act = () => + stream.Should().NotBeSeekable("we want to test the failure {0}", "message"); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().Throw() + .WithMessage("Expected stream not to be seekable *failure message*, but it was."); + } - [Fact] - public void When_having_a_non_readable_stream_be_readable_should_fail() - { - // Arrange - using var stream = new TestStream { Readable = false }; + [Fact] + public void When_null_not_be_seekable_should_fail() + { + // Arrange + TestStream stream = null; - // Act - Action act = () => - stream.Should().BeReadable("we want to test the failure {0}", "message"); + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().NotBeSeekable("we want to test the failure {0}", "message"); + }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream to be readable *failure message*, but it was not."); + // Assert + act.Should().Throw() + .WithMessage("Expected stream not to be seekable *failure message*, but found a reference."); + } } - [Fact] - public void When_null_be_readable_should_fail() + public class BeReadable { - // Arrange - TestStream stream = null; - - // Act - Action act = () => + [Fact] + public void When_having_a_readable_stream_be_readable_should_succeed() { - using var _ = new AssertionScope(); - stream.Should().BeReadable("we want to test the failure {0}", "message"); - }; + // Arrange + using var stream = new TestStream { Readable = true }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream to be readable *failure message*, but found a reference."); - } + // Act + Action act = () => + stream.Should().BeReadable(); - [Fact] - public void When_having_a_non_readable_stream_be_not_readable_should_succeed() - { - // Arrange - using var stream = new TestStream { Readable = false }; + // Assert + act.Should().NotThrow(); + } - // Act - Action act = () => - stream.Should().NotBeReadable(); + [Fact] + public void When_having_a_non_readable_stream_be_readable_should_fail() + { + // Arrange + using var stream = new TestStream { Readable = false }; - // Assert - act.Should().NotThrow(); - } + // Act + Action act = () => + stream.Should().BeReadable("we want to test the failure {0}", "message"); - [Fact] - public void When_having_a_readable_stream_be_not_readable_should_fail() - { - // Arrange - using var stream = new TestStream { Readable = true }; + // Assert + act.Should().Throw() + .WithMessage("Expected stream to be readable *failure message*, but it was not."); + } - // Act - Action act = () => - stream.Should().NotBeReadable("we want to test the failure {0}", "message"); + [Fact] + public void When_null_be_readable_should_fail() + { + // Arrange + TestStream stream = null; + + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().BeReadable("we want to test the failure {0}", "message"); + }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream not to be readable *failure message*, but it was."); + // Assert + act.Should().Throw() + .WithMessage("Expected stream to be readable *failure message*, but found a reference."); + } } - [Fact] - public void When_null_not_be_readable_should_fail() + public class NotBeReadable { - // Arrange - TestStream stream = null; - - // Act - Action act = () => + [Fact] + public void When_having_a_non_readable_stream_be_not_readable_should_succeed() { - using var _ = new AssertionScope(); - stream.Should().NotBeReadable("we want to test the failure {0}", "message"); - }; + // Arrange + using var stream = new TestStream { Readable = false }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream not to be readable *failure message*, but found a reference."); - } - - #endregion + // Act + Action act = () => + stream.Should().NotBeReadable(); - #region HavePosition / NotHavePosition + // Assert + act.Should().NotThrow(); + } - public static IEnumerable GetPositionExceptions() - { - // https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.position#exceptions - yield return new object[] { new IOException("GetPositionExceptionMessage") }; - yield return new object[] { new NotSupportedException("GetPositionExceptionMessage") }; - yield return new object[] { new ObjectDisposedException("GetPositionExceptionMessage") }; - } - - [Fact] - public void When_a_stream_has_the_expected_position_it_should_succeed() - { - // Arrange - using var stream = new TestStream { Seekable = true, Position = 10 }; + [Fact] + public void When_having_a_readable_stream_be_not_readable_should_fail() + { + // Arrange + using var stream = new TestStream { Readable = true }; - // Act - Action act = () => - stream.Should().HavePosition(10); + // Act + Action act = () => + stream.Should().NotBeReadable("we want to test the failure {0}", "message"); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().Throw() + .WithMessage("Expected stream not to be readable *failure message*, but it was."); + } - [Fact] - public void When_a_stream_has_the_unexpected_position_it_should_fail() - { - // Arrange - using var stream = new TestStream { Seekable = true, Position = 1 }; + [Fact] + public void When_null_not_be_readable_should_fail() + { + // Arrange + TestStream stream = null; - // Act - Action act = () => - stream.Should().HavePosition(10, "we want to test the failure {0}", "message"); + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().NotBeReadable("we want to test the failure {0}", "message"); + }; - // Assert - act.Should().Throw() - .WithMessage("Expected the position of stream to be 10* *failure message*, but it was 1*."); + // Assert + act.Should().Throw() + .WithMessage("Expected stream not to be readable *failure message*, but found a reference."); + } } - [Theory] - [MemberData(nameof(GetPositionExceptions))] - public void When_a_throwing_stream_should_have_a_position_it_should_fail(Exception exception) + public class HavePosition { - // Arrange - using var stream = new ExceptingStream(exception); + [Fact] + public void When_a_stream_has_the_expected_position_it_should_succeed() + { + // Arrange + using var stream = new TestStream { Seekable = true, Position = 10 }; - // Act - Action act = () => - stream.Should().HavePosition(10, "we want to test the failure {0}", "message"); + // Act + Action act = () => + stream.Should().HavePosition(10); - // Assert - act.Should().Throw() - .WithMessage("Expected the position of stream to be 10* *failure message*, " + - "but it failed with*GetPositionExceptionMessage*"); - } + // Assert + act.Should().NotThrow(); + } - [Fact] - public void When_null_have_position_should_fail() - { - // Arrange - TestStream stream = null; - - // Act - Action act = () => + [Fact] + public void When_a_stream_has_the_unexpected_position_it_should_fail() { - using var _ = new AssertionScope(); - stream.Should().HavePosition(10, "we want to test the failure {0}", "message"); - }; + // Arrange + using var stream = new TestStream { Seekable = true, Position = 1 }; - // Assert - act.Should().Throw() - .WithMessage("Expected the position of stream to be 10* *failure message*, but found a reference."); - } + // Act + Action act = () => + stream.Should().HavePosition(10, "we want to test the failure {0}", "message"); - [Fact] - public void When_a_stream_does_not_have_an_unexpected_position_it_should_succeed() - { - // Arrange - using var stream = new TestStream { Seekable = true, Position = 1 }; + // Assert + act.Should().Throw() + .WithMessage("Expected the position of stream to be 10* *failure message*, but it was 1*."); + } - // Act - Action act = () => - stream.Should().NotHavePosition(10); + [Fact] + public void When_null_have_position_should_fail() + { + // Arrange + TestStream stream = null; + + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().HavePosition(10, "we want to test the failure {0}", "message"); + }; + + // Assert + act.Should().Throw() + .WithMessage("Expected the position of stream to be 10* *failure message*, but found a reference."); + } + + [Theory] + [MemberData(nameof(StreamAssertionSpecs.GetPositionExceptions), MemberType = typeof(StreamAssertionSpecs))] + public void When_a_throwing_stream_should_have_a_position_it_should_fail(Exception exception) + { + // Arrange + using var stream = new ExceptingStream(exception); - // Assert - act.Should().NotThrow(); + // Act + Action act = () => + stream.Should().HavePosition(10, "we want to test the failure {0}", "message"); + + // Assert + act.Should().Throw() + .WithMessage("Expected the position of stream to be 10* *failure message*, " + + "but it failed with*GetPositionExceptionMessage*"); + } } - [Fact] - public void When_a_stream_does_have_the_unexpected_position_it_should_fail() + public class NotHavePosition { - // Arrange - using var stream = new TestStream { Seekable = true, Position = 10 }; - - // Act - Action act = () => - stream.Should().NotHavePosition(10, "we want to test the failure {0}", "message"); + [Fact] + public void When_a_stream_does_not_have_an_unexpected_position_it_should_succeed() + { + // Arrange + using var stream = new TestStream { Seekable = true, Position = 1 }; - // Assert - act.Should().Throw() - .WithMessage("Expected the position of stream not to be 10* *failure message*, but it was."); - } + // Act + Action act = () => + stream.Should().NotHavePosition(10); - [Theory] - [MemberData(nameof(GetPositionExceptions))] - public void When_a_throwing_stream_should_not_have_a_position_it_should_fail(Exception exception) - { - // Arrange - using var stream = new ExceptingStream(exception); + // Assert + act.Should().NotThrow(); + } - // Act - Action act = () => - stream.Should().NotHavePosition(10, "we want to test the failure {0}", "message"); + [Fact] + public void When_a_stream_does_have_the_unexpected_position_it_should_fail() + { + // Arrange + using var stream = new TestStream { Seekable = true, Position = 10 }; - // Assert - act.Should().Throw() - .WithMessage("Expected the position of stream not to be 10* *failure message*, " + - "but it failed with*GetPositionExceptionMessage*"); - } + // Act + Action act = () => + stream.Should().NotHavePosition(10, "we want to test the failure {0}", "message"); - [Fact] - public void When_null_not_have_position_should_fail() - { - // Arrange - TestStream stream = null; + // Assert + act.Should().Throw() + .WithMessage("Expected the position of stream not to be 10* *failure message*, but it was."); + } - // Act - Action act = () => + [Fact] + public void When_null_not_have_position_should_fail() { - using var _ = new AssertionScope(); - stream.Should().NotHavePosition(10, "we want to test the failure {0}", "message"); - }; - - // Assert - act.Should().Throw() - .WithMessage("Expected the position of stream not to be 10* *failure message*, but found a reference."); - } + // Arrange + TestStream stream = null; + + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().NotHavePosition(10, "we want to test the failure {0}", "message"); + }; + + // Assert + act.Should().Throw() + .WithMessage("Expected the position of stream not to be 10* *failure message*, but found a reference."); + } + + [Theory] + [MemberData(nameof(StreamAssertionSpecs.GetPositionExceptions), MemberType = typeof(StreamAssertionSpecs))] + public void When_a_throwing_stream_should_not_have_a_position_it_should_fail(Exception exception) + { + // Arrange + using var stream = new ExceptingStream(exception); - #endregion + // Act + Action act = () => + stream.Should().NotHavePosition(10, "we want to test the failure {0}", "message"); - #region HaveLength / NotHaveLength + // Assert + act.Should().Throw() + .WithMessage("Expected the position of stream not to be 10* *failure message*, " + + "but it failed with*GetPositionExceptionMessage*"); + } + } - public static IEnumerable GetLengthExceptions() + public static IEnumerable GetPositionExceptions() { - // https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.length#exceptions - yield return new object[] { new IOException("GetLengthExceptionMessage") }; - yield return new object[] { new NotSupportedException("GetLengthExceptionMessage") }; - yield return new object[] { new ObjectDisposedException("GetLengthExceptionMessage") }; + // https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.position#exceptions + yield return new object[] { new IOException("GetPositionExceptionMessage") }; + yield return new object[] { new NotSupportedException("GetPositionExceptionMessage") }; + yield return new object[] { new ObjectDisposedException("GetPositionExceptionMessage") }; } - [Fact] - public void When_a_stream_has_the_expected_length_it_should_succeed() + public class HaveLength { - // Arrange - using var stream = new TestStream { Seekable = true, WithLength = 10 }; + [Fact] + public void When_a_stream_has_the_expected_length_it_should_succeed() + { + // Arrange + using var stream = new TestStream { Seekable = true, WithLength = 10 }; - // Act - Action act = () => - stream.Should().HaveLength(10); + // Act + Action act = () => + stream.Should().HaveLength(10); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().NotThrow(); + } - [Fact] - public void When_a_stream_has_an_unexpected_length_it_should_fail() - { - // Arrange - using var stream = new TestStream { Seekable = true, WithLength = 1 }; + [Fact] + public void When_a_stream_has_an_unexpected_length_it_should_fail() + { + // Arrange + using var stream = new TestStream { Seekable = true, WithLength = 1 }; - // Act - Action act = () => - stream.Should().HaveLength(10, "we want to test the failure {0}", "message"); + // Act + Action act = () => + stream.Should().HaveLength(10, "we want to test the failure {0}", "message"); - // Assert - act.Should().Throw() - .WithMessage("Expected the length of stream to be 10* *failure message*, but it was 1*."); - } + // Assert + act.Should().Throw() + .WithMessage("Expected the length of stream to be 10* *failure message*, but it was 1*."); + } - [Theory] - [MemberData(nameof(GetLengthExceptions))] - public void When_a_throwing_stream_should_have_a_length_it_should_fail(Exception exception) - { - // Arrange - using var stream = new ExceptingStream(exception); + [Fact] + public void When_null_have_length_should_fail() + { + // Arrange + TestStream stream = null; + + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().HaveLength(10, "we want to test the failure {0}", "message"); + }; + + // Assert + act.Should().Throw() + .WithMessage("Expected the length of stream to be 10* *failure message*, but found a reference."); + } + + [Theory] + [MemberData(nameof(StreamAssertionSpecs.GetLengthExceptions), MemberType = typeof(StreamAssertionSpecs))] + public void When_a_throwing_stream_should_have_a_length_it_should_fail(Exception exception) + { + // Arrange + using var stream = new ExceptingStream(exception); - // Act - Action act = () => - stream.Should().HaveLength(10, "we want to test the failure {0}", "message"); + // Act + Action act = () => + stream.Should().HaveLength(10, "we want to test the failure {0}", "message"); - // Assert - act.Should().Throw() - .WithMessage("Expected the length of stream to be 10* *failure message*, " + - "but it failed with*GetLengthExceptionMessage*"); + // Assert + act.Should().Throw() + .WithMessage("Expected the length of stream to be 10* *failure message*, " + + "but it failed with*GetLengthExceptionMessage*"); + } } - [Fact] - public void When_null_have_length_should_fail() + public class NotHaveLength { - // Arrange - TestStream stream = null; - - // Act - Action act = () => + [Fact] + public void When_a_stream_does_not_have_an_unexpected_length_it_should_succeed() { - using var _ = new AssertionScope(); - stream.Should().HaveLength(10, "we want to test the failure {0}", "message"); - }; + // Arrange + using var stream = new TestStream { Seekable = true, WithLength = 1 }; - // Assert - act.Should().Throw() - .WithMessage("Expected the length of stream to be 10* *failure message*, but found a reference."); - } + // Act + Action act = () => + stream.Should().NotHaveLength(10); - [Fact] - public void When_a_stream_does_not_have_an_unexpected_length_it_should_succeed() - { - // Arrange - using var stream = new TestStream { Seekable = true, WithLength = 1 }; + // Assert + act.Should().NotThrow(); + } - // Act - Action act = () => - stream.Should().NotHaveLength(10); + [Fact] + public void When_a_stream_does_have_the_unexpected_length_it_should_fail() + { + // Arrange + using var stream = new TestStream { Seekable = true, WithLength = 10 }; - // Assert - act.Should().NotThrow(); - } + // Act + Action act = () => + stream.Should().NotHaveLength(10, "we want to test the failure {0}", "message"); - [Fact] - public void When_a_stream_does_have_the_unexpected_length_it_should_fail() - { - // Arrange - using var stream = new TestStream { Seekable = true, WithLength = 10 }; + // Assert + act.Should().Throw() + .WithMessage("Expected the length of stream not to be 10* *failure message*, but it was."); + } + + [Fact] + public void When_null_not_have_length_should_fail() + { + // Arrange + TestStream stream = null; + + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().NotHaveLength(10, "we want to test the failure {0}", "message"); + }; + + // Assert + act.Should().Throw() + .WithMessage("Expected the length of stream not to be 10* *failure message*, but found a reference."); + } + + [Theory] + [MemberData(nameof(StreamAssertionSpecs.GetLengthExceptions), MemberType = typeof(StreamAssertionSpecs))] + public void When_a_throwing_stream_should_not_have_a_length_it_should_fail(Exception exception) + { + // Arrange + using var stream = new ExceptingStream(exception); - // Act - Action act = () => - stream.Should().NotHaveLength(10, "we want to test the failure {0}", "message"); + // Act + Action act = () => + stream.Should().NotHaveLength(10, "we want to test the failure {0}", "message"); - // Assert - act.Should().Throw() - .WithMessage("Expected the length of stream not to be 10* *failure message*, but it was."); + // Assert + act.Should().Throw() + .WithMessage("Expected the length of stream not to be 10* *failure message*, " + + "but it failed with*GetLengthExceptionMessage*"); + } } - [Theory] - [MemberData(nameof(GetLengthExceptions))] - public void When_a_throwing_stream_should_not_have_a_length_it_should_fail(Exception exception) + public static IEnumerable GetLengthExceptions() { - // Arrange - using var stream = new ExceptingStream(exception); - - // Act - Action act = () => - stream.Should().NotHaveLength(10, "we want to test the failure {0}", "message"); - - // Assert - act.Should().Throw() - .WithMessage("Expected the length of stream not to be 10* *failure message*, " + - "but it failed with*GetLengthExceptionMessage*"); + // https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.length#exceptions + yield return new object[] { new IOException("GetLengthExceptionMessage") }; + yield return new object[] { new NotSupportedException("GetLengthExceptionMessage") }; + yield return new object[] { new ObjectDisposedException("GetLengthExceptionMessage") }; } - [Fact] - public void When_null_not_have_length_should_fail() + public class BeReadOnly { - // Arrange - TestStream stream = null; - - // Act - Action act = () => + [Fact] + public void When_having_a_readonly_stream_be_read_only_should_succeed() { - using var _ = new AssertionScope(); - stream.Should().NotHaveLength(10, "we want to test the failure {0}", "message"); - }; + // Arrange + using var stream = new TestStream { Readable = true, Writable = false }; - // Assert - act.Should().Throw() - .WithMessage("Expected the length of stream not to be 10* *failure message*, but found a reference."); - } + // Act + Action act = () => + stream.Should().BeReadOnly(); - #endregion + // Assert + act.Should().NotThrow(); + } - #region BeReadOnly / NotBeReadOnly + [Fact] + public void When_having_a_writable_stream_be_read_only_should_fail() + { + // Arrange + using var stream = new TestStream { Readable = true, Writable = true }; - [Fact] - public void When_having_a_readonly_stream_be_read_only_should_succeed() - { - // Arrange - using var stream = new TestStream { Readable = true, Writable = false }; + // Act + Action act = () => + stream.Should().BeReadOnly("we want to test the failure {0}", "message"); - // Act - Action act = () => - stream.Should().BeReadOnly(); + // Assert + act.Should().Throw() + .WithMessage("Expected stream to be read-only *failure message*, but it was writable or not readable."); + } - // Assert - act.Should().NotThrow(); - } + [Fact] + public void When_having_a_non_readable_stream_be_read_only_should_fail() + { + // Arrange + using var stream = new TestStream { Readable = false, Writable = false }; - [Fact] - public void When_having_a_writable_stream_be_read_only_should_fail() - { - // Arrange - using var stream = new TestStream { Readable = true, Writable = true }; + // Act + Action act = () => + stream.Should().BeReadOnly("we want to test the failure {0}", "message"); - // Act - Action act = () => - stream.Should().BeReadOnly("we want to test the failure {0}", "message"); + // Assert + act.Should().Throw() + .WithMessage("Expected stream to be read-only *failure message*, but it was writable or not readable."); + } - // Assert - act.Should().Throw() - .WithMessage("Expected stream to be read-only *failure message*, but it was writable or not readable."); - } - - [Fact] - public void When_having_a_non_readable_stream_be_read_only_should_fail() - { - // Arrange - using var stream = new TestStream { Readable = false, Writable = false }; + [Fact] + public void When_null_be_read_only_should_fail() + { + // Arrange + TestStream stream = null; - // Act - Action act = () => - stream.Should().BeReadOnly("we want to test the failure {0}", "message"); + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().BeReadOnly("we want to test the failure {0}", "message"); + }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream to be read-only *failure message*, but it was writable or not readable."); + // Assert + act.Should().Throw() + .WithMessage("Expected stream to be read-only *failure message*, but found a reference."); + } } - [Fact] - public void When_null_be_read_only_should_fail() + public class NotBeReadOnly { - // Arrange - TestStream stream = null; - - // Act - Action act = () => + [Fact] + public void When_having_a_non_readable_stream_be_not_read_only_should_succeed() { - using var _ = new AssertionScope(); - stream.Should().BeReadOnly("we want to test the failure {0}", "message"); - }; + // Arrange + using var stream = new TestStream { Readable = false, Writable = false }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream to be read-only *failure message*, but found a reference."); - } + // Act + Action act = () => + stream.Should().NotBeReadOnly(); - [Fact] - public void When_having_a_non_readable_stream_be_not_read_only_should_succeed() - { - // Arrange - using var stream = new TestStream { Readable = false, Writable = false }; + // Assert + act.Should().NotThrow(); + } - // Act - Action act = () => - stream.Should().NotBeReadOnly(); + [Fact] + public void When_having_a_writable_stream_be_not_read_only_should_succeed() + { + // Arrange + using var stream = new TestStream { Readable = true, Writable = true }; - // Assert - act.Should().NotThrow(); - } + // Act + Action act = () => + stream.Should().NotBeReadOnly(); - [Fact] - public void When_having_a_writable_stream_be_not_read_only_should_succeed() - { - // Arrange - using var stream = new TestStream { Readable = true, Writable = true }; + // Assert + act.Should().NotThrow(); + } - // Act - Action act = () => - stream.Should().NotBeReadOnly(); + [Fact] + public void When_having_a_readonly_stream_be_not_read_only_should_fail() + { + // Arrange + using var stream = new TestStream { Readable = true, Writable = false }; - // Assert - act.Should().NotThrow(); - } + // Act + Action act = () => + stream.Should().NotBeReadOnly("we want to test the failure {0}", "message"); - [Fact] - public void When_having_a_readonly_stream_be_not_read_only_should_fail() - { - // Arrange - using var stream = new TestStream { Readable = true, Writable = false }; + // Assert + act.Should().Throw() + .WithMessage("Expected stream not to be read-only *failure message*, but it was."); + } + + [Fact] + public void When_null_not_be_read_only_should_fail() + { + // Arrange + TestStream stream = null; - // Act - Action act = () => - stream.Should().NotBeReadOnly("we want to test the failure {0}", "message"); + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().NotBeReadOnly("we want to test the failure {0}", "message"); + }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream not to be read-only *failure message*, but it was."); + // Assert + act.Should().Throw() + .WithMessage("Expected stream not to be read-only *failure message*, but found a reference."); + } } - [Fact] - public void When_null_not_be_read_only_should_fail() + public class BeWriteOnly { - // Arrange - TestStream stream = null; - - // Act - Action act = () => + [Fact] + public void When_having_a_writeonly_stream_be_write_only_should_succeed() { - using var _ = new AssertionScope(); - stream.Should().NotBeReadOnly("we want to test the failure {0}", "message"); - }; - - // Assert - act.Should().Throw() - .WithMessage("Expected stream not to be read-only *failure message*, but found a reference."); - } + // Arrange + using var stream = new TestStream { Readable = false, Writable = true }; - #endregion + // Act + Action act = () => + stream.Should().BeWriteOnly(); - #region BeWriteOnly / NotBeWriteOnly + // Assert + act.Should().NotThrow(); + } - [Fact] - public void When_having_a_writeonly_stream_be_write_only_should_succeed() - { - // Arrange - using var stream = new TestStream { Readable = false, Writable = true }; + [Fact] + public void When_having_a_readable_stream_be_write_only_should_fail() + { + // Arrange + using var stream = new TestStream { Readable = true, Writable = true }; - // Act - Action act = () => - stream.Should().BeWriteOnly(); + // Act + Action act = () => + stream.Should().BeWriteOnly("we want to test the failure {0}", "message"); - // Assert - act.Should().NotThrow(); - } + // Assert + act.Should().Throw() + .WithMessage("Expected stream to be write-only *failure message*, but it was readable or not writable."); + } - [Fact] - public void When_having_a_readable_stream_be_write_only_should_fail() - { - // Arrange - using var stream = new TestStream { Readable = true, Writable = true }; + [Fact] + public void When_having_a_non_writable_stream_be_write_only_should_fail() + { + // Arrange + using var stream = new TestStream { Readable = false, Writable = false }; - // Act - Action act = () => - stream.Should().BeWriteOnly("we want to test the failure {0}", "message"); + // Act + Action act = () => + stream.Should().BeWriteOnly("we want to test the failure {0}", "message"); - // Assert - act.Should().Throw() - .WithMessage("Expected stream to be write-only *failure message*, but it was readable or not writable."); - } + // Assert + act.Should().Throw() + .WithMessage("Expected stream to be write-only *failure message*, but it was readable or not writable."); + } - [Fact] - public void When_having_a_non_writable_stream_be_write_only_should_fail() - { - // Arrange - using var stream = new TestStream { Readable = false, Writable = false }; + [Fact] + public void When_null_be_write_only_should_fail() + { + // Arrange + TestStream stream = null; - // Act - Action act = () => - stream.Should().BeWriteOnly("we want to test the failure {0}", "message"); + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().BeWriteOnly("we want to test the failure {0}", "message"); + }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream to be write-only *failure message*, but it was readable or not writable."); + // Assert + act.Should().Throw() + .WithMessage("Expected stream to be write-only *failure message*, but found a reference."); + } } - [Fact] - public void When_null_be_write_only_should_fail() + public class NotBeWriteOnly { - // Arrange - TestStream stream = null; - - // Act - Action act = () => + [Fact] + public void When_having_a_non_writable_stream_be_not_write_only_should_succeed() { - using var _ = new AssertionScope(); - stream.Should().BeWriteOnly("we want to test the failure {0}", "message"); - }; - - // Assert - act.Should().Throw() - .WithMessage("Expected stream to be write-only *failure message*, but found a reference."); - } - - [Fact] - public void When_having_a_non_writable_stream_be_not_write_only_should_succeed() - { - // Arrange - using var stream = new TestStream { Readable = false, Writable = false }; - - // Act - Action act = () => - stream.Should().NotBeWriteOnly(); + // Arrange + using var stream = new TestStream { Readable = false, Writable = false }; - // Assert - act.Should().NotThrow(); - } + // Act + Action act = () => + stream.Should().NotBeWriteOnly(); - [Fact] - public void When_having_a_readable_stream_be_not_write_only_should_succeed() - { - // Arrange - using var stream = new TestStream { Readable = true, Writable = true }; + // Assert + act.Should().NotThrow(); + } - // Act - Action act = () => - stream.Should().NotBeWriteOnly(); + [Fact] + public void When_having_a_readable_stream_be_not_write_only_should_succeed() + { + // Arrange + using var stream = new TestStream { Readable = true, Writable = true }; - // Assert - act.Should().NotThrow(); - } + // Act + Action act = () => + stream.Should().NotBeWriteOnly(); - [Fact] - public void When_having_a_writeonly_stream_be_not_write_only_should_fail() - { - // Arrange - using var stream = new TestStream { Readable = false, Writable = true }; + // Assert + act.Should().NotThrow(); + } - // Act - Action act = () => - stream.Should().NotBeWriteOnly("we want to test the failure {0}", "message"); + [Fact] + public void When_having_a_writeonly_stream_be_not_write_only_should_fail() + { + // Arrange + using var stream = new TestStream { Readable = false, Writable = true }; - // Assert - act.Should().Throw() - .WithMessage("Expected stream not to be write-only *failure message*, but it was."); - } + // Act + Action act = () => + stream.Should().NotBeWriteOnly("we want to test the failure {0}", "message"); - [Fact] - public void When_null_not_be_write_only_should_fail() - { - // Arrange - TestStream stream = null; + // Assert + act.Should().Throw() + .WithMessage("Expected stream not to be write-only *failure message*, but it was."); + } - // Act - Action act = () => + [Fact] + public void When_null_not_be_write_only_should_fail() { - using var _ = new AssertionScope(); - stream.Should().NotBeWriteOnly("we want to test the failure {0}", "message"); - }; + // Arrange + TestStream stream = null; - // Assert - act.Should().Throw() - .WithMessage("Expected stream not to be write-only *failure message*, but found a reference."); - } + // Act + Action act = () => + { + using var _ = new AssertionScope(); + stream.Should().NotBeWriteOnly("we want to test the failure {0}", "message"); + }; - #endregion + // Assert + act.Should().Throw() + .WithMessage("Expected stream not to be write-only *failure message*, but found a reference."); + } + } } internal class ExceptingStream : Stream