public RunInfo[] PreProcess(RunInfo[] details)
 {
     var switcher = new MSTestSwitcharoo(Environment.OSVersion.Platform,
                                         Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
     details
         .Where(x => x.Project != null).ToList()
         .ForEach(x =>
                      {
                          if (File.Exists(x.TemporaryBuildProject))
                          {
                              var project = File.ReadAllText(x.TemporaryBuildProject);
                              if (switcher.IsGuyInCloset(project))
                                  File.WriteAllText(x.TemporaryBuildProject, switcher.PerformSwitch(project));
                          }
                          else
                          {
                              var project = File.ReadAllText(x.Project.Key);
                             if (switcher.IsGuyInCloset(project))
                             {
                                 var tmpProject = getTempProject(x.Project.Key);
                                 // We can do this because we know they are ordered in the right order
                                 _tmpProjects.ForEach(y => 
                                     project = project
                                         .Replace("\\" + Path.GetFileName(getOriginalProject(y)), "\\" + Path.GetFileName(y))
                                         .Replace("\"" + Path.GetFileName(getOriginalProject(y)), "\"" + Path.GetFileName(y)));
                                 File.WriteAllText(tmpProject, switcher.PerformSwitch(project));
                                 _tmpProjects.Add(tmpProject);
                                 x.BuildTemporaryProject(tmpProject);
                             }
                          }
                      });
     return details;
 }
Esempio 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);
        }
        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);
        }
Esempio n. 4
0
        private void addIfNew(RunInfo x, TestToRun t, Func <RunInfo, List <TestToRun> > getItems, Action <RunInfo, TestToRun> addItem)
        {
            var current = _list.Where(y => y.Assembly.Equals(x.Assembly)).First();

            if (!testExists(t, getItems, current))
            {
                addItem(current, t);
            }
        }
Esempio n. 5
0
        private void addIfNew(RunInfo x, TestToRun t, Func <RunInfo, List <TestToRun> > getItems, Action <RunInfo, TestToRun> addItem, Func <RunInfo, RunInfo, bool> match)
        {
            var current = _list.Where(y => match(y, x)).First();

            if (!testExists(t, getItems, current))
            {
                addItem(current, t);
            }
        }
 private bool hasInvalidAssembly(RunInfo info)
 {
     if (info.Assembly == null)
     {
         _bus.Publish(new ErrorMessage(string.Format("Assembly was unexpectedly set to null for {0}. Skipping assembly", info.Project.Key)));
         return(true);
     }
     return(false);
 }
		private TestToRun[] getTestsFor(RunInfo info, TestItem[] cachedTests)
		{
			var tests = new List<TestToRun>();
			foreach (var failed in cachedTests)
			{
				if (failed.Key.Equals(info.Assembly))
					tests.Add(new TestToRun(TestRunner.Any, failed.Value.Name));
			}
			return tests.ToArray();
		}
		private string[] getTestsFor(RunInfo info, TestItem[] cachedTests)
		{
			var tests = new List<string>();
			foreach (var failed in cachedTests)
			{
				if (failed.Key.Equals(info.Assembly))
					tests.Add(failed.Value.Name);
			}
			return tests.ToArray();
		}
		public void PreProcess (RunInfo[] details)
		{
			foreach (var info in details)
			{
				info.AddTestsToRun(getTestsFor(info, _resultCache.Failed));
				info.AddTestsToRun(getTestsFor(info, _resultCache.Ignored));
				info.ShouldOnlyRunSpcifiedTests();
				info.RerunAllTestWhenFinished();
			}
		}
        public RunInfo[] PreProcess(RunInfo[] details)
		{
			foreach (var info in details)
			{
				info.AddTestsToRun(TestRunner.Any, getTestsFor(info, _resultCache.Failed));
                info.AddTestsToRun(TestRunner.Any, getTestsFor(info, _resultCache.Ignored));
				info.ShouldOnlyRunSpcifiedTestsFor(TestRunner.Any);
                info.ShouldRerunAllTestWhenFinishedFor(TestRunner.Any);
			}
            return details;
		}
 public RunInfo[] PostProcess(RunInfo[] details, ref RunReport runReport)
 {
     _tmpProjects
         .ForEach(x =>
                      {
                          if (File.Exists(x))
                              File.Delete(x);
                      });
     _tmpProjects.Clear();
     return details;
 }
 private BuildRunResults buildProjects(string[] changedProjects, RunInfo[] projectList, RunReport runReport)
 {
     if (_buildConfig.OptimisticBuildStrategy != null)
     {
         try {
             return optimisticBuild(changedProjects, projectList, runReport);
         } catch (Exception ex) {
             Debug.WriteException(ex);
         }
     }
     return buildProjects(projectList, runReport);
 }
