diff --git a/ApprovalTests/Namers/AssemblyLocationNamer.cs b/ApprovalTests/Namers/AssemblyLocationNamer.cs new file mode 100644 index 00000000..a95cbfcc --- /dev/null +++ b/ApprovalTests/Namers/AssemblyLocationNamer.cs @@ -0,0 +1,23 @@ +using System; +using System.IO; +using System.Reflection; + +namespace ApprovalTests.Namers +{ + public class AssemblyLocationNamer : UnitTestFrameworkNamer + { + private string AssemblyDirectory + { + get + { + // CodeBase is used because the NUnit test runner is otherwise quirky + var codeBase = Assembly.GetExecutingAssembly().CodeBase; + var uri = new UriBuilder(codeBase); + var path = Uri.UnescapeDataString(uri.Path); + return Path.GetDirectoryName(path); + } + } + + public override string SourcePath => AssemblyDirectory + GetSubdirectory(); + } +} \ No newline at end of file diff --git a/ApprovalTests/Namers/UnitTestFrameworkNamer.cs b/ApprovalTests/Namers/UnitTestFrameworkNamer.cs index 6c77c689..9a44ae83 100644 --- a/ApprovalTests/Namers/UnitTestFrameworkNamer.cs +++ b/ApprovalTests/Namers/UnitTestFrameworkNamer.cs @@ -28,7 +28,7 @@ private void HandleSubdirectory() public string Name => stackTraceParser.ApprovalName; - public string SourcePath => stackTraceParser.SourcePath + GetSubdirectory(); + public virtual string SourcePath => stackTraceParser.SourcePath + GetSubdirectory(); public string GetSubdirectory() {