Skip to content

EnumAssertions.Be() doesn't identify the subject (but its NotBe() counterpart does) #1832

@jasonsparc

Description

@jasonsparc

I decided to look at the source code after finding out that my enum assertions weren't identifying the subject name when using Be(), and yet it is identified correctly when using NotBe().

Apparently, in EnumAssertions.Be() (see line 60), {context:the enum} was not being used:

public AndConstraint<TAssertions> Be(TEnum expected, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(Subject?.Equals(expected) == true)
.BecauseOf(because, becauseArgs)
.FailWith("Expected the enum to be {0}{reason}, but found {1}.",
expected, Subject);
return new AndConstraint<TAssertions>((TAssertions)this);
}

This doesn't match the counterpart NotBe() (see line 105):

public AndConstraint<TAssertions> NotBe(TEnum unexpected, string because = "",
params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(Subject?.Equals(unexpected) != true)
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:the enum} not to be {0}{reason}, but it is.", unexpected);
return new AndConstraint<TAssertions>((TAssertions)this);
}

The above are permalinks but the issue currently exists in both the develop and master branches.

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