Permalink
Browse files

Extracting invocation of IAssemblyContext into an ISpecificationRunLi…

…stener
  • Loading branch information...
1 parent b5a5189 commit f391316a421101481e61eccc0a665cb37721787a @agross agross committed Jan 31, 2013
@@ -1,55 +0,0 @@
-using System;
-using System.IO;
-using Machine.Specifications.Runner;
-
-namespace Machine.Specifications.ConsoleRunner
-{
- /// <summary>
- /// Sets the current directory to the directory containing running assembly,
- /// thus allowing external files to be referenced by relative path within
- /// specifications in the assembly.
- /// </summary>
- public class AssemblyLocationAwareListener : ISpecificationRunListener
- {
- string originalDirectory;
-
- public void OnAssemblyStart(AssemblyInfo assembly)
- {
- this.originalDirectory = Environment.CurrentDirectory;
- Environment.CurrentDirectory = Path.GetDirectoryName(assembly.Location);
- }
-
- public void OnAssemblyEnd(AssemblyInfo assembly)
- {
- Environment.CurrentDirectory = this.originalDirectory;
- }
-
- public void OnRunStart()
- {
- }
-
- public void OnRunEnd()
- {
- }
-
- public void OnContextStart(ContextInfo context)
- {
- }
-
- public void OnContextEnd(ContextInfo context)
- {
- }
-
- public void OnSpecificationStart(SpecificationInfo specification)
- {
- }
-
- public void OnSpecificationEnd(SpecificationInfo specification, Result result)
- {
- }
-
- public void OnFatalError(ExceptionResult exception)
- {
- }
- }
-}
@@ -72,7 +72,6 @@
<Compile Include="..\VersionInfo.cs">
<Link>Properties\VersionInfo.cs</Link>
</Compile>
- <Compile Include="AssemblyLocationAwareListener.cs" />
<Compile Include="DefaultConsole.cs" />
<Compile Include="ExceptionReporter.cs" />
<Compile Include="ExitCode.cs" />
@@ -45,22 +45,22 @@ public ExitCode Run(string[] arguments)
return ExitCode.Failure;
}
- List<ISpecificationRunListener> listeners = new List<ISpecificationRunListener>();
-
- var timingListener = new TimingRunListener();
- listeners.Add(timingListener);
- listeners.Add(new AssemblyLocationAwareListener());
+ var timer = new TimingRunListener();
+ var listeners = new List<ISpecificationRunListener>
+ {
+ timer
+ };
ISpecificationRunListener mainListener;
if (options.TeamCityIntegration ||
(!options.DisableTeamCityAutodetection &&
Environment.GetEnvironmentVariable("TEAMCITY_PROJECT_NAME") != null))
{
- mainListener = new TeamCityReporter(_console.WriteLine, timingListener);
+ mainListener = new TeamCityReporter(_console.WriteLine, timer);
}
else
{
- mainListener = new RunListener(_console, DetermineOutput(options, _console), timingListener);
+ mainListener = new RunListener(_console, DetermineOutput(options, _console), timer);
}
try
@@ -74,7 +74,7 @@ public ExitCode Run(string[] arguments)
}
else
{
- _console.WriteLine("Invalid html path:" + options.HtmlPath);
+ _console.WriteLine("Invalid html path: {0}", options.HtmlPath);
_console.WriteLine(Options.Usage());
return ExitCode.Failure;
}
@@ -85,11 +85,11 @@ public ExitCode Run(string[] arguments)
{
if (IsHtmlPathValid(options.XmlPath))
{
- listeners.Add(GetXmlReportListener(options, timingListener));
+ listeners.Add(GetXmlReportListener(options, timer));
}
else
{
- _console.WriteLine("Invalid xml path:" + options.XmlPath);
+ _console.WriteLine("Invalid xml path: {0}", options.XmlPath);
_console.WriteLine(Options.Usage());
return ExitCode.Failure;
}
@@ -2,7 +2,7 @@
using Machine.Specifications.ConsoleRunner.Outputs;
using Machine.Specifications.Runner;
-using Machine.Specifications.Runner.Impl;
+using Machine.Specifications.Runner.Impl.Listener;
namespace Machine.Specifications.ConsoleRunner
{
@@ -1,4 +1,4 @@
-using Machine.Specifications.Runner.Impl;
+using Machine.Specifications.Runner;
namespace Machine.Specifications.Reporting.Generation.Xml
{
@@ -6,7 +6,6 @@
using System.Xml;
using Machine.Specifications.Runner;
-using Machine.Specifications.Runner.Impl;
namespace Machine.Specifications.Reporting.Generation.Xml
{
@@ -216,11 +215,11 @@ static void RenderError(XmlWriter reportBuilder, ExceptionResult exception)
}
reportBuilder.WriteStartElement("error");
-
+
reportBuilder.WriteStartElement("message");
reportBuilder.WriteCData(exception.Message);
reportBuilder.WriteEndElement();
-
+
reportBuilder.WriteStartElement("stack-trace");
reportBuilder.WriteCData(exception.StackTrace);
reportBuilder.WriteEndElement();
@@ -1,7 +1,6 @@
using System;
using Machine.Specifications.Runner;
-using Machine.Specifications.Runner.Impl;
namespace Machine.Specifications.Reporting.Integration
{
@@ -90,15 +90,18 @@
<Compile Include="Model\BehaviorSpecification.cs" />
<Compile Include="ComparerStrategies\NoResult.cs" />
<Compile Include="ComparerStrategies\ObjectExtension.cs" />
+ <Compile Include="Runner\AggregateRunListener.cs" />
+ <Compile Include="Runner\Impl\Listener\AssemblyContextRunListener.cs" />
<Compile Include="Runner\Impl\AssemblyRunner.cs" />
<Compile Include="Runner\Impl\ContextRunnerFactory.cs" />
- <Compile Include="Runner\Impl\RunListenerBase.cs" />
<Compile Include="Runner\Impl\ContextRunner.cs" />
+ <Compile Include="Runner\Impl\Listener\AssemblyLocationAwareListener.cs" />
<Compile Include="Runner\Impl\SpecAssemblyResolver.cs" />
<Compile Include="Runner\Impl\SpecificationRunner.cs" />
- <Compile Include="Runner\Impl\TimingRunListener.cs" />
<Compile Include="Model\Tag.cs" />
+ <Compile Include="Runner\RunListenerBase.cs" />
<Compile Include="Runner\RunOptions.cs" />
+ <Compile Include="Runner\TimingRunListener.cs" />
<Compile Include="SetupForEachSpecification.cs" />
<Compile Include="SubjectAttribute.cs" />
<Compile Include="Explorers\AssemblyExplorer.cs" />
@@ -111,14 +114,13 @@
<Compile Include="Result.cs" />
<Compile Include="Model\Context.cs" />
<Compile Include="Model\VerificationContext.cs" />
- <Compile Include="Runner\Impl\AggregateRunListener.cs" />
<Compile Include="Runner\Impl\AppDomainRunner.cs" />
<Compile Include="Runner\AssemblyInfo.cs" />
<Compile Include="Runner\ContextInfo.cs" />
<Compile Include="Runner\Impl\InfoExtensions.cs" />
<Compile Include="Runner\ISpecificationRunListener.cs" />
<Compile Include="Runner\ISpecificationRunner.cs" />
- <Compile Include="Runner\Impl\RemoteRunListener.cs" />
+ <Compile Include="Runner\Impl\Listener\RemoteRunListener.cs" />
<Compile Include="Runner\SpecificationInfo.cs" />
<Compile Include="Runner\Impl\DefaultRunner.cs" />
<Compile Include="TagsAttribute.cs" />
@@ -0,0 +1,62 @@
+using System.Collections.Generic;
+using System.Linq;
+
+using Machine.Specifications.Utility;
+
+namespace Machine.Specifications.Runner
+{
+ public class AggregateRunListener : ISpecificationRunListener
+ {
+ readonly IList<ISpecificationRunListener> _listeners;
+
+ public AggregateRunListener(IEnumerable<ISpecificationRunListener> listeners)
+ {
+ _listeners = new List<ISpecificationRunListener>(listeners);
+ }
+
+ public void OnAssemblyStart(AssemblyInfo assembly)
+ {
+ _listeners.Each(listener => listener.OnAssemblyStart(assembly));
+ }
+
+ public void OnAssemblyEnd(AssemblyInfo assembly)
+ {
+ _listeners.Reverse().Each(listener => listener.OnAssemblyEnd(assembly));
+ }
+
+ public void OnRunStart()
+ {
+ _listeners.Each(listener => listener.OnRunStart());
+ }
+
+ public void OnRunEnd()
+ {
+ _listeners.Reverse().Each(listener => listener.OnRunEnd());
+ }
+
+ public void OnContextStart(ContextInfo context)
+ {
+ _listeners.Each(listener => listener.OnContextStart(context));
+ }
+
+ public void OnContextEnd(ContextInfo context)
+ {
+ _listeners.Reverse().Each(listener => listener.OnContextEnd(context));
+ }
+
+ public void OnSpecificationStart(SpecificationInfo specification)
+ {
+ _listeners.Each(listener => listener.OnSpecificationStart(specification));
+ }
+
+ public void OnSpecificationEnd(SpecificationInfo specification, Result result)
+ {
+ _listeners.Reverse().Each(listener => listener.OnSpecificationEnd(specification, result));
+ }
+
+ public void OnFatalError(ExceptionResult exception)
+ {
+ _listeners.Each(listener => listener.OnFatalError(exception));
+ }
+ }
+}
@@ -1,62 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Machine.Specifications.Runner.Impl
-{
- public class AggregateRunListener : ISpecificationRunListener
- {
- readonly List<ISpecificationRunListener> _listeners;
-
- public AggregateRunListener(IEnumerable<ISpecificationRunListener> listeners)
- {
- _listeners = new List<ISpecificationRunListener>(listeners);
- }
-
- public void OnAssemblyStart(AssemblyInfo assembly)
- {
- _listeners.ForEach(listener => listener.OnAssemblyStart(assembly));
- }
-
- public void OnAssemblyEnd(AssemblyInfo assembly)
- {
- _listeners.ForEach(listener => listener.OnAssemblyEnd(assembly));
- }
-
- public void OnRunStart()
- {
- _listeners.ForEach(listener => listener.OnRunStart());
- }
-
- public void OnRunEnd()
- {
- _listeners.ForEach(listener => listener.OnRunEnd());
- }
-
- public void OnContextStart(ContextInfo context)
- {
- _listeners.ForEach(listener => listener.OnContextStart(context));
- }
-
- public void OnContextEnd(ContextInfo context)
- {
- _listeners.ForEach(listener => listener.OnContextEnd(context));
- }
-
- public void OnSpecificationStart(SpecificationInfo specification)
- {
- _listeners.ForEach(listener => listener.OnSpecificationStart(specification));
- }
-
- public void OnSpecificationEnd(SpecificationInfo specification, Result result)
- {
- _listeners.ForEach(listener => listener.OnSpecificationEnd(specification, result));
- }
-
- public void OnFatalError(ExceptionResult exception)
- {
- _listeners.ForEach(listener => listener.OnFatalError(exception));
- }
- }
-}
@@ -3,6 +3,8 @@
using System.IO;
using System.Reflection;
using System.Security;
+
+using Machine.Specifications.Runner.Impl.Listener;
using Machine.Specifications.Utility;
namespace Machine.Specifications.Runner.Impl
@@ -196,4 +198,4 @@ public override object InitializeLifetimeService()
}
}
}
-}
+}
Oops, something went wrong.

0 comments on commit f391316

Please sign in to comment.