public async Task ExecuteMethodsMarkedForAfterRun()
        {
            var initialCount = HookSamples.AfterRunCallCount;
            await runHooks.ExecuteAfterRun();

            Assert.AreEqual(initialCount + 1, HookSamples.AfterRunCallCount);
        }
Beispiel #2
0
        private void RunMappedTests(IEnumerable <TestCase> mappedTests, IFrameworkHandle frameworkHandle)
        {
            frameworkHandle.SendMessage(TestMessageLevel.Informational, "Running tests");

            using (var defaultServiceProvider = new DefaultServiceProvider())
            {
                var testRunContext = (TestRunContext)defaultServiceProvider.GetService(
                    typeof(TestRunContext));

                var runHooks = new RunHooks(
                    testRunContext,
                    mappedTests
                    .Select(
                        test => test
                        .DiscoveredData()
                        .Assembly)
                    .Distinct());

                runHooks.ExecuteBeforeRun().Wait();

                var stepBinder = new StepBinder();

                var tasks = new List <Task>();

                foreach (var testCase in mappedTests)
                {
                    if (isCancelling)
                    {
                        frameworkHandle.SendMessage(TestMessageLevel.Informational, "Test run cancelled");
                        break;
                    }

                    if (testCase.DiscoveredData().IsIgnored)
                    {
                        testCase.MarkAsSkipped(frameworkHandle);
                        continue;
                    }

                    tasks.Add(
                        RunMappedTest(testCase, testCase.DiscoveredData(), testRunContext, stepBinder, frameworkHandle));
                }

                Task.WhenAll(tasks).Wait();
                runHooks.ExecuteAfterRun().Wait();
            }
        }