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

NullReferenceException when argument implements IEnumerable #169

Closed
frolyo opened this issue May 6, 2015 · 1 comment
Closed

NullReferenceException when argument implements IEnumerable #169

frolyo opened this issue May 6, 2015 · 1 comment
Labels

Comments

@frolyo
Copy link

frolyo commented May 6, 2015

if I make IInput not implementing IEnumerable, then NullRef does not occur.

using System.Collections.Generic;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Moq;

[TestClass]
public class FooTest
{
    [TestMethod]
    public void ShouldCalculate()
    {
        var mocks = new MockRepository(MockBehavior.Loose);
        var service = mocks.Create<IDependency>();

        var input1 = mocks.OneOf<IInput>();
        service.Setup(x => x.Run(input1)).Returns(1);

        var input2 = mocks.OneOf<IInput>();
        service.Setup(x => x.Run(input2)).Returns(2);

        var foo = new Foo(service.Object);
        foo.Calculate(input1);
        foo.Calculate(input2);
    }
}

public interface IDependency
{
    decimal Run(IInput input);
}

public interface IInput : IEnumerable<int>
{
}

public class Foo
{
    private readonly IDependency dependency;

    public Foo(IDependency dependency)
    {
        this.dependency = dependency;
    }

    public void Calculate(IInput input)
    {
        this.dependency.Run(input);
    }
}
@stakx
Copy link
Contributor

stakx commented Jul 11, 2017

This will be fixed in the next release of Moq (version >4.7.63).

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

No branches or pull requests

2 participants