Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Source/Mock/lhc_mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ bool Mock_Internal_HCHttpCallPerformAsync(
auto& mocks{ httpSingleton->m_mocks };
HC_MOCK_CALL* mock{ nullptr };

// Use the most recently added mock that matches (similar to a stack).
for (auto iter = mocks.rbegin(); iter != mocks.rend(); ++iter)
// Use the first mock that matches this call
for (auto iter = mocks.begin(); iter != mocks.end(); ++iter)
{
if (DoesMockCallMatch(*iter, originalCall))
{
Expand Down Expand Up @@ -128,6 +128,21 @@ bool Mock_Internal_HCHttpCallPerformAsync(
HCHttpCallResponseSetHeader(originalCall, str1, str2);
}

// If this is not the only mock that matches, remove it from the list of mocks so that multiple can be used
// in sequence
auto countMatching = std::count_if(
mocks.begin(),
mocks.end(),
[originalCall](auto m)
{
return DoesMockCallMatch(m, originalCall);
});

if (countMatching > 1)
{
HCMockRemoveMock(mock);
}

return true;
}

Expand Down