Skip to content

Commit

Permalink
Merge pull request #52 from mauroservienti/thread-safe-integration-co…
Browse files Browse the repository at this point in the history
…ntext

Thread safe integration context
  • Loading branch information
mauroservienti authored Jun 1, 2020
2 parents 5b7205d + 0ecada4 commit 65c75f8
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/NServiceBus.IntegrationTesting/IntegrationContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NServiceBus.AcceptanceTesting;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand All @@ -7,9 +8,11 @@ namespace NServiceBus.IntegrationTesting
{
public class IntegrationContext : ScenarioContext
{
List<HandlerInvocation> invokedHandlers = new List<HandlerInvocation>();
readonly ConcurrentBag<HandlerInvocation> invokedHandlers = new ConcurrentBag<HandlerInvocation>();
readonly ConcurrentBag<SagaInvocation> invokedSagas = new ConcurrentBag<SagaInvocation>();

public IEnumerable<HandlerInvocation> InvokedHandlers { get { return invokedHandlers; } }
public IEnumerable<SagaInvocation> InvokedSagas { get { return invokedSagas; } }

internal HandlerInvocation CaptureInvokedHandler(HandlerInvocation invocation)
{
Expand All @@ -18,19 +21,14 @@ internal HandlerInvocation CaptureInvokedHandler(HandlerInvocation invocation)
return invocation;
}

List<SagaInvocation> invokedSagas = new List<SagaInvocation>();

public IEnumerable<SagaInvocation> InvokedSagas { get { return invokedSagas; } }


internal SagaInvocation CaptureInvokedSaga(SagaInvocation invocation)
{
invokedSagas.Add(invocation);

return invocation;
}

static PropertyInfo GetCurrentProperty()
static PropertyInfo GetScenarioContextCurrentProperty()
{
return typeof(ScenarioContext).GetProperty("Current", BindingFlags.Static | BindingFlags.NonPublic);
}
Expand All @@ -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;
Expand Down

0 comments on commit 65c75f8

Please sign in to comment.