Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed May 11, 2024
1 parent cde06f2 commit 2f52ab2
Show file tree
Hide file tree
Showing 24 changed files with 81 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/ApprovalTests.NUnit3/NUnitReporterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class NUnitReporterTest
public void TestNunitIsWorking()
{
Approvals.SetCaller();
Assert.IsTrue(NUnitReporter.INSTANCE.IsWorkingInThisEnvironment("default.txt"));
Assert.IsTrue(NUnit3Reporter.INSTANCE.IsWorkingInThisEnvironment("default.txt"));
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion src/ApprovalTests.NUnit3/NUnitReporterWithCleanup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class NUnitReporterWithCleanup : NUnitReporter
public class NUnitReporterWithCleanup : NUnit3Reporter
{
public override void Report(string approved, string received)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ApprovalTests.Tests/ApprovalTests.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageReference Include="itext7.bouncy-castle-adapter" Version="8.0.4" />
<PackageReference Include="MarkdownSnippets.MsBuild" Version="27.0.2" PrivateAssets="all" />
<PackageReference Include="itext7" Version="8.0.4" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="System.Management" Version="8.0.0" />
Expand Down
6 changes: 3 additions & 3 deletions src/ApprovalTests.Tests/FileApproverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void LineEndingsAreIgnored()
File.WriteAllText(approvedFile, "Foo\nBar");
File.WriteAllText(receivedFile, "Foo\r\nBar");
var fileApprover = new FileApprover(null, null, true).Approve(approvedFile, receivedFile);
Assert.IsNull(fileApprover);
ClassicAssert.IsNull(fileApprover);
}

[Test]
Expand All @@ -34,13 +34,13 @@ public void LineEndingAreNotIgnored()
File.WriteAllText(approvedFile, "Foo\nBar");
File.WriteAllText(receivedFile, "Foo\r\nBar");
var fileApprover = new FileApprover(null, null).Approve(approvedFile, receivedFile);
Assert.IsInstanceOf<ApprovalMismatchException>(fileApprover);
ClassicAssert.IsInstanceOf<ApprovalMismatchException>(fileApprover);
}

static void AssertApprover(string receivedFile, string approvedFile, bool expected)
{
var basePath = PathUtilities.GetDirectoryForCaller();
var fileApprover = new FileApprover(null, null).Approve(basePath + approvedFile, basePath + receivedFile);
Assert.AreEqual(expected, fileApprover == null);
ClassicAssert.AreEqual(expected, fileApprover == null);
}
}
3 changes: 2 additions & 1 deletion src/ApprovalTests.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
global using iText.Kernel.Pdf;
global using iText.Layout;
global using iText.Layout.Element;
global using NUnit.Framework;
global using NUnit.Framework;
global using NUnit.Framework.Legacy;
14 changes: 7 additions & 7 deletions src/ApprovalTests.Tests/Namer/AdditionalInformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void UniqueForRuntime()
public void WithoutExtraInfo()
{
var name = Approvals.GetDefaultNamer().Name;
Assert.AreEqual("AdditionalInformationTests.WithoutExtraInfo", name);
ClassicAssert.AreEqual("AdditionalInformationTests.WithoutExtraInfo", name);
}

[Test]
Expand All @@ -32,7 +32,7 @@ public void WithScenarioData()
using (ApprovalResults.ForScenario("ScenarioName"))
{
var name = Approvals.GetDefaultNamer().Name;
Assert.AreEqual("AdditionalInformationTests.WithScenarioData.ForScenario.ScenarioName", name);
ClassicAssert.AreEqual("AdditionalInformationTests.WithScenarioData.ForScenario.ScenarioName", name);
}
}

Expand All @@ -43,7 +43,7 @@ public async Task WithScenarioDataAsync()
{
await Task.Delay(10);
var name = Approvals.GetDefaultNamer().Name;
Assert.AreEqual("AdditionalInformationTests.WithScenarioDataAsync.ForScenario.asyncScenario", name);
ClassicAssert.AreEqual("AdditionalInformationTests.WithScenarioDataAsync.ForScenario.asyncScenario", name);
}
}

Expand All @@ -54,7 +54,7 @@ public void WithScenarioDataScrubsInvalidChars()
using (ApprovalResults.ForScenario("invalid/chars"))
{
var name = Approvals.GetDefaultNamer().Name;
Assert.AreEqual(
ClassicAssert.AreEqual(
"AdditionalInformationTests.WithScenarioDataScrubsInvalidChars.ForScenario.invalid_chars", name);
}
}
Expand All @@ -66,7 +66,7 @@ public void WithMultiplePartScenarioData(string a, string b)
using (ApprovalResults.ForScenario(a, b))
{
var name = Approvals.GetDefaultNamer().Name;
Assert.AreEqual("AdditionalInformationTests.WithMultiplePartScenarioData.ForScenario.foo.bar", name);
ClassicAssert.AreEqual("AdditionalInformationTests.WithMultiplePartScenarioData.ForScenario.foo.bar", name);
}
}

