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

Null array elements are not printed to test output #321

Closed
cmeeren opened this issue Feb 10, 2017 · 1 comment
Closed

Null array elements are not printed to test output #321

cmeeren opened this issue Feb 10, 2017 · 1 comment

Comments

@cmeeren
Copy link

cmeeren commented Feb 10, 2017

Consider the following test fixture with two tests (the only difference between Test1 and Test2 is that I've switcher null/ids between the act and assert parts):

[TestFixture]
public class CustomerLookupControllerTests
{
    private CustomerLookupController _controller;
    private Mock<IStatsRepository> _repo;

    [SetUp]
    public void SetUp()
    {
        _repo = new Mock<IStatsRepository>();
        _controller = new CustomerLookupController(_repo.Object);
    }

    [Test]
    public void Test1()
    {
        // Arrange
        var ids = new[] { "foo", null, "bar", null, "baz" };

        // Act
        _controller.GetMatchingCustomers(null, ids, 1);

        // Assert (will obviously fail)
        _repo.Verify(mock => mock.GetMatchingCustomers(null, null, 1));
    }

    [Test]
    public void Test2()
    {
        // Arrange
        var ids = new[] { "foo", null, "bar", null, "baz" };

        // Act
        _controller.GetMatchingCustomers(null, null, 1);

        // Assert (will obviously fail)
        _repo.Verify(mock => mock.GetMatchingCustomers(null, ids, 1));
    }
}

Test1 will fail with the following message, note the lack of null elements in the performed invocation:

Moq.MockException : 
Expected invocation on the mock at least once, but was never performed: 
mock => mock.GetMatchingCustomers(null, null, 1)
No setups configured.

Performed invocations:
IStatsRepository.GetMatchingCustomers(null, ["foo", "bar", "baz"], 1)

Test2 will fail with the following message, note the complete lack of the array in the expected invocation:

Moq.MockException : 
Expected invocation on the mock at least once, but was never performed: 
mock => mock.GetMatchingCustomers(null, , 1)
No setups configured.

Performed invocations:
IStatsRepository.GetMatchingCustomers(null, null, 1)

In case it's relevant, I'm using NUnit with ReSharper's test runner.

@stakx
Copy link
Contributor

stakx commented Jun 20, 2017

This should be fixed in Moq 4.7.58.

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

No branches or pull requests

3 participants