question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should().Be() is claiming that objects aren't equal even though they should be equal

See original GitHub issue

Description

When running my test I’m getting the following error

  Message: 
    Expected SauceOptions.BrowserName to be chrome, but found chrome.
  Stack Trace: 
    LateBoundTestFramework.Throw(String message)
    TestFrameworkProvider.Throw(String message)
    DefaultAssertionStrategy.HandleFailure(String message)
    AssertionScope.FailWith(Func`1 failReasonFunc)
    AssertionScope.FailWith(Func`1 failReasonFunc)
    AssertionScope.FailWith(String message, Object[] args)
    ObjectAssertions.Be(Object expected, String because, Object[] becauseArgs)
    SauceOptionsTests.UsesLatestChromeWindowsVersionsByDefault() line 29

[Description of the issue]

Complete minimal example reproducing the issue

[TestMethod]
public void UsesLatestChromeWindowsVersionsByDefault()
{
    SauceOptions = new SauceOptions();
    SauceOptions.BrowserName.Should().Be(Browser.Chrome);
}

public class SauceOptions
{
    private Browser _browserName = Browser.Chrome;
    public Browser BrowserName 
    { 
        get
        {
            return _browserName;
        }
    }
}

Expected behavior:

For the test to pass and assert true

Actual behavior:

Failure with message

  Message: 
    Expected SauceOptions.BrowserName to be chrome, but found chrome.
  Stack Trace: 
    LateBoundTestFramework.Throw(String message)
    TestFrameworkProvider.Throw(String message)
    DefaultAssertionStrategy.HandleFailure(String message)
    AssertionScope.FailWith(Func`1 failReasonFunc)
    AssertionScope.FailWith(Func`1 failReasonFunc)
    AssertionScope.FailWith(String message, Object[] args)
    ObjectAssertions.Be(Object expected, String because, Object[] becauseArgs)
    SauceOptionsTests.UsesLatestChromeWindowsVersionsByDefault() line 29

Versions

  • Which version of Fluent Assertions are you using? 5.9.0
  • Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.1. .NET Core 3.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
nadvolodcommented, Feb 5, 2020

Excellent solution @jnyrup ! It worked. You’re the best. Really appreciate you 🙏

2reactions
dennisdoomencommented, Feb 5, 2020

I do wonder if we can do something to make the distinction clearer if the IValueFormatters for the actual and expectation yield the same output

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Is it a good idea to have logic in the equals method ...
An equality operator will claim that two objects are equal if and only if they should be considered equal, due to whatever considerations...
Read more >
ShouldBeEquivalentTo method still invokes Object.Equals ...
I think you cannot alter behavior of this function, it assumes that if you override Equals - than you want comparison to be...
Read more >
Equality comparisons and sameness - JavaScript | MDN
This model falls short with Object.is , because it isn't "looser" than double equals or "stricter" than triple equals, nor does it fit...
Read more >
C# Object Equality in .NET
Explore ways to override the default concepts of object equality, based on reference and value types, in the Microsoft .NET Framework.
Read more >
Be() and BeSameAs() are doing the same thing · Issue #1237
Be uses object.Equals() to compare whether your two identical instances ProductRequestModel are to be considered equal. As you haven't ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found