From aaab5b49ad9c68d705e4e0664b265c3cb3b44e40 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 23 Jan 2024 10:57:52 +1100 Subject: [PATCH] cleanup --- src/ApprovalTests.Tests/ApprovalsTest.cs | 2 +- src/ApprovalTests.Tests/LockDownTests.cs | 8 ++++---- src/ApprovalTests/Approvers/FileApprover.cs | 18 ++++++------------ .../Combinations/CombinationApprovals.cs | 2 +- .../ExceptionalExceptions/Exceptional.cs | 4 ++-- src/ApprovalTests/Namers/ApprovalResults.cs | 2 +- .../Reporters/ExecutableQueryFailure.cs | 8 +++++++- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ApprovalTests.Tests/ApprovalsTest.cs b/src/ApprovalTests.Tests/ApprovalsTest.cs index a2ffad9f..0f89c63e 100644 --- a/src/ApprovalTests.Tests/ApprovalsTest.cs +++ b/src/ApprovalTests.Tests/ApprovalsTest.cs @@ -1,7 +1,7 @@ [TestFixture] public class ApprovalsTest { - static readonly string[] text = {"abc", "123", "!@#"}; + static readonly string[] text = ["abc", "123", "!@#"]; // begin-snippet: simple_verify [Test] diff --git a/src/ApprovalTests.Tests/LockDownTests.cs b/src/ApprovalTests.Tests/LockDownTests.cs index aa63e674..112f67e9 100644 --- a/src/ApprovalTests.Tests/LockDownTests.cs +++ b/src/ApprovalTests.Tests/LockDownTests.cs @@ -10,21 +10,21 @@ public class LockDownTests [Test] public void TestLockDown() { - int[] n = {1, 2}; + int[] n = [1, 2]; CombinationApprovals.VerifyAllCombinations((a, b, c, d, e, f, g, h, i) => Echo(a, b, c, d, e, f, g, h, i), n, n, n, n, n, n, n, n, n); } [Test] public void TestLockDown8() { - int[] n = {1, 2}; + int[] n = [1, 2]; CombinationApprovals.VerifyAllCombinations((a, b, c, d, e, f, g, h) => Echo(a, b, c, d, e, f, g, h), n, n, n, n, n, n, n, n); } [Test] public void TestLockDown2() { - int[] n = {1, 2}; + int[] n = [1, 2]; CombinationApprovals.VerifyAllCombinations((a, b) => Echo(a, b), n, n); } @@ -34,7 +34,7 @@ public void TestExceptions() { using (ApprovalResults.UniqueForOs()) { - int[] n = {0, 2}; + int[] n = [0, 2]; CombinationApprovals.VerifyAllCombinations((a, b) => a / b, n, n); } } diff --git a/src/ApprovalTests/Approvers/FileApprover.cs b/src/ApprovalTests/Approvers/FileApprover.cs index 15086197..61825295 100644 --- a/src/ApprovalTests/Approvers/FileApprover.cs +++ b/src/ApprovalTests/Approvers/FileApprover.cs @@ -4,22 +4,16 @@ namespace ApprovalTests.Approvers; -public class FileApprover : IApprovalApprover +public class FileApprover(IApprovalWriter writer, IApprovalNamer namer, bool normalizeLineEndingsForTextFiles = false) + : IApprovalApprover { - public readonly IApprovalNamer namer; - public readonly bool normalizeLineEndingsForTextFiles; - public readonly IApprovalWriter writer; + public readonly IApprovalNamer namer = namer; + public readonly bool normalizeLineEndingsForTextFiles = normalizeLineEndingsForTextFiles; + public readonly IApprovalWriter writer = writer; public string approved; public ApprovalException failure; public string received; - public FileApprover(IApprovalWriter writer, IApprovalNamer namer, bool normalizeLineEndingsForTextFiles = false) - { - this.writer = writer; - this.namer = namer; - this.normalizeLineEndingsForTextFiles = normalizeLineEndingsForTextFiles; - } - public virtual bool Approve() { var basename = Path.Combine(namer.SourcePath, namer.Name); @@ -38,7 +32,7 @@ public virtual ApprovalException Approve(string approvedPath, string receivedPat return new ApprovalMissingException(receivedPath, approvedPath); } - if (normalizeLineEndingsForTextFiles && FileExtensions.IsText(approvedPath)) + if (normalizeLineEndingsForTextFiles && FileExtensions.IsTextFile(approvedPath)) { var receivedText = File.ReadAllText(receivedPath).Replace("\r\n", "\n"); var approvedText = File.ReadAllText(approvedPath).Replace("\r\n", "\n"); diff --git a/src/ApprovalTests/Combinations/CombinationApprovals.cs b/src/ApprovalTests/Combinations/CombinationApprovals.cs index bd08954d..57c237c2 100644 --- a/src/ApprovalTests/Combinations/CombinationApprovals.cs +++ b/src/ApprovalTests/Combinations/CombinationApprovals.cs @@ -5,7 +5,7 @@ namespace ApprovalTests.Combinations; public static class CombinationApprovals { - static readonly object[] EMPTY = {null}; + static readonly object[] EMPTY = [null]; public static void VerifyAllCombinations(Func processCall, IEnumerable aList) => VerifyAllCombinations((a, _, _, _, _, _, _, _, _) => diff --git a/src/ApprovalTests/ExceptionalExceptions/Exceptional.cs b/src/ApprovalTests/ExceptionalExceptions/Exceptional.cs index 2ed02bdf..2f12f9fd 100644 --- a/src/ApprovalTests/ExceptionalExceptions/Exceptional.cs +++ b/src/ApprovalTests/ExceptionalExceptions/Exceptional.cs @@ -14,8 +14,8 @@ public static T Create(Exception causedBy, string formattableMessage, params Func reflectiveConstructor = (m, e) => { var type = typeof(T); - var constructorInfo = type.GetConstructor(new[] {typeof(string), typeof(Exception)}); - var instance = (T) constructorInfo.Invoke(new object[] {m, e}); + var constructorInfo = type.GetConstructor([typeof(string), typeof(Exception)]); + var instance = (T) constructorInfo.Invoke([m, e]); return instance; }; return Create(reflectiveConstructor, causedBy, formattableMessage, messageParameters); diff --git a/src/ApprovalTests/Namers/ApprovalResults.cs b/src/ApprovalTests/Namers/ApprovalResults.cs index 22c111ed..76f9ea5b 100644 --- a/src/ApprovalTests/Namers/ApprovalResults.cs +++ b/src/ApprovalTests/Namers/ApprovalResults.cs @@ -82,7 +82,7 @@ public static string GetFullOsName() public static string TransformEasyOsName(string captionName) { - string[] known = {"XP", "2000", "Vista", "7", "8", "Server 2003", "Server 2008", "Server 2012"}; + string[] known = ["XP", "2000", "Vista", "7", "8", "Server 2003", "Server 2008", "Server 2012"]; var matched = known.FirstOrDefault(s => captionName.StartsWith("Microsoft Windows " + s)); if (matched != null) { diff --git a/src/ApprovalTests/Reporters/ExecutableQueryFailure.cs b/src/ApprovalTests/Reporters/ExecutableQueryFailure.cs index 3c0a4e70..e704bf5f 100644 --- a/src/ApprovalTests/Reporters/ExecutableQueryFailure.cs +++ b/src/ApprovalTests/Reporters/ExecutableQueryFailure.cs @@ -7,7 +7,13 @@ public class ExecutableQueryFailure(IExecutableQuery query, IApprovalFailureRepo IApprovalFailureReporter, IApprovalReporterWithCleanUp { const string FileNameSuffix = ".queryresults.txt"; - const string Header = "\t\tDo NOT approve\n\t\tThis File will be Deleted\n\t\tit is for feedback purposes only.\n\t\tAn additional file has been opened with only the query which you can approve.\n"; + const string Header = """ + Do NOT approve + This File will be Deleted + it is for feedback purposes only. + An additional file has been opened with only the query which you can approve. + + """; public void CleanUp(string approved, string received) {