public TestRunResults RunTests(Project project, string assemblyName) { var timer = Stopwatch.StartNew(); var unitTestExe = _configuration.NunitTestRunner(project.Value.Framework); if (!File.Exists(unitTestExe)) return new TestRunResults(project.Key, assemblyName, new TestResult[] {}); var arguments = getExecutableArguments(assemblyName); var proc = new Process(); proc.StartInfo = new ProcessStartInfo(unitTestExe, arguments); proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(assemblyName); proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.Start(); var parser = new NUnitTestResponseParser(_bus, project.Key, assemblyName); parser.Parse(proc.StandardOutput.ReadToEnd()); proc.WaitForExit(); timer.Stop(); var result = parser.Result; result.SetTimeSpent(timer.Elapsed); return result; }
public void Should_return_project_when_provided_with_one() { var project = new Project("somekey", null); _fakeCache.WhenGeting("somekey").Return(project); var returnedProject = _fakeCache.Get<Project>("somekey"); returnedProject.ShouldBeTheSameAs(project); }
public TestRunResults RunTests(Project project, string assemblyName) { var timer = Stopwatch.StartNew(); var unitTestExe = _configuration.XunitTestRunner(project.Value.Framework); if (!File.Exists(unitTestExe)) return new TestRunResults(project.Key, assemblyName, new TestResult[] { }); var resultFile = Path.GetTempFileName(); var arguments = string.Format("\"{0}\" /noshadow /nunit \"{1}\"", assemblyName, resultFile); var proc = new Process(); proc.StartInfo = new ProcessStartInfo(unitTestExe, arguments); proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(assemblyName); proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.Start(); // Make sure we empty buffer proc.StandardOutput.ReadToEnd(); proc.WaitForExit(); timer.Stop(); var parser = new NUnitTestResponseParser(_bus, project.Key, assemblyName); using (TextReader reader = new StreamReader(resultFile)) { parser.Parse(reader.ReadToEnd()); } File.Delete(resultFile); var result = parser.Result; result.SetTimeSpent(timer.Elapsed); return result; }
public void Should_return_null_when_parse_fails() { var record = new Project("someproject", null); _parser.ThrowExceptionOnParse(); var project = _preparer.Prepare(record); project.ShouldBeNull(); }
public BuildRunResults RunBuild(Project project, string buildExecutable) { var timer = Stopwatch.StartNew(); _buildExecutable = buildExecutable; var properties = buildProperties(project); var arguments = string.Format("\"{0}\"", project.Key) + properties; DebugLog.Debug.WriteMessage(string.Format("Running build: {0} {1}", _buildExecutable, arguments)); Process process = new Process(); process.StartInfo = new ProcessStartInfo(_buildExecutable, arguments); process.StartInfo.RedirectStandardOutput = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.Start(); string line; var buildResults = new BuildRunResults(project.Key); var lines = new List<string>(); while ((line = process.StandardOutput.ReadLine()) != null) lines.Add(line); process.WaitForExit(); timer.Stop(); var parser = new MSBuildOutputParser(buildResults, lines.ToArray()); parser.Parse(); buildResults.SetTimeSpent(timer.Elapsed); return buildResults; }
public TestRunResults RunTests(Project project, string assemblyName) { var timer = Stopwatch.StartNew(); var unitTestExe = _configuration.MSTestRunner(project.Value.Framework); if (!File.Exists(unitTestExe)) return new TestRunResults(project.Key, assemblyName, new TestResult[] { }); var proc = new Process(); proc.StartInfo = new ProcessStartInfo(unitTestExe, "/testcontainer:\"" + assemblyName + "\" /detail:errorstacktrace /detail:errormessage"); proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(assemblyName); proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.Start(); string line; var parser = new MSTestResponseParser(project.Key, assemblyName); while ((line = proc.StandardOutput.ReadLine()) != null) parser.ParseLine(line); proc.WaitForExit(); timer.Stop(); parser.Result.SetTimeSpent(timer.Elapsed); return parser.Result; }
public void Should_return_null_when_provided_with_wrong_key() { var project = new Project("somekey", null); _fakeCache.WhenGeting("somekey").Return(project); var returnedProject = _fakeCache.Get<Project>("another key"); returnedProject.ShouldNotBeTheSameAs(project); }
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); }
public void SetUp() { _cache = MockRepository.GenerateMock<ICache>(); _reloader = new ProjectReloader(_cache); _project = new Project("project", new ProjectDocument(ProjectType.CSharp)); _project.Value.AddReferencedBy("Referenced by"); _project.Value.HasBeenReadFromFile(); }
public void Should_prepare_project() { var record = new Project("someproject", null); _cache.WhenGeting("ReferencedProject") .Return(new Project("", new ProjectDocument(ProjectType.CSharp))); var project = _preparer.Prepare(record); project.Value.ShouldNotBeNull(); }
public void When_already_prepared_return_null() { var document = new ProjectDocument(ProjectType.CSharp); document.HasBeenReadFromFile(); var record = new Project("someproject", document); var project = _preparer.Prepare(record); project.ShouldBeTheSameAs(record); }
public TestRunInfo(Project project, string assembly) { Project = project; Assembly = assembly; _testsToRun = new List<string>(); OnlyRunSpcifiedTests = false; RerunAllWhenFinished = false; }
public TestRunInfo(Project project, string assembly) { Project = project; Assembly = assembly; _testsToRun = new List<TestToRun>(); _onlyRunTestsFor = new List<TestRunner>(); _rerunAllWhenFinishedFor = new List<TestRunner>(); }
private string getOutputDir(Project project) { var outputPath = string.Format("bin{0}AutoTest.Net{0}", Path.DirectorySeparatorChar); if (_configuration.CustomOutputPath != null && _configuration.CustomOutputPath.Length > 0) outputPath = _configuration.CustomOutputPath; if (outputPath.Substring(outputPath.Length - 1, 1) != Path.DirectorySeparatorChar.ToString()) outputPath += Path.DirectorySeparatorChar; return outputPath; }
public BuildRunResults RunBuild(Project project, string buildExecutable) { var properties = buildProperties(project); var arguments = string.Format("\"{0}\"", project.Key) + properties; if (project.Value.RequiresRebuild) arguments += " /target:rebuild"; var target = project.Key; return runBuild(buildExecutable, arguments, target); }
public RunInfo(Project project) { Project = project; ShouldBeBuilt = false; Assembly = null; _testsToRun = new List<string>(); OnlyRunSpcifiedTests = false; RerunAllWhenFinished = false; }
public RunInfo(Project project) { Project = project; ShouldBeBuilt = false; Assembly = null; _testsToRun = new List<TestToRun>(); _onlyRunTestsFor = new List<TestRunner>(); _rerunAllWhenFinishedFor = new List<TestRunner>(); }
public void Should_Add_ReferencedProjects() { _cache.WhenGeting("ReferencedProject") .Return(new Project("NonExisting", new ProjectDocument(ProjectType.CSharp))); var record = new Project(_testProject, null); var project = _preparer.Prepare(record); project.ShouldNotBeNull(); project.Value.References.Length.ShouldEqual(1); }
public void When_custom_output_path_use_custom_output_path() { var document = new ProjectDocument(ProjectType.CSharp); document.SetAssemblyName("mehassembly.dll"); document.SetOutputPath(string.Format("bin{0}Debug", Path.DirectorySeparatorChar)); var project = new Project(string.Format("C:{0}Project{0}Location{0}meh.csproj", Path.DirectorySeparatorChar), document); var assembly = project.GetAssembly(string.Format("bin{0}bleh{0}", Path.DirectorySeparatorChar)); assembly.ShouldEqual(string.Format(@"C:{0}Project{0}Location{0}bin{0}bleh{0}mehassembly.dll", Path.DirectorySeparatorChar)); }
public void When_custom_output_path_exists_use_only_custom_output_path() { var path = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); var document = new ProjectDocument(ProjectType.CSharp); document.SetAssemblyName("mehassembly.dll"); document.SetOutputPath(string.Format("bin{0}Debug", Path.DirectorySeparatorChar)); var project = new Project(string.Format("C:{0}Project{0}Location{0}meh.csproj", Path.DirectorySeparatorChar), document); var assembly = project.GetAssembly(path); assembly.ShouldEqual(string.Format(Path.Combine(path, "mehassembly.dll"), Path.DirectorySeparatorChar)); }
private List<RunInfo> getRunInfoList(Project[] projectList) { var runList = new List<RunInfo>(); foreach (var project in projectList) { if (project.Value != null) runList.Add(new RunInfo(project)); } return runList; }
public void Should_populate_referenced_by() { var record = new Project("someproject", null); var referencedProject = new ProjectDocument(ProjectType.CSharp); _cache.WhenGeting("ReferencedProject") .Return(new Project("", referencedProject)); var project = _preparer.Prepare(record); project.ShouldNotBeNull(); referencedProject.ReferencedBy[0].ShouldEqual("someproject"); }
private void setAssemblyDestinationsRecursive(List<RunInfo> runList, Project item, string assemblyPath) { var builtBy = runList.Where<RunInfo>(r => r.Project.Value.ReferencedBy.Contains(item.Key)); foreach (var project in builtBy) { if (project.Assembly != null) continue; project.SetAssembly(Path.Combine(assemblyPath, project.Project.Value.AssemblyName)); setAssemblyDestinationsRecursive(runList, project.Project, assemblyPath); } }
private string buildProperties(Project project) { var outputDir = getOutputDir(project); string overriddenPlatform = ""; // Only override platform for winodws. It's flawed on other platforms if (Environment.OSVersion.Platform != PlatformID.MacOSX && Environment.OSVersion.Platform != PlatformID.Unix) { if (project.Value.Platform == null || project.Value.Platform.Length.Equals(0)) overriddenPlatform = ",Platform=AnyCPU"; } return " /property:OutDir=" + outputDir + overriddenPlatform; }
public RunInfo(Project project) { Project = project; TemporaryBuildProject = null; ShouldBeBuilt = false; Assembly = null; _testsToRun = new List<TestToRun>(); _membersToRun = new List<TestToRun>(); _namespacesToRun = new List<TestToRun>(); _onlyRunTestsFor = new List<TestRunner>(); _rerunAllWhenFinishedFor = new List<TestRunner>(); }
public void Should_Add_ReferencedProjects() { var referenceWasAdded = false; var record = new Project("someproject", null); var action = new Action<Project>(x => { x.Key.ShouldEqual("ReferencedProject"); referenceWasAdded = true; }); var project = _preparer.Prepare(record, action); project.ShouldNotBeNull(); referenceWasAdded.ShouldBeTrue(); }
public void SetUp() { _project = new Project(Path.GetFullPath("someProject.csproj"), new ProjectDocument(ProjectType.CSharp)); _bus = MockRepository.GenerateMock<IMessageBus>(); _listGenerator = MockRepository.GenerateMock<IGenerateBuildList>(); _cache = MockRepository.GenerateMock<ICache>(); _configuration = MockRepository.GenerateMock<IConfiguration>(); _buildRunner = MockRepository.GenerateMock<IBuildRunner>(); _testRunner = MockRepository.GenerateMock<ITestRunner>(); _consumer = new ProjectChangeConsumer(_bus, _listGenerator, _cache, _configuration, _buildRunner, new ITestRunner[] { _testRunner }); _cache.Stub(c => c.Get<Project>(null)).IgnoreArguments().Return(_project); }
public void Should_add_projects_that_doesnt_exist() { var project = new Project("", new ProjectDocument(ProjectType.VisualBasic)); var cache = MockRepository.GenerateMock<ICache>(); var message = new FileChangeMessage(); message.AddFile(new ChangedFile(string.Format("TestResources{0}VS2008{0}NUnitTestProjectVisualBasic.vbproj", Path.DirectorySeparatorChar))); cache.Stub(c => c.Get<Project>(message.Files[0].FullName)).Return(null).Repeat.Once(); cache.Stub(c => c.Get<Project>(message.Files[0].FullName)).Return(project).Repeat.Once(); var marker = new ProjectRebuildMarker(cache); marker.HandleProjects(message); cache.AssertWasCalled(c => c.Add<Project>(message.Files[0].FullName)); }
private string buildProperties(Project project) { var outputDir = getOutputDir(project); string overriddenPlatform = ""; // Only override platform for winodws. It's flawed on other platforms // I don't think we need this anymore. Anyhow it's just lucky guesses anyhow //if (Environment.OSVersion.Platform != PlatformID.MacOSX && Environment.OSVersion.Platform != PlatformID.Unix) //{ // if (project.Value.Platform == null || project.Value.Platform.Length.Equals(0)) // overriddenPlatform = ",Platform=AnyCPU"; //} var imoutputDir = Path.Combine(outputDir, "_tmpIntermediateAT") + Path.DirectorySeparatorChar; return " /property:OutDir=" + outputDir + ";IntermediateOutputPath=" + imoutputDir + overriddenPlatform; }
public void Should_never_handle_realtime_tests() { var project = new Project("", new ProjectDocument(ProjectType.VisualBasic)); var cache = MockRepository.GenerateMock<ICache>(); var config = MockRepository.GenerateMock<IConfiguration>(); var file = new ChangedFile(string.Format("TestResources{0}VS2008{0}_rltm_build_fl_Bleh.csproj", Path.DirectorySeparatorChar)); cache.Stub(c => c.Get<Project>(file.FullName)).Return(null).Repeat.Once(); cache.Stub(c => c.Get<Project>(file.FullName)).Return(project).Repeat.Once(); var marker = new ProjectRebuildMarker(cache, config); marker.HandleProjects(file); cache.AssertWasNotCalled(c => c.Add<Project>(file.FullName)); }