I have what I think should be a very simple test case, but every time I run it, QTAgent32 dies. Running a test case in debug mode shows that System.StackOverflowException"Unknown module" is selected. I narrowed it down to the most basic implementation that demonstrates this behavior (.NET 4 and VS 2010 Ultimate):
[TestClass]
public class StackOverflow
{
[TestMethod]
public void CreateStackOverflow()
{
var mockMyType1 = new Mock<MyType>();
mockMyType1.Setup(m => m.Equals(mockMyType1.Object)).Returns(true);
var mockMyType2 = new Mock<MyType>();
Assert.IsTrue(mockMyType1.Object.Equals(mockMyType1.Object));
Assert.IsFalse(mockMyType1.Object.Equals(mockMyType2.Object));
}
}
public class MyType
{
public virtual bool IsActive { get; set; }
public override bool Equals(object obj)
{
return false;
}
}
I feel like I'm missing something important with regards to closing, or maybe Moka, but it seems like this should work. Things I tried trying to understand the problem, but only confused me more:
- I tried replacing the Equals () setting with
mockMyType.Setup(m => m.Equals(m)).Returns(true);, but that causes Moq to throw a NotSupportedException - If I make CallBase true instead of setting Equals (), everything works
- , MyType Equals(), .
- , ? .
: , ( ), , . - Moq Visual Studio, ?
. Denys Moq. :
mockMyType1.Setup(m => m.Equals(It.Is<MyType>(x => ReferenceEquals(x, mockMyType1.Object)))).Returns(true);