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

VerifyNoOtherCalls causes stack overflow when mock setup returns the mocked object (since 4.11) #846

Closed
bash opened this issue Jun 6, 2019 · 1 comment · Fixed by #848
Assignees
Labels
Milestone

Comments

@bash
Copy link

bash commented Jun 6, 2019

MCVE

using Moq;
using Xunit;

public interface IFooBuilder
{
    IFooBuilder Bar();
}

public class UnitTest1
{
    [Fact]
    public void Test1()
    {
        var builder = new Mock<IFooBuilder>();
        builder.Setup(d => d.Bar()).Returns(builder.Object);
        builder.VerifyNoOtherCalls();
    }
}

Result when running dotnet test:

Microsoft (R) Test Execution Command Line Tool Version 16.0.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
The active test run was aborted. Reason: Process is terminating due to StackOverflowException.


Test Run Aborted.

Workaround

Use a function to calculate the return value.

builder.Setup(d => d.Bar()).Returns(() => builder.Object);
@stakx stakx added the bug label Jun 6, 2019
@stakx stakx added this to the 4.12.0 milestone Jun 6, 2019
@stakx stakx self-assigned this Jun 6, 2019
@stakx
Copy link
Contributor

stakx commented Jun 6, 2019

Thanks for the bug report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants