public void SetUp()
        {
            _project = new Project(Path.GetFullPath("someProject.csproj"), new ProjectDocument(ProjectType.CSharp));
			_project.Value.SetOutputPath("");
			_project.Value.SetAssemblyName("someAssembly.dll");
            _bus = MockRepository.GenerateMock<IMessageBus>();
            _listGenerator = MockRepository.GenerateMock<IGenerateBuildList>();
            _configuration = MockRepository.GenerateMock<IConfiguration>();
            _buildRunner = MockRepository.GenerateMock<IBuildRunner>();
            _testRunner = MockRepository.GenerateMock<ITestRunner>();
			_testAssemblyValidator = MockRepository.GenerateMock<IDetermineIfAssemblyShouldBeTested>();
			_optimizer = MockRepository.GenerateMock<IOptimizeBuildConfiguration>();
			_runInfo = new RunInfo(_project);
			_runInfo.ShouldBuild();
			_runInfo.SetAssembly(_project.Value.AssemblyName);
			_optimizer.Stub(o => o.AssembleBuildConfiguration(new string[] {})).IgnoreArguments().Return(new RunInfo[] { _runInfo });
            _preProcessor = MockRepository.GenerateMock<IPreProcessTestruns>();
            _preProcessor.Stub(x => x.PreProcess(null)).IgnoreArguments().Return(new RunInfo[] { _runInfo });
            var preProcessors = new IPreProcessTestruns[] { _preProcessor };
            var buildPreProcessor = MockRepository.GenerateMock<IPreProcessBuildruns>();
            buildPreProcessor.Stub(x => x.PreProcess(null)).IgnoreArguments().Return(new RunInfo[] { _runInfo });
            var buildPreProcessors = new IPreProcessBuildruns[] { buildPreProcessor };
            _removedTestLocator = MockRepository.GenerateMock<ILocateRemovedTests>();
            _consumer = new ProjectChangeConsumer(_bus, _listGenerator, _configuration, _buildRunner, new ITestRunner[] { _testRunner }, _testAssemblyValidator, _optimizer, preProcessors, _removedTestLocator, buildPreProcessors);
        }
Exemplo n.º 2
0
        public RunInfo Clone()
        {
            var runInfo = new RunInfo(Project);

            runInfo.SetAssembly(Assembly);
            BuildTemporaryProject(TemporaryBuildProject);
            if (ShouldBeBuilt)
            {
                runInfo.ShouldBuild();
            }
            if (IsChanged)
            {
                runInfo.Changed();
            }
            runInfo.AddTestsToRun(GetTests());
            runInfo.AddMembersToRun(GetMembers());
            runInfo.AddNamespacesToRun(GetNamespaces());
            foreach (var runner in _onlyRunTestsFor)
            {
                runInfo.ShouldOnlyRunSpcifiedTestsFor(runner);
            }
            foreach (var runner in _rerunAllWhenFinishedFor)
            {
                runInfo.ShouldRerunAllTestWhenFinishedFor(runner);
            }
            return(runInfo);
        }
		private RunInfo[] getRunInfos(AssemblyChangeMessage message)
        {
			var projects = _cache.GetAll<Project>();
            var runInfos = new List<RunInfo>();
            foreach (var file in message.Files)
            {
				var project = projects.Where(x => x.GetAssembly(_config.CustomOutputPath).Equals(file.FullName)).FirstOrDefault();
                var runInfo = new RunInfo(project);
                runInfo.SetAssembly(file.FullName);
                runInfos.Add(runInfo);
            }
            return runInfos.ToArray();
        }
		public void Should_run_cached_failed_and_ignored_tests_and_mark_for_rerun()
		{
			_resultCache.Stub(r => r.Failed).Return(new TestItem[] { new TestItem("assembly", "project", new TestResult(TestRunStatus.Failed, "sometests")) });
			_resultCache.Stub(r => r.Ignored).Return(new TestItem[] { new TestItem("assembly", "project", new TestResult(TestRunStatus.Ignored, "someignoredtests")) });
			var details = new RunInfo(new Project("project", new ProjectDocument(ProjectType.CSharp)));
			details.SetAssembly("assembly");
			
			_preProcessor.PreProcess(new RunInfo[] { details });
			details.TestsToRun.Length.ShouldEqual(2);
			details.TestsToRun[0].ShouldEqual("sometests");
			details.TestsToRun[1].ShouldEqual("someignoredtests");
			details.OnlyRunSpcifiedTests.ShouldBeTrue();
			details.RerunAllWhenFinished.ShouldBeTrue();
		}
Exemplo n.º 5
0
 public RunInfo Clone()
 {
     var runInfo = new RunInfo(Project);
     runInfo.SetAssembly(Assembly);
     BuildTemporaryProject(TemporaryBuildProject);
     if (ShouldBeBuilt)
         runInfo.ShouldBuild();
     if (IsChanged)
         runInfo.Changed();
     runInfo.AddTestsToRun(GetTests());
     runInfo.AddMembersToRun(GetMembers());
     runInfo.AddNamespacesToRun(GetNamespaces());
     foreach (var runner in _onlyRunTestsFor)
         runInfo.ShouldOnlyRunSpcifiedTestsFor(runner);
     foreach (var runner in _rerunAllWhenFinishedFor)
         runInfo.ShouldRerunAllTestWhenFinishedFor(runner);
     return runInfo;
 }
 private RunInfo getItem(string assemblyName)
 {
     var info = new RunInfo(null);
     info.SetAssembly(assemblyName);
     return info;
 }
