vendredi 25 mars 2016

Moq - Mocked Method Response is not returning expected value

Moq Setup:

Branch3GInfo mockCasResponse = new Branch3GInfo
{
    Branch3GActiveRouters = new CasApiRouterModelExtendedInfo[]
    {
        new CasApiRouterModelExtendedInfo(12345, "MyRouter", 4, 1, "MyModelType")
    }
};

var mock = new Mock<BranchCircuitStatusScheduleEntry>(_application);
mock.CallBase = true;

mock.Setup(x => x.GetNodesOn3GBackupAsync()).ReturnsAsync(mockCasResponse);
var mockedObject = mock.Object.GetNodesOn3GBackupAsync().Result;

mockedObject contains the mocked response which I have created.

BranchCircuitStatusScheduleEntry has a method called GetNodesInCriticalCondition().

GetNodesInCriticalCondition() calls GetNodesOn3GBackupAsync() within its body, and then produces some output based on that. However, it makes this call, it calls the REAL GetNodesOn3GBackupAsync(), and not my mocked version. Is there a way to make this work?

Aucun commentaire:

Enregistrer un commentaire