Expand All @@ -78,7 +78,7 @@ public void TestMultipleNames()
using (ApprovalResults.ForScenario("machineName"))
{
var name = Approvals.GetDefaultNamer().Name;
Assert.AreEqual(name,
ClassicAssert.AreEqual(name,
"AdditionalInformationTests.TestMultipleNames.ForScenario.scenario.ForScenario.machineName");
}
}
Expand All @@ -91,7 +91,7 @@ public class NestedClassTests
public void WithNestedClass()
{
var name = Approvals.GetDefaultNamer().Name;
Assert.AreEqual("AdditionalInformationTests.NestedClassTests.WithNestedClass", name);
ClassicAssert.AreEqual("AdditionalInformationTests.NestedClassTests.WithNestedClass", name);
}
}
}
2 changes: 1 addition & 1 deletion src/ApprovalTests.Tests/Namer/ApprovalResultsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void TestUniqueNames()

[Test]
public void TestEasyNames() =>
Assert.AreEqual("Windows 7", ApprovalResults.TransformEasyOsName("Microsoft Windows 7 Professional N"));
ClassicAssert.AreEqual("Windows 7", ApprovalResults.TransformEasyOsName("Microsoft Windows 7 Professional N"));

public void SampleUniqueForOs()
{
Expand Down
2 changes: 1 addition & 1 deletion src/ApprovalTests.Tests/Namer/ApprovalsFilenameTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public void TestMachineSpecificName()
var approvalsFilename = ApprovalsFilename.Parse(@"..\Email\EmailTest.Testname.Microsoft_Windows_10_Education.approved.eml");
// end-snippet
Approvals.Verify(approvalsFilename);
Assert.True(approvalsFilename.IsMachineSpecific);
ClassicAssert.True(approvalsFilename.IsMachineSpecific);
}

[Test]
Expand Down
8 changes: 4 additions & 4 deletions src/ApprovalTests.Tests/Namer/NunitStackTraceNamerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ public class NunitStackTraceNamerTests
public void TestApprovalName()
{
var name = new UnitTestFrameworkNamer().Name;
Assert.AreEqual("NunitStackTraceNamerTests.TestApprovalName", name);
ClassicAssert.AreEqual("NunitStackTraceNamerTests.TestApprovalName", name);
}

[Test]
public void TestSourcePath()
{
var path = Approvals.GetDefaultNamer().SourcePath;
Assert.IsNotEmpty(path);
ClassicAssert.IsNotEmpty(path);
var fullPath = path.ToLower() + Path.DirectorySeparatorChar + GetType().Name + ".cs";
Assert.IsTrue(File.Exists(fullPath), fullPath + " does not exist");
ClassicAssert.IsTrue(File.Exists(fullPath), fullPath + " does not exist");
}

[Test]
Expand All @@ -25,6 +25,6 @@ public void TestCaseAttributes(string caseName)
{
NamerFactory.AdditionalInformation = caseName;
var name = new UnitTestFrameworkNamer().Name;
Assert.AreEqual("NunitStackTraceNamerTests.TestCaseAttributes." + caseName, name);
ClassicAssert.AreEqual("NunitStackTraceNamerTests.TestCaseAttributes." + caseName, name);
}
}
8 changes: 4 additions & 4 deletions src/ApprovalTests.Tests/Pdf/PdfTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ arbitrary content
public void TestPdf_ScrubberIdsMatch(string input)
{
var matchPositions = PdfScrubber.FindIds(input).ToList();
Assert.AreEqual(2, matchPositions.Count);
ClassicAssert.AreEqual(2, matchPositions.Count);

Assert.IsTrue(matchPositions.All(pos => input[pos.start - 1] == '<' && input[pos.start + pos.length] == '>'));
ClassicAssert.IsTrue(matchPositions.All(pos => input[pos.start - 1] == '<' && input[pos.start + pos.length] == '>'));
}

