diff --git a/src/TestStack.BDDfy/Reporters/FileHelpers.cs b/src/TestStack.BDDfy/Reporters/FileHelpers.cs new file mode 100644 index 0000000..58c5525 --- /dev/null +++ b/src/TestStack.BDDfy/Reporters/FileHelpers.cs @@ -0,0 +1,23 @@ +using System; +using System.IO; + +namespace TestStack.BDDfy.Reporters +{ + public class FileHelpers + { + // http://stackoverflow.com/questions/52797/c-how-do-i-get-the-path-of-the-assembly-the-code-is-in#answer-283917 + internal static string AssemblyDirectory() + { +#if NET40 + string codeBase = typeof(Engine).Assembly().CodeBase; + var uri = new UriBuilder(codeBase); + string path = Uri.UnescapeDataString(uri.Path); + return Path.GetDirectoryName(path); +#else + var basePath = AppContext.BaseDirectory; + return Path.GetFullPath(basePath); +#endif + } + + } +} diff --git a/src/TestStack.BDDfy/Reporters/Html/DefaultHtmlReportConfiguration.cs b/src/TestStack.BDDfy/Reporters/Html/DefaultHtmlReportConfiguration.cs index 8a4a940..1bb87d8 100644 --- a/src/TestStack.BDDfy/Reporters/Html/DefaultHtmlReportConfiguration.cs +++ b/src/TestStack.BDDfy/Reporters/Html/DefaultHtmlReportConfiguration.cs @@ -20,7 +20,7 @@ public virtual string ReportDescription set { _reportDescription = value; } } - private string _outputPath = AssemblyDirectory; + private string _outputPath = FileHelpers.AssemblyDirectory(); public virtual string OutputPath { get { return _outputPath; } @@ -45,17 +45,5 @@ public virtual bool RunsOn(Story story) { return true; } - - // http://stackoverflow.com/questions/52797/c-how-do-i-get-the-path-of-the-assembly-the-code-is-in#answer-283917 - private static string AssemblyDirectory - { - get - { - var codeBase = typeof(DefaultHtmlReportConfiguration).Assembly().CodeBase; - var uri = new UriBuilder(codeBase); - var path = Uri.UnescapeDataString(uri.Path); - return Path.GetDirectoryName(path); - } - } } } \ No newline at end of file diff --git a/src/TestStack.BDDfy/Reporters/Writers/FileWriter.cs b/src/TestStack.BDDfy/Reporters/Writers/FileWriter.cs index ff6c1e0..0919e33 100644 --- a/src/TestStack.BDDfy/Reporters/Writers/FileWriter.cs +++ b/src/TestStack.BDDfy/Reporters/Writers/FileWriter.cs @@ -8,29 +8,12 @@ public class FileWriter : IReportWriter { public void OutputReport(string reportData, string reportName, string outputDirectory = null) { - string directory = outputDirectory ?? GetDefaultOutputDirectory; + string directory = outputDirectory ?? FileHelpers.AssemblyDirectory(); var path = Path.Combine(directory, reportName); if (File.Exists(path)) File.Delete(path); File.WriteAllText(path, reportData); } - - private static string GetDefaultOutputDirectory - { - get - { - -#if NET40 - string codeBase = typeof(DiagnosticsReporter).Assembly().CodeBase; - var uri = new UriBuilder(codeBase); - string path = Uri.UnescapeDataString(uri.Path); - return Path.GetDirectoryName(path); -#else - var basePath = AppContext.BaseDirectory; - return Path.GetFullPath(basePath); -#endif - } - } } } \ No newline at end of file