Exemple #1
0
        public string AnalyzeByType(string analyzerType)
        {
            _parameters = new AnalyzerParameters
            {
                Records = Records
            };

            if (analyzerType == "analyzerbyip")
            {
                var analyzerByIp = _kernel.Get <AnalyzerByIp>();
                var converter    = _kernel.Get <IpAnalyzerReportConverter>();
                return(converter.Convert(analyzerByIp.Analyze(_parameters)));
            }

            if (analyzerType == "analyzerbysumofbytes")
            {
                var analyzerBySumOfByte         = _kernel.Get <AnalyzerSumOfBytes>();
                var reportConverterBySumOfBytes = _kernel.Get <SumOfBytesAnalyzerReportConverter>();
                return(reportConverterBySumOfBytes.Convert(analyzerBySumOfByte.Analyze(_parameters)));
            }

            if (analyzerType != null && Regex.IsMatch(analyzerType, @"analyzerbyweights\.\w+"))
            {
                var analyzerByWeights = _kernel.Get <AnalyzerByWeightings>();
                analyzerByWeights.TypeOfWeightAnalyzer = analyzerType.Split('.')[1];
                var reportConverterByWeights = _kernel.Get <WeightsAnalyzerReportConverter>();
                return(reportConverterByWeights.Convert(analyzerByWeights.Analyze(_parameters)));
            }

            return(String.Empty);
        }
Exemple #2
0
        private Dictionary <string, ICollection <IMemberDefinition> > InstrumentAndSelect(IEnumerable <string> programModules, IEnumerable <string> testModules)
        {
            AnalyzerParameters analyzerParameters = new AnalyzerParameters(args.DependencyCollectionGranularity, !args.NoSmartChecksums);
            Analyzer           analyzer           = args.TestingFramework.GetAnalyzer(analyzerParameters);

            analysisStopwatch = new Stopwatch();

            analysisStopwatch.Start();
            Dictionary <string, ICollection <IMemberDefinition> > moduleToAffectedTests = analyzer.Analyze(testModules, programModules);

            analysisStopwatch.Stop();

            ModuleDefinition         dependencyMonitorModule  = CILTransformer.GetModuleDefinition(CommonPaths.DependencyMonitorDLLPath);
            InstrumentatorParameters instrumentatorParameters = new InstrumentatorParameters(dependencyMonitorModule, args.TestingFramework, args.InstrumentationStrategy, args.InstrumentationArgumentsType, args.InstrumentAtMethodBeginning);
            Instrumentator           instrumentator           = new Instrumentator(instrumentatorParameters);

            foreach (var modulePath in testModules)
            {
                string destination = Path.Combine(Path.GetDirectoryName(modulePath), "DependencyMonitor.dll");
                File.Copy(CommonPaths.DependencyMonitorDLLPath, destination, true);
                string configuration = Path.Combine(Path.GetDirectoryName(modulePath), Paths.DependencyMonitorConfigurationFileName);
                File.WriteAllText(configuration, Paths.OutputDirectory);
            }

            instrumentationStopwatch = new Stopwatch();
            instrumentationStopwatch.Start();
            bool instrument = false;

            foreach (var tests in moduleToAffectedTests.Values)
            {
                if (tests.Any())
                {
                    // instruments if there are some tests to be run
                    instrument = true;
                    break;
                }
            }
            if (instrument)
            {
                instrumentator.Instrument(moduleToAffectedTests, programModules);
            }
            instrumentationStopwatch.Stop();

            return(moduleToAffectedTests);
        }
Exemple #3
0
        public static Analyzer GetAnalyzer(this TestingFrameworkType testingFramework, AnalyzerParameters options)
        {
            switch (testingFramework)
            {
            case TestingFrameworkType.NUnit2:
            case TestingFrameworkType.NUnit3:
                return(new NUnitAnalyzer(options));

            case TestingFrameworkType.XUnit1:
            case TestingFrameworkType.XUnit2:
                return(new XUnitAnalyzer(options));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }