diff --git a/Source/Interceptor.cs b/Source/Interceptor.cs index 01a930650..edde1db83 100644 --- a/Source/Interceptor.cs +++ b/Source/Interceptor.cs @@ -75,10 +75,13 @@ internal void VerifyAll() private void VerifyOrThrow(Func match) { - var failures = calls.Values.Where(match).ToArray(); - if (failures.Length > 0) + lock (calls) { - throw new MockVerificationException(failures); + var failures = calls.Values.Where(match); + if (failures.Any()) + { + throw new MockVerificationException(failures.ToArray()); + } } } @@ -96,18 +99,21 @@ public void AddCall(IProxyCall call, SetupKind kind) if (!call.IsConditional) { - // if it's not a conditional call, we do - // all the override setups. - // TODO maybe add the conditionals to other - // record like calls to be user friendly and display - // somethig like: non of this calls were performed. - if (calls.ContainsKey(key)) + lock (calls) { - // Remove previous from ordered calls - InterceptionContext.RemoveOrderedCall(calls[key]); - } + // if it's not a conditional call, we do + // all the override setups. + // TODO maybe add the conditionals to other + // record like calls to be user friendly and display + // somethig like: non of this calls were performed. + if (calls.ContainsKey(key)) + { + // Remove previous from ordered calls + InterceptionContext.RemoveOrderedCall(calls[key]); + } - calls[key] = call; + calls[key] = call; + } } InterceptionContext.AddOrderedCall(call); @@ -115,7 +121,10 @@ public void AddCall(IProxyCall call, SetupKind kind) internal void ClearCalls() { - calls.Clear(); + lock (calls) + { + calls.Clear(); + } } private IEnumerable InterceptionStrategies()