diff --git a/Source/Mock/lhc_mock.cpp b/Source/Mock/lhc_mock.cpp index 73c276ec..c1fb2d7b 100644 --- a/Source/Mock/lhc_mock.cpp +++ b/Source/Mock/lhc_mock.cpp @@ -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)) { @@ -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; }