Skip to content

Methods are not guarded against being wrapped in an AssertionScope #2400

@jnyrup

Description

@jnyrup

Description

When doing #2399 I found that these four methods in TypeAssertions are not guarded against being wrapped in an AssertionScope.

  • HaveExplicitProperty
  • NotHaveExplicitProperty
  • HaveExplicitMethod
  • NotHaveExplicitMethod

See how we call Should().Implement() and the make the next assertion without any guards.

Subject.Should().Implement(interfaceType, because, becauseArgs);
var explicitlyImplementsProperty = Subject.HasExplicitlyImplementedProperty(interfaceType, name);
Execute.Assertion
.BecauseOf(because, becauseArgs)
.ForCondition(explicitlyImplementsProperty)
.FailWith(
$"Expected {Subject} to explicitly implement {interfaceType}.{name}{{reason}}, but it does not.");

Reproduction Steps

var act = () =>
{
    using var _ = new AssertionScope();
    typeof(int).Should().HaveExplicitProperty(typeof(IExplicitInterface), "Foo");
};

act.Should().Throw<XunitException>()
    .WithMessage("Expected type System.Int32 to*implement IExplicitInterface.Foo, but it does not.");

Expected behavior

pass

Actual behavior

Expected exception message to match the equivalent of "Expected type System.Int32 to*implement IExplicitInterface.Foo, but it does not.", but "Expected type System.Int32 to implement interface FluentAssertions.Specs.Types.IExplicitInterface, but it does not.
Expected System.Int32 to explicitly implement FluentAssertions.Specs.Types.IExplicitInterface.Foo, but it does not.
" does not.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Are you willing to help with a pull-request?

Yes, please assign this issue to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions