public void TryRun(string targetName, ScriptFileInfo fixtureProject) { if (fixtureProject.Targets.Contains(targetName)) { fixtureProject.Targets[targetName].Execute(); } }
public string GetCurrentDirectory() { ScriptFileInfo ScriptInfo = null; try { ScriptInfo = this.Project.ScriptFileInfoList.Where(script => script.FilePath == this.Location.FileName).Single <ScriptFileInfo>(); } catch (Exception ex) { throw new BuildException("Could not find current script name.", this.Location, ex); } return(Path.GetDirectoryName(ScriptInfo.FilePath)); }
public string GetCurrentName() { ScriptFileInfo ScriptInfo = null; try { ScriptInfo = this.Project.ScriptFileInfoList.Where(script => script.FilePath == this.Location.FileName).Single <ScriptFileInfo>(); } catch (Exception ex) { throw new BuildException("Could not find current script name.", this.Location, ex); } return(StringUtils.ConvertNullToEmpty(ScriptInfo.ProjectName)); }
public string GetName(string scriptFilePath) { ScriptFileInfo ScriptInfo = null; try { ScriptInfo = this.Project.ScriptFileInfoList.Where(script => script.FilePath == scriptFilePath).Single <ScriptFileInfo>(); } catch (Exception ex) { throw new BuildException(String.Format("Could not find script {0}.", scriptFilePath), ex); } return(StringUtils.ConvertNullToEmpty(ScriptInfo.ProjectName)); }
protected override void ExecuteTask() { int TestCount = 0; int TestPassingCount = 0; StringBuilder FailingTestInfo = new StringBuilder(); ReportContainer Report = new ReportContainer(); foreach (String Fixture in Fixtures) { if (!this.Project.ScriptFileInfoList.Contains(Fixture)) { throw new BuildException(string.Format("There is no fixture loaded for {0}.", Fixture), this.Location); } ScriptFileInfo FixtureProject = this.Project.ScriptFileInfoList[Fixture]; FixtureReport fixtureReport = new FixtureReport(Fixture); Report.FixtureReports.Add(fixtureReport); try { this.TryRun(string.Format("{0}.{1}", FixtureProject.ProjectName, FixtureSetUp), FixtureProject); foreach (Target FixtureTarget in FixtureProject.Targets) { if (FixtureTarget.Name.EndsWith("Test")) { TestReport testReport = new TestReport(FixtureTarget.Name); fixtureReport.TestReports.Add(testReport); try { TestCount++; this.TryRun(string.Format("{0}.{1}", FixtureProject.ProjectName, SetUpName), FixtureProject); FixtureTarget.Execute(); TestPassingCount++; testReport.Passed = true; } catch (BuildException bx) { string FailureInfo = string.Format("{0} at:{1}{2}{3}{4}", bx.Message, Environment.NewLine, bx.Location.ToString(), Environment.NewLine, bx.ToString()); Log(Level.Error, FailureInfo); FailingTestInfo.AppendLine(FailureInfo); testReport.Passed = false; testReport.FailureException = bx.ToString(); } catch (Exception ex) { string FailureInfo = string.Format("{0} in {1}{2}{3}", ex.Message, FixtureTarget.Name, Environment.NewLine, ex.ToString()); Log(Level.Error, FailureInfo); FailingTestInfo.AppendLine(FailureInfo); testReport.Passed = false; testReport.FailureException = ex.ToString(); } finally { this.TryRun(string.Format("{0}.{1}", FixtureProject.ProjectName, TearDownName), FixtureProject); } } } } finally { this.TryRun(string.Format("{0}.{1}", FixtureProject.ProjectName, FixtureTearDown), FixtureProject); } } int TestFailingCount = TestCount - TestPassingCount; Log(Level.Info, "Tests Run: {0}", TestCount); Log(Level.Info, "Tests Passing: {0}", TestPassingCount); Log(Level.Info, "Tests Failing: {0}", TestFailingCount); Log(Level.Info, "Test Assertions Executed: {0}", MbUnit.Framework.Assert.AssertCount); Console.WriteLine(FailingTestInfo.ToString()); if (File.Exists(FilePath)) { File.Delete(FilePath); } XmlSerializer Serializer = new XmlSerializer(typeof(ReportContainer)); using (FileStream ReportStream = File.OpenWrite(FilePath)) { Serializer.Serialize(ReportStream, Report); } if (TestFailingCount > 0) { throw new BuildException(string.Format("{0} tests failed.", TestFailingCount)); } }