Skip to content

Substitute.ForPartsOf() usage -- or Alternative? #608

Closed
@CleveSteve

Description

@CleveSteve

I have a method (MethodA) I'm trying to test (of course) and I'd like to substitute a method (MethodC) that is called inside of the method (MethodA) being tested like this...

public async MethodA(CustomClass myInfo, bool myBool)
{
    ... await stuff
    paramVal1 = MethodB(paramVal1, myInfo, myBool);
    ...morestuff
}

public DifferentCustomClass MethodB(DifferentCustomClass paramVal1, CustomClass myInfo, bool myBool)
{
    ...stuff
    paramVal1.PropertyZ = MethodC(myInfo, myBool);
    ...stuff
    return paramVal1;
}

Methods A, B, and C are all in the same class.

Is there any way I can use NSubstitute to give a .Returns(value) for MethodC when testing MethodA? I tried Substitute.ForPartsOf with .Configure().MethodC(val1, val2).Returns(val0) with and without .When(x => x.MethodC(val1, val2)).DoNotCallBase() to no avail.

Is it clear what I am trying to do here? Is there a way this can be implemented in NSubstitute? Thanks.

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