Esempio n. 13
0
		private void markReferencedShouldBuildProjectsForRebuild(RunInfo info, List<RunInfo> runList)
		{
			foreach (var reference in info.Project.Value.ReferencedBy)
			{
				var item = runList.Single(x => x.Project.Key.Equals(reference));
				if (item.ShouldBeBuilt)
				{
					item.Project.Value.RebuildOnNextRun();
					continue;
				}
				markReferencedShouldBuildProjectsForRebuild(item, runList);
			}
		}
		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();
        }
Esempio n. 15
0
        public BuildRunResults RunBuild(RunInfo runInfo, string buildExecutable, Func<bool> abortIfTrue)
        {
            var project = runInfo.Project;
			var properties = buildProperties(project);
            var projectPath = project.Key;
            if (runInfo.TemporaryBuildProject != null)
                projectPath = runInfo.TemporaryBuildProject;
            var arguments = string.Format("\"{0}\"", projectPath) + properties;
			if (project.Value.RequiresRebuild)
				arguments += " /target:rebuild";
            var target = projectPath;
            return runBuild(buildExecutable, arguments, target, abortIfTrue);
        }
		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();
		}
Esempio n. 17
0
        private BuildRunResults build(RunInfo info, RunReport runReport)
        {
            if (File.Exists(_configuration.BuildExecutable(info.Project.Value)))
            {
                _bus.Publish(new RunInformationMessage(
                                 InformationType.Build,
                                 info.Project.Key,
                                 info.Assembly,
                                 typeof(MSBuildRunner)));
                return(buildProject(info, runReport));
            }

            return(null);
        }
Esempio n. 18
0
        public BuildRunResults RunBuild(RunInfo runInfo, string buildExecutable, Func<bool> abortIfTrue)
        {
            var project = runInfo.Project;
			var properties = buildProperties(project);
            var projectPath = project.Key;
            if (runInfo.TemporaryBuildProject != null)
                projectPath = runInfo.TemporaryBuildProject;
            var arguments = string.Format("\"{0}\"", projectPath) + properties;
			if (project.Value.RequiresRebuild)
				arguments += " /target:rebuild";
            if (File.Exists(_configuration.SolutionToBuild))
                arguments += " /property:SolutionDir=\"" + Path.GetDirectoryName(_configuration.SolutionToBuild) + "\"";
            var target = projectPath;
            return runBuild(buildExecutable, arguments, target, abortIfTrue);
        }
        public bool Build(string[] originalProjects, RunInfo[] projectList, RunReport runReport, Func<bool> exit)
        {
            _exit = exit;
            projectList = preProcessBuildRun(projectList);
            if (projectList.Where(x => x.ShouldBeBuilt).Select(x => x).Count() == 0)
                return true;

            Debug.WriteInfo("Running builds");
            BuildRunResults results = null;
            if (_configuration.ShouldBuildSolution)
                results = buildSolution(projectList, runReport);
            else
                results = buildProjects(originalProjects, projectList, runReport);
            postProcessBuildRuns(projectList, ref runReport);
            return results == null;
        }
        private bool build(RunInfo info, RunReport runReport)
        {
            if (File.Exists(_configuration.BuildExecutable(info.Project.Value)))
            {
                _bus.Publish(new RunInformationMessage(
                                 InformationType.Build,
                                 info.Project.Key,
                                 info.Assembly,
                                 typeof(MSBuildRunner)));
                if (!buildProject(info.Project, runReport))
                {
                    return(false);
                }
            }

            return(true);
        }
        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>();
			var runInfo = new RunInfo(_project);
			runInfo.ShouldBuild();
			_optimizer.Stub(o => o.AssembleBuildConfiguration(null)).IgnoreArguments().Return(new RunInfo[] { runInfo });
            _consumer = new ProjectChangeConsumer(_bus, _listGenerator, _configuration, _buildRunner, new ITestRunner[] { _testRunner }, _testAssemblyValidator, _optimizer);
        }
Esempio n. 22
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;
 }
Esempio n. 23
0
 private void markReferencedShouldBuildProjectsForRebuild(RunInfo info, List <RunInfo> runList)
 {
     foreach (var reference in info.Project.Value.ReferencedBy)
     {
         var item = runList.Where(x => x.Project.Key.Equals(reference)).FirstOrDefault();
         if (item == null)
         {
             DebugLog.Debug.WriteDebug("Could not find project for reference " + reference);
             continue;
         }
         if (item.ShouldBeBuilt)
         {
             item.Project.Value.RebuildOnNextRun();
             continue;
         }
         markReferencedShouldBuildProjectsForRebuild(item, runList);
     }
 }
Esempio n. 24
0
        private BuildRunResults buildProject(RunInfo info, RunReport report)
        {
            var project     = info.Project;
            var buildReport = _buildRunner.RunBuild(info, _configuration.BuildExecutable(project.Value), () => { return(_exit); });

            buildReport = postProcessBuildReports(buildReport);
            var succeeded = buildReport.ErrorCount == 0;

            report.AddBuild(buildReport.Project, buildReport.TimeSpent, succeeded);
            _bus.Publish(new BuildRunMessage(buildReport));
            if (succeeded)
            {
                return(null);
            }
            else
            {
                return(buildReport);
            }
        }
 public RunInfo[] PreProcess(RunInfo[] details)
 {
     if (_isActive && _files != null)
     {
         _configuration.OverrideSolution(_files.Solution.Tempfile);
         details
             .Where(x => x.Project != null).ToList()
             .ForEach(x =>
                 {
                     Logger.WriteDebug("Checking for temp projects for " + x.Project.Key);
                     var temp = _files.Files.FirstOrDefault(y => y.Original.Equals(x.Project.Key));
                     if (temp != null)
                     {
                         Logger.WriteDebug("\tFound " + temp.Tempfile);
                         x.BuildTemporaryProject(temp.Tempfile);
                     }
                 });
     }
     return details;
 }
 private static bool testExists(TestToRun t, Func<RunInfo, List<TestToRun>> getItems, RunInfo current)
 {
     return getItems(current).Exists(test => compareTests(t, test));
 }
 private bool exists(RunInfo x, Func<RunInfo, RunInfo, bool> match)
 {
     return _list.Exists(y => match(y, x));
 }
 private RunInfo[] preProcessBuildRun(RunInfo[] runInfos)
 {
     foreach (var preProcessor in _preBuildProcessors)
         runInfos = preProcessor.PreProcess(runInfos);
     return runInfos;
 }
 private RunInfo[] postProcessBuildRuns(RunInfo[] runInfos, ref RunReport runReport)
 {
     foreach (var preProcessor in _preBuildProcessors)
         runInfos = preProcessor.PostProcess(runInfos, ref runReport);
     return runInfos;
 }
 public void SetUp()
 {
     _info = new RunInfo(new Project("", new ProjectDocument(ProjectType.CSharp)));
 }
Esempio n. 31
0
 private RunInfo getRunInfo(Project x)
 {
     var info = new RunInfo(x);
     info.SetAssembly(x.GetAssembly(_configuration.CustomOutputPath));
     return info;
 }
Esempio n. 32
0
 private bool exists(RunInfo x, Func <RunInfo, RunInfo, bool> match)
 {
     return(_list.Exists(y => match(y, x)));
 }