[TestCase("""
Expand All @@ -46,7 +46,7 @@ NO IDS DECLARED
public void TestPdf_ScrubberIdsNotMatch(string input)
{
var matchPositions = PdfScrubber.FindIds(input).ToList();
Assert.AreEqual(0, matchPositions.Count);
ClassicAssert.AreEqual(0, matchPositions.Count);
}

[Test]
Expand Down Expand Up @@ -128,6 +128,6 @@ public void TestPdf_ScrubberFindAllReplacementsInFile()

using var fileStream = File.OpenRead(pdf);
var matches = PdfScrubber.FindReplacements(fileStream);
Assert.AreEqual(3, matches.Count());
ClassicAssert.AreEqual(3, matches.Count());
}
}
6 changes: 3 additions & 3 deletions src/ApprovalTests.Tests/Persistence/AsyncSaverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ public void TestAsyncWrapperSave()
{
using var f = new TempFile("stuff");
var s = new FileSaver(f.File);
Assert.AreEqual("hello", s.ToAsync().Save("hello").Result);
ClassicAssert.AreEqual("hello", s.ToAsync().Save("hello").Result);
}

[Test]
public void TestTrueAsyncSave()
{
using var f = new TempFile("stuff");
var s = new FileAsyncSaver(f.File);
Assert.AreEqual("hello", s.Save("hello").Result);
ClassicAssert.AreEqual("hello", s.Save("hello").Result);
}

[Test]
public void TestNonAsyncWrapper()
{
using var f = new TempFile("stuff");
var s = new FileAsyncSaver(f.File);
Assert.AreEqual("hello", s.ToSynchronous().Save("hello"));
ClassicAssert.AreEqual("hello", s.ToSynchronous().Save("hello"));
}
}
2 changes: 1 addition & 1 deletion src/ApprovalTests.Tests/Reporters/AssemblyLevelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public void TestClassLevel()
{
using (Approvals.SetFrontLoadedReporter(ReportWithoutFrontLoading.INSTANCE))
{
Assert.AreEqual(typeof(DiffReporter), Approvals.GetReporter().GetType());
ClassicAssert.AreEqual(typeof(DiffReporter), Approvals.GetReporter().GetType());
}
}
}
18 changes: 9 additions & 9 deletions src/ApprovalTests.Tests/Reporters/FirstWorkingReporterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public void TestCallsFirstAndOnlyFirst()
var c = new RecordingReporter(true);

var reporter = new FirstWorkingReporter(a, b, c);
Assert.IsTrue(reporter.IsWorkingInThisEnvironment("default.txt"));
ClassicAssert.IsTrue(reporter.IsWorkingInThisEnvironment("default.txt"));
reporter.Report("a", "b");
Assert.IsNull(a.CalledWith);
Assert.AreEqual("a,b", b.CalledWith);
Assert.IsNull(c.CalledWith);
ClassicAssert.IsNull(a.CalledWith);
ClassicAssert.AreEqual("a,b", b.CalledWith);
ClassicAssert.IsNull(c.CalledWith);
}

[Test]
Expand All @@ -28,7 +28,7 @@ public void TestException()
try
{
var ex = ExceptionUtilities.GetException(() => new DiffReporter().Report("received.notreal", "received.notreal"));
Assert.AreEqual("Could not find a diff tool for extension: .notreal", ex.Message);
ClassicAssert.AreEqual("Could not find a diff tool for extension: .notreal", ex.Message);
}
finally
{
Expand All @@ -43,10 +43,10 @@ public void TestCleanup()
var cleanup2 = new MockCleanup();
var r = new FirstWorkingReporter(cleanup1, new QuietReporter(), cleanup2);
r.CleanUp("a", "r");
Assert.AreEqual("a", cleanup1.approved);
Assert.AreEqual("a", cleanup2.approved);
Assert.AreEqual("r", cleanup1.received);
Assert.AreEqual("r", cleanup2.received);
ClassicAssert.AreEqual("a", cleanup1.approved);
ClassicAssert.AreEqual("a", cleanup2.approved);
ClassicAssert.AreEqual("r", cleanup1.received);
ClassicAssert.AreEqual("r", cleanup2.received);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/ApprovalTests.Tests/Reporters/MultiReporterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ public void TestMultiReporter()
var b = new RecordingReporter();
var multi = new MultiReporter(a, b);
multi.Report("a", "r");
Assert.AreEqual("a,r", a.CalledWith);
Assert.AreEqual("a,r", b.CalledWith);
ClassicAssert.AreEqual("a,r", a.CalledWith);
ClassicAssert.AreEqual("a,r", b.CalledWith);
}

[Test]
public void TestCallAfterException()
{
var a = new NUnitReporter();
var a = new NUnit4Reporter();
var b = new RecordingReporter();
var multi = new MultiReporter(a, b);
var exception = ExceptionUtilities.GetException(() => multi.Report("a", "r"));
Assert.AreEqual("a,r", b.CalledWith);
Assert.IsInstanceOf<Exception>(exception);
ClassicAssert.AreEqual("a,r", b.CalledWith);
ClassicAssert.IsInstanceOf<Exception>(exception);
}
}
8 changes: 3 additions & 5 deletions src/ApprovalTests.Tests/Reporters/NUnitReporterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class NUnitReporterTest
public void TestNunitIsWorking()
{
Approvals.SetCaller();
Assert.IsTrue(NUnitReporter.INSTANCE.IsWorkingInThisEnvironment("default.txt"));
ClassicAssert.IsTrue(NUnit4Reporter.INSTANCE.IsWorkingInThisEnvironment("default.txt"));
}

[Test]
Expand All @@ -23,10 +23,8 @@ public void TestReporter()
}
catch (Exception e)
{
var expectedMessage = string.Format(" String lengths are both 5. Strings differ at index 0.{0} Expected: \"World\"{0} But was: \"Hello\"{0} -----------^{0}", Environment.NewLine);
Assert.AreEqual(
expectedMessage,
e.Message);
var expectedMessage = string.Format(" Assert.That(actual, Is.EqualTo(expected)){0} String lengths are both 5. Strings differ at index 0.{0} Expected: \"World\"{0} But was: \"Hello\"{0} -----------^{0}", Environment.NewLine);
ClassicAssert.AreEqual(expectedMessage, e.Message);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class NUnitReporterWithCleanup : NUnitReporter
public class NUnitReporterWithCleanup : NUnit4Reporter
{
public override void Report(string approved, string received)
{
Expand Down
15 changes: 9 additions & 6 deletions src/ApprovalTests.Tests/Reporters/ReporterFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ static IEnumerable<Type> GetSingletonReporterTypes()
}

static void SubMethod() =>
Assert.AreEqual(typeof(MethodLevelReporter), Approvals.GetReporter().GetType());
ClassicAssert.AreEqual(typeof(MethodLevelReporter), Approvals.GetReporter().GetType());

[Test]
public void TestClassLevel()
{
using (Approvals.SetFrontLoadedReporter(ReportWithoutFrontLoading.INSTANCE))
{
Assert.AreEqual(typeof(ClassLevelReporter), Approvals.GetReporter().GetType());
ClassicAssert.AreEqual(typeof(ClassLevelReporter), Approvals.GetReporter().GetType());
}
}

Expand All @@ -28,7 +28,7 @@ public void TestMethodOverride()
{
using (Approvals.SetFrontLoadedReporter(ReportWithoutFrontLoading.INSTANCE))
{
Assert.AreEqual(typeof(MethodLevelReporter), Approvals.GetReporter().GetType());
ClassicAssert.AreEqual(typeof(MethodLevelReporter), Approvals.GetReporter().GetType());
}
}

Expand All @@ -39,7 +39,7 @@ public async Task TestAsyncMethodOverride()
await Task.Delay(1);
using (Approvals.SetFrontLoadedReporter(ReportWithoutFrontLoading.INSTANCE))
{
Assert.AreEqual(typeof(MethodLevelReporter), Approvals.GetReporter().GetType());
ClassicAssert.AreEqual(typeof(MethodLevelReporter), Approvals.GetReporter().GetType());
}
}

Expand All @@ -59,7 +59,7 @@ public void TestMultipleReporters()
{
using (Approvals.SetFrontLoadedReporter(ReportWithoutFrontLoading.INSTANCE))
{
Assert.AreEqual(typeof(MultiReporter), Approvals.GetReporter().GetType());
ClassicAssert.AreEqual(typeof(MultiReporter), Approvals.GetReporter().GetType());
}
}

Expand All @@ -69,7 +69,10 @@ public void TestSingletonOnAllReporters()
using (Approvals.SetFrontLoadedReporter(ReportWithoutFrontLoading.INSTANCE))
{
var reporters = GetSingletonReporterTypes();
foreach (var r in reporters) Assert.IsInstanceOf(r, UseReporterAttribute.GetSingleton(r), $"Please add\npublic static readonly {r.FullName} INSTANCE = new {r.FullName}();");
foreach (var r in reporters)
{
ClassicAssert.IsInstanceOf(r, UseReporterAttribute.GetSingleton(r), $"Please add\npublic static readonly {r.FullName} INSTANCE = new {r.FullName}();");
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ApprovalTests.Tests/Reporters/ReporterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public void Testname()
{
var old = Environment.GetEnvironmentVariable(NCrunchReporter.EnvironmentVariable);
Environment.SetEnvironmentVariable(NCrunchReporter.EnvironmentVariable, "1");
Assert.IsTrue(NCrunchReporter.INSTANCE.IsWorkingInThisEnvironment("a.txt"));
ClassicAssert.IsTrue(NCrunchReporter.INSTANCE.IsWorkingInThisEnvironment("a.txt"));
Environment.SetEnvironmentVariable(NCrunchReporter.EnvironmentVariable, old);
}

Expand Down
Loading

0 comments on commit 2f52ab2

Please sign in to comment.