예제 #1
0
        public async Task SetThreadUICultureToMatchFeatureCulture()
        {
            var scenarioStep = new GivenStep("Scenario step", DataTable.Empty, null);
            var testFeature  = new Feature("Feature", null,
                                           Background.Empty,
                                           new[]
            {
                new Scenario(
                    "Scenario",
                    new[] { scenarioStep },
                    1,
                    Enumerable.Empty <Tag>())
            },
                                           Enumerable.Empty <ScenarioOutline>(),
                                           Enumerable.Empty <Rule>(),
                                           new[] {
                new Tag("culture(nb-NO)")
            });

            var testData = new DiscoveredTestData(testAssembly, testFeature, null, testFeature.Scenarios.First());

            string capturedCultureName     = null;
            var    mockScenarioStepMapping = new Mock <IStepBinding>();

            mockStepBinder
            .Setup(m => m.GetBindingFor(scenarioStep, testAssembly))
            .Returns(mockScenarioStepMapping.Object)
            .Callback(() => capturedCultureName = CultureInfo.CurrentUICulture.Name);

            var testResult = await stepsExecutor.Execute(testCase, testData, testRunContext, mockLogger.Object);

            Assert.AreEqual("nb-NO", capturedCultureName);
        }
예제 #2
0
        public async Task ExecuteFeatureBackgroundStepsThenScenarioSteps()
        {
            var backgroundStep = new GivenStep("Feature background step", DataTable.Empty, null);
            var scenarioStep   = new GivenStep("Scenario step", DataTable.Empty, null);

            var testFeature = new Feature("Feature", null,
                                          new Background(
                                              new[] { backgroundStep },
                                              0),
                                          new[]
            {
                new Scenario(
                    "Scenario",
                    new[] { scenarioStep },
                    1,
                    Enumerable.Empty <Tag>())
            },
                                          Enumerable.Empty <ScenarioOutline>(),
                                          Enumerable.Empty <Rule>(),
                                          Enumerable.Empty <Tag>());

            var testData = new DiscoveredTestData(testAssembly, testFeature, null, testFeature.Scenarios.First());

            var invocationOrder           = 0;
            var mockBackgroundStepMapping = new Mock <IStepBinding>();

            mockStepBinder
            .Setup(m => m.GetBindingFor(backgroundStep, testAssembly))
            .Returns(mockBackgroundStepMapping.Object)
            .Callback(() => Assert.AreEqual(0, invocationOrder++));

            var mockScenarioStepMapping = new Mock <IStepBinding>();

            mockStepBinder
            .Setup(m => m.GetBindingFor(scenarioStep, testAssembly))
            .Returns(mockScenarioStepMapping.Object)
            .Callback(() => Assert.AreEqual(1, invocationOrder++));

            var testResult = await stepsExecutor.Execute(testCase, testData, testRunContext, mockLogger.Object);

            mockBackgroundStepMapping.Verify(m => m.Execute(It.IsAny <IServiceProvider>(), It.IsAny <Collection <TestResultMessage> >()), Times.Once);
            mockScenarioStepMapping.Verify(m => m.Execute(It.IsAny <IServiceProvider>(), It.IsAny <Collection <TestResultMessage> >()), Times.Once);
        }
예제 #3
0
        private async Task RunMappedTest(TestCase testCase, DiscoveredTestData testData, TestRunContext testRunContext, StepBinder stepBinder, IFrameworkHandle frameworkHandle)
        {
            frameworkHandle.SendMessage(TestMessageLevel.Informational, $"Starting test \"{testCase.DisplayName}\"");

            frameworkHandle.RecordStart(testCase);

            var executor = new StepsExecutor(stepBinder);

            // Deliberately resume on same context to try to avoid Visual Studio Test Explorer "bug" (?) that doesn't
            // always detect the end of the test run when multiple tests are run in parallel.
            var testResult = await executor
                             .Execute(testCase, testData, testRunContext, frameworkHandle)
                             .ConfigureAwait(true);

            // https://github.com/Microsoft/vstest/blob/master/src/Microsoft.TestPlatform.CrossPlatEngine/Adapter/TestExecutionRecorder.cs <- comments here seem to suggest that we need to call RecordEnd just before RecordResult
            frameworkHandle.RecordEnd(testCase, testResult.Outcome);
            frameworkHandle.RecordResult(testResult);

            frameworkHandle.SendMessage(TestMessageLevel.Informational, $"Finished test \"{testCase.DisplayName}\"");
        }