Exemplo n.º 7
0
 private RunInfo getRunInfo(Project x)
 {
     var info = new RunInfo(x);
     info.SetAssembly(x.GetAssembly(_configuration.CustomOutputPath));
     return info;
 }
        public PreProcessedTesRuns PreProcess(PreProcessedTesRuns preProcessed)
        {
            // Clean up profiler logs before we start
            var logFiles = getProfilerOutput();
            cleanUpFiles(logFiles);

            var runMinimized = !(_isFullRun || minimizerIsDisabled() || _minimizerPaused);
            Logger.WriteDebug("Run minimized is " + runMinimized.ToString());
            if (runMinimized)
                _bus.Publish(new RunInformationMessage(InformationType.PreProcessing, "", "", typeof(MinimizingPreProcessor)));
            var finalDetails = new List<RunInfo>();
            var details = preProcessed.RunInfos;
            if (!minimizerGraphsAndRiskIsOff())
            {
                try
                {
                    var assemblies = GetAssemblies();
                    //var hash = details.ToDictionary(current => current.Assembly);
                    if (!runMinimized || _runCount % 10 == 0)
                        _minimizer.LoadOldCachedFiles(assemblies);
                    _runCount++;
                    var tests = _minimizer.GetTestsFor(assemblies);
                    Logger.WriteDebug("minimizer returns " + tests.Count + " tests");

                    if (runMinimized)
                    {
                        var profiled = GetProfiledEntries();
                        Logger.WriteDebug("profiler returns " + profiled.Count() + " tests");
                        var all = Combine(tests, profiled);

                        //TODO THIS IS A HACK TO ENRICH PROFILED TESTS, REFACTOR ME
                        foreach (var t in all)
                        {
                            var original = t.TestAssembly
                                .Replace(".mm.dll", ".dll")
                                .Replace(".mm.exe", ".exe");
                            var testAssembly = original;
                            testAssembly = new PathTranslator(_configuration.WatchToken).TranslateFrom(testAssembly);
                            if (testAssembly == null)
                                testAssembly = original;
                            Logger.WriteDebug("Translated TestAssembly is: " + testAssembly + " original is: " + t.TestAssembly);
                            var current = details.FirstOrDefault(x => x.Assembly.Equals(testAssembly));
                            if (current == null)
                            {
                                current = finalDetails.FirstOrDefault(x => x.Assembly.Equals(testAssembly));
                                if (current == null)
                                    current = GetRunInfoFromAssembly(testAssembly);
                                if (current == null)
                                    throw new Exception("unable to match assembly for test. - assembly is " + testAssembly);
                                if (!finalDetails.Exists(x => x.Assembly.Equals(testAssembly)))
                                    finalDetails.Add(current);
                            }

                            foreach (var s in t.TestRunners)
                            {
                                var runner = ConvertStringToTestRunnerEnum(s);
                                var test = getTestSignature(t, runner);
                                Logger.WriteDetails(string.Format("Adding test {0} to runner {1} on run info {2}", test,
                                                                  runner, current.Assembly));
                                current.AddTestsToRun(runner, test);
                            }
                        }

                        if (runMinimized)
                            addCurrentBrokenTests(details);

                        foreach (var detail in details)
                        {
                            detail.ShouldOnlyRunSpcifiedTestsFor(TestRunner.Any);
                        }
                        Logger.WritePreprocessor(string.Format("Found {0} affected tests", tests.Count));
                        _bus.Publish(new AssembliesMinimizedMessage());
                        finalDetails.AddRange(details);
                    }

                }
                catch (Exception ex)
                {
                    Logger.WriteError(ex.ToString());
                    var newDetails = new List<RunInfo>();
                    foreach (var detail in details)
                    {
                        var newDetail = new RunInfo(detail.Project);
                        newDetail.SetAssembly(detail.Assembly);
                        if (detail.ShouldBeBuilt)
                            newDetail.ShouldBuild();
                        newDetails.Add(newDetail);
                    }
                }

                Logger.WriteDebug("Running 2nd generation garbage collection");
                GC.Collect(2);
                Logger.WriteDebug("Waiting for finalizers");
                GC.WaitForPendingFinalizers();
                Logger.WriteDebug("GC done");
            }

            Logger.WriteDebug("Getting profiler wrapper");
            _profilerWrapper = getProfilerWrapper();
            if (!runMinimized)
            {
                var wrapper = _profilerWrapper;
                _profilerWrapper = null;
                Logger.WriteDebug("Returning original runinfos");
                return new PreProcessedTesRuns(wrapper, preProcessed.RunInfos); // return original runInfos
            }
            finalDetails.ForEach(x => _runsToProfile.Add(x.CloneToTestRunInfo()));
            Logger.WriteDebug("Returning modified details");
            return new PreProcessedTesRuns(_profilerWrapper, finalDetails.ToArray());
        }