Skip to content

[Request] Custom validations on 'Stream' types #1452

@julealgon

Description

@julealgon

Description

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)

Expected behavior:

stream.Should().BeReadOnly();

Actual behavior:

using (new AssertionScope())
{
    stream.CanRead.Should().BeTrue();
    stream.CanWrite.Should().BeFalse();
}

Versions

  • 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

Additional Information

Related to #961

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions