You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we update to the moq version 4.5.30 the test below fails.
If we remove the "Equals" attribute (it is from Fody) from the class "Bar" the test succeeds.
With the previous version we don't have this problem.
The setup from "bar1" gets lost somehow.
[Fact]
public void FactMethodName()
{
var bar1 = new Bar();
var bar2 = new Bar();
var foo = new Mock<IFoo>();
foo.Setup(x => x.Foo(bar1)).Returns("aa");
foo.Setup(x => x.Foo(bar2)).Returns("bb");
foo.Object.Foo(bar1).Should().Be("aa"); // fails
foo.Object.Foo(bar2).Should().Be("bb");
}
public interface IFoo
{
string Foo(Bar bar);
}
[Equals]
public class Bar
{
public override string ToString()
{
return "Bar";
}
}
The text was updated successfully, but these errors were encountered:
Moq now supports mocking Equals, GetHashCode and ToString, which likely has an unexpected interaction with Fody. Dunno how it's implemented though, and what we should be doing.
This type definition and Fody's processing of it means that although Bar is a reference type, comparing any two instances for equality will yield true. For instance:
varbar1=new Bar();varbar2=new Bar();
bar1.Equals(bar2) == true. Therefore, the following two setups are equivalent (since Moq matches these arguments using object.Equals) and the last one overrides the first one:
When we update to the moq version 4.5.30 the test below fails.
If we remove the "Equals" attribute (it is from Fody) from the class "Bar" the test succeeds.
With the previous version we don't have this problem.
The setup from "bar1" gets lost somehow.
The text was updated successfully, but these errors were encountered: