diff --git a/src/NServiceBus.IntegrationTesting/IntegrationContext.cs b/src/NServiceBus.IntegrationTesting/IntegrationContext.cs index dd937a2a..1f6ad968 100644 --- a/src/NServiceBus.IntegrationTesting/IntegrationContext.cs +++ b/src/NServiceBus.IntegrationTesting/IntegrationContext.cs @@ -1,4 +1,5 @@ using NServiceBus.AcceptanceTesting; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -7,9 +8,11 @@ namespace NServiceBus.IntegrationTesting { public class IntegrationContext : ScenarioContext { - List invokedHandlers = new List(); + readonly ConcurrentBag invokedHandlers = new ConcurrentBag(); + readonly ConcurrentBag invokedSagas = new ConcurrentBag(); public IEnumerable InvokedHandlers { get { return invokedHandlers; } } + public IEnumerable InvokedSagas { get { return invokedSagas; } } internal HandlerInvocation CaptureInvokedHandler(HandlerInvocation invocation) { @@ -18,11 +21,6 @@ internal HandlerInvocation CaptureInvokedHandler(HandlerInvocation invocation) return invocation; } - List invokedSagas = new List(); - - public IEnumerable InvokedSagas { get { return invokedSagas; } } - - internal SagaInvocation CaptureInvokedSaga(SagaInvocation invocation) { invokedSagas.Add(invocation); @@ -30,7 +28,7 @@ internal SagaInvocation CaptureInvokedSaga(SagaInvocation invocation) return invocation; } - static PropertyInfo GetCurrentProperty() + static PropertyInfo GetScenarioContextCurrentProperty() { return typeof(ScenarioContext).GetProperty("Current", BindingFlags.Static | BindingFlags.NonPublic); } @@ -39,7 +37,7 @@ public static IntegrationContext CurrentContext { get { - var pi = GetCurrentProperty(); + var pi = GetScenarioContextCurrentProperty(); var current = (IntegrationContext)pi.GetMethod.Invoke(null, null); return current;