[FluentResults.Extensions.FluentAssertions.Test] HaveMetadata breaks when `new string` is used
The following fails in my XUnit test suite:
var testValue = String.Join(", ", new [] {"test1"});
var error = new Error("Missing columns from extraction");
IEnumerable<(string, string)> groups = new (string, string)[] { ("Category", testValue) };
foreach (var (key, value) in groups)
{
error = error.WithMetadata(key, value);
}
var testResult = Result.Fail<JObject>(error);
// Act
var result = sut.VerifyMapping(JsonConvert.SerializeObject(mapping), extraction);
// Assert
testResult.Should()
.BeFailure()
.And.HaveReason("Missing", MessageComparisonLogics.ActualContainsExpected)
.That.HaveMetadata("Category", "test1");
// Assert
result.Should()
.BeFailure()
.And.HaveReason("Missing", MessageComparisonLogics.ActualContainsExpected)
.That.HaveMetadata("Category", "test1");
Where result is the real value I'm trying to check and testResult is a variable I've created to try and duplicate. As you can see bellow they have the same structure.

However, the result assertions fail, but testResult don't. I've then tried to step through the actual actions of the assertion, where I've found the following issue (result assertion).

The equality comparison here returns false for "obj == metatdataValue, but when I tried obj.Equals(metatdataValue)` it returned true.
Do you have any idea why would this be happening, or what would be a way to fix it? Sorry if it's obvious, I'm quite new to dotnet
Okay, so turns out, swapping out
var testValue = String.Join(", ", new [] {"test1"});
// To
var testValue = String.Join(", ", new [] {new string("test1")});
// Or
var testValue = String.Join(", ", new [] {"aatest1".Substring(2)});
Causes the testResult to fail as well. Is this intended behaviour?
The second line is not buildable in my vs (.net 6). Which .net version do you use?
I've got the same problem, but when using the Guid instead of the string.
This error happens due to Guid boxing as the Guid equality operator compares objects rather than values.
As you can see here I have obj and metadataValue with the same value, but as Guid were boxed earlier they represent different objects. Using obj.Equals(metatdataValue) will resolve this issue, due to value comparison.