Created
May 10, 2019 09:24
-
-
Save viceice/cefdc272b33f23914d038f7abe263844 to your computer and use it in GitHub Desktop.
snapper net45 support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Snapper.Core/Snapper.Core.csproj b/Snapper.Core/Snapper.Core.csproj | |
index d81b315..26d1d0e 100644 | |
--- a/Snapper.Core/Snapper.Core.csproj | |
+++ b/Snapper.Core/Snapper.Core.csproj | |
@@ -11,6 +11,6 @@ See Project Site for more details</Description> | |
<PackageTags>testing, test, snapshot, jest</PackageTags> | |
<LangVersion>latest</LangVersion> | |
<LangVersion >latest</LangVersion > | |
- <TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks> | |
+ <TargetFrameworks>net45;netstandard1.3;netstandard2.0</TargetFrameworks> | |
</PropertyGroup> | |
</Project> | |
\ No newline at end of file | |
diff --git a/Snapper.Json.Nunit/NUnitEnvironmentVariableUpdateDecider.cs b/Snapper.Json.Nunit/NUnitEnvironmentVariableUpdateDecider.cs | |
index 53bb60c..95b2aa2 100644 | |
--- a/Snapper.Json.Nunit/NUnitEnvironmentVariableUpdateDecider.cs | |
+++ b/Snapper.Json.Nunit/NUnitEnvironmentVariableUpdateDecider.cs | |
@@ -17,11 +17,11 @@ public bool ShouldUpdateSnap() | |
if (_envUpdateDecider.ShouldUpdateSnap()) | |
return true; | |
- var (method, _) = NUnitTestHelper.GetCallingTestInfo(); | |
+ var info = NUnitTestHelper.GetCallingTestInfo(); | |
- var methodHasAttribute = method?.GetCustomAttributes(typeof(UpdateSnapshots), true).Any() ?? false; | |
+ var methodHasAttribute = info.Method?.GetCustomAttributes(typeof(UpdateSnapshots), true).Any() ?? false; | |
var classHasAttribute = | |
- method?.ReflectedType?.GetCustomAttributes(typeof(UpdateSnapshots), true).Any() ?? false; | |
+ info.Method?.ReflectedType?.GetCustomAttributes(typeof(UpdateSnapshots), true).Any() ?? false; | |
return methodHasAttribute || classHasAttribute; | |
} | |
diff --git a/Snapper.Json.Nunit/NUnitPathResolver.cs b/Snapper.Json.Nunit/NUnitPathResolver.cs | |
index c7901a9..e7903dd 100644 | |
--- a/Snapper.Json.Nunit/NUnitPathResolver.cs | |
+++ b/Snapper.Json.Nunit/NUnitPathResolver.cs | |
@@ -7,11 +7,11 @@ internal class NUnitPathResolver : IPathResolver | |
{ | |
public string ResolvePath(string snapshotName) | |
{ | |
- var (method, filePath) = NUnitTestHelper.GetCallingTestInfo(); | |
- var directory = Path.GetDirectoryName(filePath); | |
- var className = method.DeclaringType?.Name; | |
+ var info = NUnitTestHelper.GetCallingTestInfo(); | |
+ var directory = Path.GetDirectoryName(info.FileName); | |
+ var className = info.Method.DeclaringType?.Name; | |
var snapName = string.IsNullOrWhiteSpace(snapshotName) | |
- ? $"{className}{'_'}{method.Name}" | |
+ ? $"{className}{'_'}{info.Method.Name}" | |
: $"{className}{'_'}{snapshotName}"; | |
return Path.Combine(directory, "_snapshots", $"{snapName}.json"); | |
diff --git a/Snapper.Json.Nunit/NUnitTestHelper.cs b/Snapper.Json.Nunit/NUnitTestHelper.cs | |
index c186513..83dbaac 100644 | |
--- a/Snapper.Json.Nunit/NUnitTestHelper.cs | |
+++ b/Snapper.Json.Nunit/NUnitTestHelper.cs | |
@@ -7,9 +7,15 @@ | |
namespace Snapper.Json.Nunit | |
{ | |
+ internal class CalingTestInfo | |
+ { | |
+ public MethodBase Method { get; set; } | |
+ public string FileName { get; set; } | |
+ } | |
+ | |
internal static class NUnitTestHelper | |
{ | |
- public static (MethodBase, string) GetCallingTestInfo() | |
+ public static CalingTestInfo GetCallingTestInfo() | |
{ | |
var stackTrace = new StackTrace(2, true); | |
foreach (var stackFrame in stackTrace.GetFrames() ?? new StackFrame[0]) | |
@@ -17,11 +23,11 @@ public static (MethodBase, string) GetCallingTestInfo() | |
var method = stackFrame.GetMethod(); | |
if (IsNUnitTestMethod(method)) | |
- return (method, stackFrame.GetFileName()); | |
+ return new CalingTestInfo { Method = method, FileName = stackFrame.GetFileName() }; | |
var asyncMethod = GetMethodBaseOfAsyncMethod(method); | |
if (IsNUnitTestMethod(asyncMethod)) | |
- return (asyncMethod, stackFrame.GetFileName()); | |
+ return new CalingTestInfo { Method = asyncMethod, FileName = stackFrame.GetFileName() }; ; | |
} | |
throw new InvalidOperationException( | |
diff --git a/Snapper.Json.Nunit/Snapper.Json.Nunit.csproj b/Snapper.Json.Nunit/Snapper.Json.Nunit.csproj | |
index fdda27b..40bbf11 100644 | |
--- a/Snapper.Json.Nunit/Snapper.Json.Nunit.csproj | |
+++ b/Snapper.Json.Nunit/Snapper.Json.Nunit.csproj | |
@@ -1,6 +1,6 @@ | |
´╗┐<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
- <TargetFramework>netstandard2.0</TargetFramework> | |
+ <TargetFrameworks>net45;netstandard2.0</TargetFrameworks> | |
<Version>0.0.0</Version> | |
<Authors>Simar Kalra</Authors> | |
<RepositoryUrl>https://github.com/theramis/Snapper</RepositoryUrl> | |
diff --git a/Snapper.Json.Xunit/Snapper.Json.Xunit.csproj b/Snapper.Json.Xunit/Snapper.Json.Xunit.csproj | |
index 7798abd..a952f64 100644 | |
--- a/Snapper.Json.Xunit/Snapper.Json.Xunit.csproj | |
+++ b/Snapper.Json.Xunit/Snapper.Json.Xunit.csproj | |
@@ -1,6 +1,6 @@ | |
´╗┐<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
- <TargetFramework>netstandard2.0</TargetFramework> | |
+ <TargetFrameworks>net45;netstandard2.0</TargetFrameworks> | |
<Version>0.0.0</Version> | |
<Authors>Simar Kalra</Authors> | |
<RepositoryUrl>https://github.com/theramis/Snapper</RepositoryUrl> | |
diff --git a/Snapper.Json.Xunit/XUnitEnvironmentVariableUpdateDecider.cs b/Snapper.Json.Xunit/XUnitEnvironmentVariableUpdateDecider.cs | |
index 651ebcb..dc03919 100644 | |
--- a/Snapper.Json.Xunit/XUnitEnvironmentVariableUpdateDecider.cs | |
+++ b/Snapper.Json.Xunit/XUnitEnvironmentVariableUpdateDecider.cs | |
@@ -17,11 +17,11 @@ public bool ShouldUpdateSnap() | |
if (_envUpdateDecider.ShouldUpdateSnap()) | |
return true; | |
- var (method, _) = XUnitTestHelper.GetCallingTestInfo(); | |
+ var info = XUnitTestHelper.GetCallingTestInfo(); | |
- var methodHasAttribute = method?.GetCustomAttributes(typeof(UpdateSnapshots), true).Any() ?? false; | |
+ var methodHasAttribute = info.Method?.GetCustomAttributes(typeof(UpdateSnapshots), true).Any() ?? false; | |
var classHasAttribute = | |
- method?.ReflectedType?.GetCustomAttributes(typeof(UpdateSnapshots), true).Any() ?? false; | |
+ info.Method?.ReflectedType?.GetCustomAttributes(typeof(UpdateSnapshots), true).Any() ?? false; | |
return methodHasAttribute || classHasAttribute; | |
} | |
diff --git a/Snapper.Json.Xunit/XUnitPathResolver.cs b/Snapper.Json.Xunit/XUnitPathResolver.cs | |
index 38189c1..3eb221f 100644 | |
--- a/Snapper.Json.Xunit/XUnitPathResolver.cs | |
+++ b/Snapper.Json.Xunit/XUnitPathResolver.cs | |
@@ -7,9 +7,9 @@ public class XUnitPathResolver : IPathResolver | |
{ | |
public string ResolvePath(string snapshotName) | |
{ | |
- var (method, filePath) = XUnitTestHelper.GetCallingTestInfo(); | |
- var directory = Path.GetDirectoryName(filePath); | |
- var snapName = string.IsNullOrWhiteSpace(snapshotName) ? method.Name : snapshotName; | |
+ var info = XUnitTestHelper.GetCallingTestInfo(); | |
+ var directory = Path.GetDirectoryName(info.FileName); | |
+ var snapName = string.IsNullOrWhiteSpace(snapshotName) ? info.Method.Name : snapshotName; | |
return Path.Combine(directory, "_snapshots", $"{snapName}.json"); | |
} | |
diff --git a/Snapper.Json.Xunit/XUnitTestHelper.cs b/Snapper.Json.Xunit/XUnitTestHelper.cs | |
index 8027e48..3e84c67 100644 | |
--- a/Snapper.Json.Xunit/XUnitTestHelper.cs | |
+++ b/Snapper.Json.Xunit/XUnitTestHelper.cs | |
@@ -7,9 +7,15 @@ | |
namespace Snapper.Json.Xunit | |
{ | |
+ internal class CalingTestInfo | |
+ { | |
+ public MethodBase Method { get; set; } | |
+ public string FileName { get; set; } | |
+ } | |
+ | |
internal static class XUnitTestHelper | |
{ | |
- public static (MethodBase method, string filePath) GetCallingTestInfo() | |
+ public static CalingTestInfo GetCallingTestInfo() | |
{ | |
var stackTrace = new StackTrace(2, true); | |
foreach (var stackFrame in stackTrace.GetFrames() ?? new StackFrame[0]) | |
@@ -17,11 +23,11 @@ public static (MethodBase method, string filePath) GetCallingTestInfo() | |
var method = stackFrame.GetMethod(); | |
if (IsXUnitTestMethod(method)) | |
- return (method, stackFrame.GetFileName()); | |
+ return new CalingTestInfo { Method = method, FileName = stackFrame.GetFileName() }; | |
var asyncMethod = GetMethodBaseOfAsyncMethod(method); | |
if (IsXUnitTestMethod(asyncMethod)) | |
- return (asyncMethod, stackFrame.GetFileName()); | |
+ return new CalingTestInfo { Method = asyncMethod, FileName = stackFrame.GetFileName() }; | |
} | |
throw new InvalidOperationException("Snapshots can only be created from classes decorated with the [Fact] or [Theory] attribute"); | |
diff --git a/Snapper.Json/Snapper.Json.csproj b/Snapper.Json/Snapper.Json.csproj | |
index f0a180b..9decdad 100644 | |
--- a/Snapper.Json/Snapper.Json.csproj | |
+++ b/Snapper.Json/Snapper.Json.csproj | |
@@ -10,7 +10,7 @@ See Project Site for more details</Description> | |
<PackageLicenseUrl>https://github.com/theramis/Snapper/blob/master/LICENSE</PackageLicenseUrl> | |
<PackageTags>testing, test, snapshot, jest, json</PackageTags> | |
<LangVersion>latest</LangVersion> | |
- <TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks> | |
+ <TargetFrameworks>net45;netstandard1.3;netstandard2.0</TargetFrameworks> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment