Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflow when setting up a property on a mock that references another instance of the same type #161

Closed
ArildF opened this issue Mar 13, 2015 · 1 comment

Comments

@ArildF
Copy link

ArildF commented Mar 13, 2015

The following code gives a StackOverflowException in Moq 4.2.1502.911, but not in 4.1.1309.1617:

public interface IFoo
{
    IBar Bar { get; }
}

public interface IBar
{
    IBar SomeOtherBar { get; }
    string ATC { get; }
}

[TestMethod]
public void SomeTest()
{
    var factory = new MockRepository(MockBehavior.Strict){DefaultValue = DefaultValue.Mock};
    var foo = factory.Create<IFoo>();
    foo.SetupGet(r => r.Bar.ATC).Returns("asjkhsd"); // boom
}

This appears to be a similar problem to https://code.google.com/p/moq/issues/detail?id=332 , although in this case the result is a stack overflow and not an infinite loop as it appears in that issue.

Using DefaultValue.Empty avoids the problem; however, this may not be a practical solution in our case. The value of MockBehavior does not matter.

vladonemo added a commit to vladonemo/moq4 that referenced this issue Jan 29, 2016
vladonemo added a commit to vladonemo/moq4 that referenced this issue May 12, 2016
kzu pushed a commit that referenced this issue Aug 10, 2016
@stakx
Copy link
Contributor

stakx commented Jun 5, 2017

This appears to have been fixed. The error can no longer be reproduced in Moq 4.7.25.

@stakx stakx closed this as completed Jun 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants