Skip to content

Allow callbacks (Do/Does) before Returns #833

Open
@Jason31569

Description

@Jason31569

Referencing issue #98...

While doing something like stuffDoer.Calculate().Returns(42).AndCalls(x => blah()); works, it is would make a lot more sense to be able to do something like stuffDoer.Calculate(something).Do(x => { }).Returns(42); instead

Take the below example

var items = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

var a = items.Where(x => x % 2 == 0).Skip(3).ToArray();
var b = items.Skip(3).Where(x => x % 2 == 0).ToArray();

Because execution is from left to right a=[8, 10], and b=[4, 6, 8, 10]

We are used to reading (and even expecting) statements to work from left to right. Someone new to NSubstitute (like myself) could find this confusing, and would not expect the trailing Do to run before the Returns

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestRequest for a new NSubstitute feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions