private void SetupMockTimeOutTestRun(Mock <IVsTestConsoleWrapper> mockVsTest, IReadOnlyDictionary <string, string> results, string timeoutTest, EventWaitHandle endProcess)
        {
            mockVsTest.Setup(x =>
                             x.RunTestsWithCustomTestHost(
                                 It.IsAny <IEnumerable <TestCase> >(),
                                 It.IsAny <string>(),
                                 It.IsAny <ITestRunEventsHandler>(),
                                 It.IsAny <ITestHostLauncher>())).Callback(
                (IEnumerable <TestCase> sources, string settings, ITestRunEventsHandler testRunEvents,
                 ITestHostLauncher host) =>
            {
                var collector = new CoverageCollector();
                var start     = new TestSessionStartArgs
                {
                    Configuration = settings
                };
                var mock = new Mock <IDataCollectionSink>(MockBehavior.Loose);
                TestCase timeOutTestCase = null;
                collector.Initialize(mock.Object);
                collector.TestSessionStart(start);

                var mutants = collector.MutantList;
                if (!results.ContainsKey(mutants))
                {
                    throw new ArgumentException($"Unexpected mutant run {mutants}");
                }

                var tests = sources.ToList();
                var data  = results[mutants].Split(',').Select(e => e.Split('=')).ToList();
                if (data.Count != tests.Count)
                {
                    throw new ArgumentException($"Invalid number of tests for mutant run {mutants}: found {tests.Count}, expected {data.Count}");
                }

                var runResults = new List <TestResult>(data.Count);
                foreach (var strings in data)
                {
                    var matchingTest = tests.FirstOrDefault(t => t.FullyQualifiedName == strings[0]);
                    if (matchingTest == null)
                    {
                        throw new ArgumentException($"Test {strings[0]} not run for mutant {mutants}.");
                    }
                    if (matchingTest.FullyQualifiedName == timeoutTest)
                    {
                        timeOutTestCase = matchingTest;
                    }
                    var result = new TestResult(matchingTest)
                    {
                        Outcome = strings[1] == "F" ? TestOutcome.Failed : TestOutcome.Passed, ComputerName = "."
                    };
                    runResults.Add(result);
                }
                // setup a normal test run
                MoqTestRun(testRunEvents, runResults, timeOutTestCase);
                collector.TestSessionEnd(new TestSessionEndArgs());

                endProcess.Set();
            });
        }
Esempio n. 2
0
        public void ProperlyCaptureParams()
        {
            var collector = new CoverageCollector();

            var start = new TestSessionStartArgs
            {
                Configuration = CoverageCollector.GetVsTestSettings(true, null, "Stryker.Core.UnitTest.TestRunners")
            };
            var mock = new Mock <IDataCollectionSink>(MockBehavior.Loose);

            collector.Initialize(mock.Object);

            collector.TestSessionStart(start);
            collector.TestCaseStart(new TestCaseStartArgs(new TestCase("theTest", new Uri("xunit://"), "source.cs")));
            MutantControl.CaptureCoverage.ShouldBeTrue();
        }
Esempio n. 3
0
        public void ProperlySelectMutant()
        {
            var collector = new CoverageCollector();

            var mutantMap = new Dictionary <int, IList <string> >()
            {
                [0] = new List <string>()
            };

            var start = new TestSessionStartArgs
            {
                Configuration = CoverageCollector.GetVsTestSettings(false, mutantMap, this.GetType().Namespace)
            };
            var mock = new Mock <IDataCollectionSink>(MockBehavior.Loose);

            collector.Initialize(mock.Object);

            collector.TestSessionStart(start);

            collector.TestCaseStart(new TestCaseStartArgs(new TestCase("theTest", new Uri("xunit://"), "source.cs")));

            MutantControl.ActiveMutant.ShouldBe(0);
        }