Esempio n. 1
0
        public async Task Instrument(TModel toInstrument, IList <MSTestTestcase> tests, CancellationToken token)
        {
            dependencyMonitorModule    = ModuleDefinition.ReadModule(Path.GetFullPath($"{MonitorAssemblyName}.dll"));
            dependencyMonitorType      = dependencyMonitorModule.Types.Single(x => x.FullName == DependencyMonitorClassFullName);
            testMethodStartedReference = dependencyMonitorType.Methods.Single(x => x.FullName == TestMethodStartFullName);
            testMethodNameReference    = dependencyMonitorType.Methods.Single(x => x.FullName == TestMethodNameFullName);
            testMethodEndReference     = dependencyMonitorType.Methods.Single(x => x.FullName == TestMethodEndFullName);
            typeVisitedMethodReference = dependencyMonitorType.Methods.Single(x => x.FullName == TypeMethodFullName);

            testAssemblies = tests.Select(x => x.AssemblyPath).Distinct().ToList();
            var parsingResult = await assembliesAdapter.Parse(toInstrument.AbsoluteSolutionPath, token);

            assemblies              = parsingResult.Select(x => x.AbsolutePath).ToList();
            assemblyNames           = assemblies.Select(Path.GetFileName).ToList();
            msTestTestcases         = tests;
            testNamesToExecutionIds = tests.Select(x => new Tuple <string, int>(x.Id, tests.IndexOf(x))).ToList();

            loggingHelper.ReportNeededTime(() => InstrumentProgramAssemblies(token), "Instrumenting Program Assemblies");
            loggingHelper.ReportNeededTime(() => InstrumentTestAssemblies(token), "Instrumenting Test Assemblies");
        }
Esempio n. 2
0
        public async Task <StructuralDelta <TestsModel <MSTestTestcase>, MSTestTestcase> > GetTestsDelta(TDelta programDelta, Func <MSTestTestcase, bool> filterFunction, CancellationToken token)
        {
            var oldTestsModel = testsModelAdapter.Parse(GetTestsStorage(programDelta.OldModel.VersionId));

            if (!runConfiguration.DiscoverNewTests && oldTestsModel != null)
            {
                return(new StructuralDelta <TestsModel <MSTestTestcase>, MSTestTestcase>(oldTestsModel, oldTestsModel));
            }

            if (oldTestsModel == null)
            {
                oldTestsModel = new TestsModel <MSTestTestcase>
                {
                    TestSuite = new HashSet <MSTestTestcase>(),
                    VersionId = programDelta.OldModel.VersionId
                };
            }

            var parsingResult = await assembliesAdapter.Parse(programDelta.NewModel.AbsoluteSolutionPath, token);

            token.ThrowIfCancellationRequested();

            var sources = parsingResult.Select(x => x.AbsolutePath).Where(x => x.EndsWith(settingsProvider.TestAssembliesFilter));

            var vsTestCases = await DiscoverTests(sources, token);

            var newTestsModel = new TestsModel <MSTestTestcase>
            {
                TestSuite = new HashSet <MSTestTestcase>(vsTestCases.Select(x => vsTestCaseAdapter.Parse(x)).Where(x => !x.Ignored && filterFunction(x))),
                VersionId = programDelta.NewModel.VersionId
            };

            testsModelAdapter.Unparse(newTestsModel, GetTestsStorage(programDelta.NewModel.VersionId));

            var testsDelta = new StructuralDelta <TestsModel <MSTestTestcase>, MSTestTestcase>(oldTestsModel, newTestsModel);

            testsDelta.AddedElements.AddRange(newTestsModel.TestSuite.Except(oldTestsModel.TestSuite));
            testsDelta.DeletedElements.AddRange(oldTestsModel.TestSuite.Except(newTestsModel.TestSuite));

            return(testsDelta);
        }