Skip to content

An unmocked method leaves its out parameter value untouched #590

Closed
@davidnemeti

Description

@davidnemeti

Describe the bug

An unmocked method leaves its out parameter value untouched, i.e. it does not set it to default value.

Now, that seems a bit unorthodox, so I believe that it should set it to the default value. A normal (non-mocked) method cannot behave like this, i.e. it cannot leave its out parameter value as not set.

Handling out parameters should be similar to handling the return value: an unmocked method returns the default value.

To Reproduce

void Main()
{
    var foo = Substitute.For<IFoo>();

    int number1, number2;

    number1 = 11;
    number2 = 22;

    foo.Baz(out number1);
    foo.Bar(out number2);

    Console.WriteLine(number1);
    Console.WriteLine(number2);
}

public interface IFoo
{
    void Bar(out int number);
    int Baz(out int number);
}

The above code produces the following output:

11
22

Expected behaviour

The above code should produce the following output:

0
0

Environment

  • NSubstitute version: 4.2.1
  • Platform: .NET Framework 4.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions