Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Replacement of .IsSameOrEqualTo() for extensions in v6.0 #1644

Answered by dennisdoomen
CNBoland asked this question in Q&A
Discussion options

I'm working with an extension that uses IsSameOrEqualTo() like so:

public TObjectResultAssertion WithValue(object expectedValue, string reason = "", params object[] reasonArgs)
{
    object actualValue = ObjectResultSubject.Value;

    Execute.Assertion
        .BecauseOf(reason, reasonArgs)
        .ForCondition(actualValue.IsSameOrEqualTo(expectedValue))
        .WithDefaultIdentifier(Identifier + ".Value")
        .FailWith(FailureMessages.CommonFailMessage, expectedValue, actualValue);

    return (TObjectResultAssertion)this;
}

IsSameOrEqualTo() is now an internal in v6.0. What is a recommended replacement?

You must be logged in to vote

Since it's an internal piece of code, it was never meant to be reused outside our code base. But you can still copy the code if you really need it. Although in most cases, a simple Equals should suffice.

Replies: 2 comments · 4 replies

Comment options

Since it's an internal piece of code, it was never meant to be reused outside our code base. But you can still copy the code if you really need it. Although in most cases, a simple Equals should suffice.

You must be logged in to vote
2 replies
@jnyrup
Comment options

To elaborate a bit more, IsSameOrEquals is now mostly object.Equals() plus

  • allow comparison of boxed numerics, e.g. comparing (object)1d and (object)1L, and
  • optimizations to avoid boxing of value types.
@CNBoland
Comment options

@dennisdoomen That worked nicely. Thank you for the suggestion.

Answer selected by CNBoland
Comment options

Hi,
I have upgraded to version 6.10.0 and just replaced IsSameOrEqualTo() with Equals() as suggested. But i am getting a System.NullReferenceException. what am i doing wrong?

        if (actualValue.Equals(expectedValue.Value))
        {
        }
You must be logged in to vote
2 replies
@jnyrup
Comment options

With object.Equals() I guess I meant public static bool Equals(object? objA, object? objB)

So in your case Equals(actualValue, expectedValue.Value).

Here's the implementation of IsSameOrEqualTo from v5

@Lemraj
Comment options

Thanks for the quick response! your suggestion worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.