diff --git a/src/NScenario/TestScenarioFactory.cs b/src/NScenario/TestScenarioFactory.cs index d8a1eeb..9db09f3 100644 --- a/src/NScenario/TestScenarioFactory.cs +++ b/src/NScenario/TestScenarioFactory.cs @@ -42,11 +42,15 @@ private static string GenerateScenarioTitle(string scenario) private static readonly HashSet ScenarioTitles = new HashSet(); + private static readonly object titleUniquenessLock = new object(); private static void EnsureTestScenarioTitleUniqueness(string scenarioTitle) { - if (ScenarioTitles.Add(scenarioTitle) == false) + lock (titleUniquenessLock) { - throw new InvalidOperationException("Test scenario with a given title was already created. If you are using test method with parameters, please specify test scenario title explicitly by setting 'title' parameter."); + if (ScenarioTitles.Add(scenarioTitle) == false) + { + throw new InvalidOperationException("Test scenario with a given title was already created. If you are using test method with parameters, please specify test scenario title explicitly by setting 'title' parameter."); + } } }