示例#1
0
        private async Task <ITestRunner> GetTestRunnerWithoutExceptionHandlingAsync(string testClassId)
        {
            if (!testRunnerRegistry.TryGetValue(testClassId, out var testRunner))
            {
                await syncRootSemaphore.WaitAsync();

                try
                {
                    if (!testRunnerRegistry.TryGetValue(testClassId, out testRunner))
                    {
                        testRunner = await CreateTestRunnerAsync(testClassId);

                        testRunnerRegistry.Add(testClassId, testRunner);

                        if (IsMultiThreaded)
                        {
                            FeatureContext.DisableSingletonInstance();
                            ScenarioContext.DisableSingletonInstance();
                            ScenarioStepContext.DisableSingletonInstance();
                        }
                    }
                }
                finally
                {
                    syncRootSemaphore.Release();
                }
            }
            return(testRunner);
        }
 public static StepDefinition CurrentStep(this ScenarioStepContext context)
 {
     if (!(ExecutionContextContainer.Contexts[Thread.CurrentThread.ManagedThreadId].PeekingEnabled ||
           ExecutionContextContainer.Contexts[Thread.CurrentThread.ManagedThreadId].RegressionEnabled))
     {
         throw new TagNotSetException("enable-peeking", nameof(CurrentStep));
     }
     return(ExecutionContextContainer.Contexts[Thread.CurrentThread.ManagedThreadId].CurrentStep);
 }
        public static void RegisterRepeatCount(this ScenarioStepContext context, string repeatContextName, int count)
        {
            if (!ExecutionContextContainer.Contexts[Thread.CurrentThread.ManagedThreadId].RegressionEnabled)
            {
                throw new TagNotSetException("enable-regression", nameof(RegisterRepeatCount));
            }

            var contextDictionary = ExecutionContextContainer.Contexts[Thread.CurrentThread.ManagedThreadId].RepeatContext;

            contextDictionary[repeatContextName] = new RepeatContext()
            {
                Count = count,
                BeginStepDefinition = context.CurrentStep()
            };
        }
        public static void DecrementRepeatCount(this ScenarioStepContext context, string repeatContextName)
        {
            if (!ExecutionContextContainer.Contexts[Thread.CurrentThread.ManagedThreadId].RegressionEnabled)
            {
                throw new TagNotSetException("enable-regression", nameof(DecrementRepeatCount));
            }

            var contextDictionary = ExecutionContextContainer.Contexts[Thread.CurrentThread.ManagedThreadId].RepeatContext;

            if (contextDictionary.ContainsKey(repeatContextName))
            {
                contextDictionary[repeatContextName] = new RepeatContext()
                {
                    Count = contextDictionary[repeatContextName].Count - 1,
                    BeginStepDefinition = contextDictionary[repeatContextName].BeginStepDefinition,
                    EndStepDefinition   = context.CurrentStep()
                };
            }
            else
            {
                throw new AdvanceStepsException($"Repeat context with the name {repeatContextName} is not yet set, please call 'RegisterRepeatCount' to set it");
            }
        }
示例#5
0
        private ITestRunner GetTestRunnerWithoutExceptionHandling(int threadId)
        {
            ITestRunner testRunner;

            if (!testRunnerRegistry.TryGetValue(threadId, out testRunner))
            {
                lock (syncRoot)
                {
                    if (!testRunnerRegistry.TryGetValue(threadId, out testRunner))
                    {
                        testRunner = CreateTestRunner(threadId);
                        testRunnerRegistry.Add(threadId, testRunner);

                        if (IsMultiThreaded)
                        {
                            FeatureContext.DisableSingletonInstance();
                            ScenarioContext.DisableSingletonInstance();
                            ScenarioStepContext.DisableSingletonInstance();
                        }
                    }
                }
            }
            return(testRunner);
        }
 public static StepDefinition CurrentStep(this ScenarioStepContext context)
 {
     return(ExecutionContextContainer.Contexts[Thread.CurrentThread.ManagedThreadId].CurrentStep);
 }
示例#7
0
 internal static void DisableSingletonInstance()
 {
     isCurrentDisabled = true;
     Thread.MemoryBarrier();
     current = null;
 }
示例#8
0
 internal static void DisableSingletonInstance()
 {
     isCurrentDisabled = true;
     Thread.MemoryBarrier();
     current = null;
 }