Should().Be() is claiming that objects aren't equal even though they should be equal
See original GitHub issueDescription
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:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Excellent solution @jnyrup ! It worked. You’re the best. Really appreciate you 🙏
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