I've come across a few scenarios where I need to validate specific properties and property combinations on Stream instances. I noticed the library does not expose any custom validations for such types so I had to workaround it.
I'd like to see simple validations such as:
.BeWritable (stream.CanWrite).BeReadable (stream.CanRead).BeReadOnly (stream.CanRead && !stream.CanWrite).BeWriteOnly (stream.CanWrite && !stream.CanRead).BeSeekable (stream.CanSeek)As well as potentially more advanced validations such as:
.HaveContentsEquivalentTo(byte[]) (matches a given byte[] for readable streams)stream.Should().BeReadOnly();
using (new AssertionScope())
{
stream.CanRead.Should().BeTrue();
stream.CanWrite.Should().BeFalse();
}
Which version of Fluent Assertions are you using?
5.10.3
Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.1.
Net Core 3.1 / Net 5
Related to #961
Sounds like a good start to me :+1:
For completeness it should also have:
NotBeSeekableNotBeReadable NotBeWritableIt should maybe have
HaveLength/NotHaveLengthNotSupportedException for non-seekable streams.I'm not sure about the HaveContentsEquivalentTo as would require us to make assumptions on _how_ to consume the particular stream.
That might make a strong coupling on implementation details.
The StreamAssertions should be generic in TStream, such that it:
StreamAssertionsI'm not sure about the HaveContentsEquivalentTo as would require us to make assumptions on how to consume the particular stream.
Can you elaborate what assumptions you are foreseeing?
As long as the comparison is with a byte[] I don't think there would be much to it, since you can read the bytes from a stream regardless of stream type, right?
My initial thoughts are:
Stream that can never be fully consumed.expected.Length bytes.Stream.Stream where a using CopyTo would give sync-over-async execution.
Most helpful comment
Sounds like a good start to me :+1:
For completeness it should also have:
NotBeSeekableNotBeReadableNotBeWritableE.g. an initially writeonly stream being in a state where it has been closed for further writing. It is now not readonly but at the same time not writeonly.
It should maybe have
HaveLength/NotHaveLengthNotSupportedExceptionfor non-seekable streams.I'm not sure about the
HaveContentsEquivalentToas would require us to make assumptions on _how_ to consume the particular stream.That might make a strong coupling on implementation details.
The
StreamAssertionsshould be generic inTStream, such that it:StreamAssertions