Esempio n. 33
0
 private static bool testExists(TestToRun t, Func <RunInfo, List <TestToRun> > getItems, RunInfo current)
 {
     return(getItems(current).Exists(test => compareTests(t, test)));
 }
 private void addIfNew(RunInfo x, TestToRun t, Func<RunInfo, List<TestToRun>> getItems, Action<RunInfo, TestToRun> addItem, Func<RunInfo, RunInfo, bool> match)
 {
     var current = _list.Where(y => match(y, x)).First();
     if (!testExists(t, getItems, current))
         addItem(current, t);
 }
 private bool hasInvalidOutputPath(RunInfo info)
 {
     return(info.Assembly == null);
 }
Esempio n. 36
0
		private void markReferencedShouldBuildProjectsForRebuild(RunInfo info, List<RunInfo> runList)
		{
			foreach (var reference in info.Project.Value.ReferencedBy)
			{
				var item = runList.Where(x => x.Project.Key.Equals(reference)).FirstOrDefault();
                if (item == null)
                {
                    DebugLog.Debug.WriteDebug("Could not find project for reference " + reference);
                    continue;
                }
				if (item.ShouldBeBuilt)
				{
					item.Project.Value.RebuildOnNextRun();
					continue;
				}
				markReferencedShouldBuildProjectsForRebuild(item, runList);
			}
		}
Esempio n. 37
0
 private bool exists(RunInfo x)
 {
     return(_list.Exists(y => y.Assembly.Equals(x.Assembly)));
 }
Esempio n. 38
0
 private bool doesNotExist(RunInfo x)
 {
     return !_list.Exists(y => y.Project.Key.Equals(x.Project.Key));
 }
 private BuildRunResults optimisticBuild(string[] changedProjects, RunInfo[] projectList, RunReport runReport)
 {
     var projectWithIssues = new List<string>();
     projectWithIssues.AddRange(_runCache
         .Errors
         .GroupBy(x => x.Key)
         .Select(x => x.Key));
     var builtProjects = new List<RunInfo>();
     var indirectlyBuilt = new List<string>();
     foreach (var file in projectList)
     {
         if (changedProjects.Contains(file.Project.Key) || projectWithIssues.Contains(file.Project.Key))
         {
             Debug.WriteDebug("Optimistic build for project {0}", file.Project.Key);
             var original = file.Assembly + ".original" + Path.GetExtension(file.Assembly);
             _fs.CopyFile(file.Assembly, original);
             var report = build(file, runReport);
             var optimisticAdviced = _buildConfig.OptimisticBuildStrategy(file.Assembly, original);
             _fs.DeleteFile(original);
             if (!optimisticAdviced)
                 throw new Exception("Optimistic build is not adviced for this scenario");
             if (report != null)
                 return report;
             builtProjects.Add(file);
         }
         else
         {
             Debug.WriteDebug("Not set to optimisticly build project {0}", file.Project.Key);
             indirectlyBuilt.Add(file.Project.Key);
         }
     }
     builtProjects.ForEach(x => copyAssembly(x.Project.Key, x.Assembly));
     foreach (var project in indirectlyBuilt)
         runReport.AddBuild(project, new TimeSpan(0), true);
     return null;
 }
 RunInfo[] IPreProcessBuildruns.PreProcess(RunInfo[] details)
 {
     if (!_isActive)
         return details;
     foreach (var detail in details)
         detail.ShouldNotBuild();
     return details;
 }
 private RunInfo getItem(string assemblyName)
 {
     var info = new RunInfo(null);
     info.SetAssembly(assemblyName);
     return info;
 }
Esempio n. 42
0
 private bool doesNotExist(RunInfo x)
 {
     return(!_list.Exists(y => y.Project.Key.Equals(x.Project.Key)));
 }
 RunInfo[] IPreProcessBuildruns.PostProcess(RunInfo[] details, ref RunReport runReport)
 {
     return details;
 }
 private BuildRunResults buildProject(RunInfo info, RunReport report)
 {
     var project = info.Project;
     var buildReport = _buildRunner.RunBuild(info, _configuration.BuildExecutable(project.Value), () => { return _exit(); });
     buildReport = postProcessBuildReports(buildReport);
     var succeeded = buildReport.ErrorCount == 0;
     report.AddBuild(buildReport.Project, buildReport.TimeSpent, succeeded);
     _bus.Publish(new BuildRunMessage(buildReport));
     if (succeeded)
         return null;
     else
         return buildReport;
 }