Skip to content

Assign non-out/ref arg from AndDoes #61

Closed
@dtchepak

Description

Just realised that out and ref arguments can also be set via AndDoes (in the same way they can be set from Returns). This should probably also result in a NS3005 if a non-out/ref arg is set.

        public interface ILookup { bool Lookup(string key, out int i); }

        [Fact]
        public void Test() {
            var sub = Substitute.For<ILookup>();

            sub.Lookup("blah", out Arg.Any<int>())
               .Returns(true)
               .AndDoes(x => x[0] = 45); // <-- incorrectly setting x[0] instead of x[1]. Should give NS3005

            sub.Lookup("blah", out var value);
        }

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions