Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Nov 30, 2023
1 parent 6efb62f commit bb86854
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
18 changes: 8 additions & 10 deletions src/ApprovalTests/Reporters/TestFrameworks/MsTestReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@

namespace ApprovalTests.Reporters.TestFrameworks;

public class MsTestReporter : AssertReporter
public class MsTestReporter() :
AssertReporter(
assertClass: "Microsoft.VisualStudio.TestTools.UnitTesting.Assert, Microsoft.VisualStudio.TestPlatform.TestFramework",
areEqual: "AreEqual",
frameworkAttribute: VSStackTraceParser.Attribute)
{
public readonly static MsTestReporter INSTANCE = new();

public MsTestReporter()
: base(
assertClass: "Microsoft.VisualStudio.TestTools.UnitTesting.Assert, Microsoft.VisualStudio.TestPlatform.TestFramework",
areEqual: "AreEqual",
frameworkAttribute: VSStackTraceParser.Attribute)
{
}

protected override void InvokeEqualsMethod(Type type, string[] parameters)
{
var bindingFlags = BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static;
var areEquals = type
.GetMethods(bindingFlags)
.Single(_ => _.Name=="AreEqual" && _.ContainsGenericParameters && _.GetParameters().Length == 2);
.Single(_ => _.Name == "AreEqual" &&
_.ContainsGenericParameters &&
_.GetParameters().Length == 2);
var method = areEquals.MakeGenericMethod(typeof(string));
method.Invoke(null, parameters);
}
Expand Down
11 changes: 5 additions & 6 deletions src/ApprovalTests/Reporters/TestFrameworks/XUnit2Reporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace ApprovalTests.Reporters.TestFrameworks;

public class XUnit2Reporter : AssertReporter
public class XUnit2Reporter() :
AssertReporter(
"Xunit.Assert, xunit.assert",
"Equal",
XUnitStackTraceParser.Attribute)
{
public readonly static XUnit2Reporter INSTANCE = new();
static readonly Lazy<bool> isXunit2 = new(IsXunit2);
Expand All @@ -20,11 +24,6 @@ static bool IsXunit2()
});
}

public XUnit2Reporter()
: base("Xunit.Assert, xunit.assert", "Equal", XUnitStackTraceParser.Attribute)
{
}

public override bool IsWorkingInThisEnvironment(string forFile) =>
base.IsWorkingInThisEnvironment(forFile) && isXunit2.Value;

Expand Down

0 comments on commit bb86854

Please sign in to comment.