Skip to content

Commit

Permalink
Fixes BDDfy.html. Fixes #237
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhelan committed Sep 15, 2016
1 parent 96b4204 commit 2d74ac0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
23 changes: 23 additions & 0 deletions src/TestStack.BDDfy/Reporters/FileHelpers.cs
Original file line number Diff line number Diff line change
@@ -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
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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);
}
}
}
}
19 changes: 1 addition & 18 deletions src/TestStack.BDDfy/Reporters/Writers/FileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}

0 comments on commit 2d74ac0

Please sign in to comment.