From bac6c0dc6fb91c0c19a2d250c7edcb8f949cbf52 Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Sun, 12 May 2024 21:01:16 +0200 Subject: [PATCH] Update analyzer, fix coding warnings --- .../AcceptanceTests.cs | 4 +--- .../FilterTests.cs | 24 +++++++++---------- .../NUnit.TestAdapter.Tests.Acceptance.csproj | 2 +- .../ParanthesisTests.cs | 14 +++++------ .../AdapterSettingsTests.cs | 2 +- src/NUnitTestAdapterTests/AsyncTests.cs | 5 +--- src/NUnitTestAdapterTests/DumpXmlTests.cs | 6 ++--- src/NUnitTestAdapterTests/ExecutionTests.cs | 4 +--- src/NUnitTestAdapterTests/ExtensionsTests.cs | 4 ++-- .../Filtering/FilteringTestUtils.cs | 4 ++-- .../Filtering/TestDoubleFilterExpression.cs | 13 +++------- .../NUnit.TestAdapter.Tests.csproj | 2 +- .../NUnitEngineTests/NUnitDiscoveryTests.cs | 6 ++--- .../NUnitEngineTests/NUnitResultsTests.cs | 6 ----- .../NUnitEngineTests/NUnitTestCaseTests.cs | 6 ++--- .../NUnitTestEventTestOutputTests.cs | 8 +++---- .../NUnitEngineTests/NUnitTestEventsTests.cs | 9 ++++--- .../NUnitEventListenerOutputTests.cs | 7 +++--- 18 files changed, 52 insertions(+), 74 deletions(-) diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs index c8167de1..2f778d32 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs +++ b/src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs @@ -3,7 +3,6 @@ using System.Diagnostics; using System.IO; using System.Linq; -using System.Net; using NUnit.Framework; using NUnit.Framework.Interfaces; @@ -277,7 +276,6 @@ private static string TryGetTestNupkgVersion(string directory, string packageId) var path = selected?.FullName; - return path is null ? null : - Path.GetFileNameWithoutExtension(path).Substring(packageId.Length + 1); + return Path.GetFileNameWithoutExtension(path)?.Substring(packageId.Length + 1) ?? ""; } } \ No newline at end of file diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/FilterTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/FilterTests.cs index b7129265..917bc6cb 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/FilterTests.cs +++ b/src/NUnit.TestAdapter.Tests.Acceptance/FilterTests.cs @@ -40,12 +40,12 @@ public void Bar() [Test, Platform("Win")] [TestCase(NoFilter, 2, 3)] - [TestCase(@"TestCategory=FooGroup", 1, 2)] - [TestCase(@"TestCategory!=BarGroup", 1, 2)] - [TestCase(@"TestCategory=IsExplicit", 1, 1)] - [TestCase(@"FullyQualifiedName=Filter.Tests.Foo", 1, 1)] - [TestCase(@"FullyQualifiedName!=Filter.Tests.Foo", 1, 1)] - [TestCase(@"TestCategory!=AllGroup", 0, 0)] + [TestCase("TestCategory=FooGroup", 1, 2)] + [TestCase("TestCategory!=BarGroup", 1, 2)] + [TestCase("TestCategory=IsExplicit", 1, 1)] + [TestCase("FullyQualifiedName=Filter.Tests.Foo", 1, 1)] + [TestCase("FullyQualifiedName!=Filter.Tests.Foo", 1, 1)] + [TestCase("TestCategory!=AllGroup", 0, 0)] // [TestCase(@"TestThatDontExistHere", 0, 0)] // [TestCase(@"FullyQualifiedName~Filter.Tests.Foo", 1, 1)] // [TestCase(@"FullyQualifiedName~Foo", 1, 1)] @@ -58,11 +58,11 @@ public void Filter_DotNetTest(string filter, int executed, int total) [Test, Platform("Win")] [TestCase(NoFilter, 2, 3)] - [TestCase(@"TestCategory=FooGroup", 1, 2)] - [TestCase(@"TestCategory!=BarGroup", 1, 2)] - [TestCase(@"TestCategory=IsExplicit", 1, 1)] - [TestCase(@"FullyQualifiedName=Filter.Tests.Foo", 1, 1)] - [TestCase(@"TestCategory=XXXX", 0, 0)] + [TestCase("TestCategory=FooGroup", 1, 2)] + [TestCase("TestCategory!=BarGroup", 1, 2)] + [TestCase("TestCategory=IsExplicit", 1, 1)] + [TestCase("FullyQualifiedName=Filter.Tests.Foo", 1, 1)] + [TestCase("TestCategory=XXXX", 0, 0)] public void Filter_VSTest(string filter, int executed, int total) { var workspace = Build(); @@ -84,7 +84,7 @@ public void Filter_VSTest(string filter, int executed, int total) public void Filter_DotNetTest_NUnitWhere(string filter, int executed, int total) { var workspace = Build(); - var nunitWhere = $@"NUnit.Where={filter}"; + var nunitWhere = $"NUnit.Where={filter}"; var results = workspace.DotNetTest(nunitWhere, true, true, TestContext.WriteLine); Verify(executed, total, results); } diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/NUnit.TestAdapter.Tests.Acceptance.csproj b/src/NUnit.TestAdapter.Tests.Acceptance/NUnit.TestAdapter.Tests.Acceptance.csproj index e003b512..7a41f152 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/NUnit.TestAdapter.Tests.Acceptance.csproj +++ b/src/NUnit.TestAdapter.Tests.Acceptance/NUnit.TestAdapter.Tests.Acceptance.csproj @@ -13,7 +13,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/NUnit.TestAdapter.Tests.Acceptance/ParanthesisTests.cs b/src/NUnit.TestAdapter.Tests.Acceptance/ParanthesisTests.cs index e16fac7d..b74e8613 100644 --- a/src/NUnit.TestAdapter.Tests.Acceptance/ParanthesisTests.cs +++ b/src/NUnit.TestAdapter.Tests.Acceptance/ParanthesisTests.cs @@ -42,13 +42,13 @@ public void VsTestNoFilter() } [Test, Platform("Win")] - [TestCase(@"FullyQualifiedName=Issue919.Foo.Bzzt", 1, 1)] // Sanity check + [TestCase("FullyQualifiedName=Issue919.Foo.Bzzt", 1, 1)] // Sanity check [TestCase(@"FullyQualifiedName=Issue919.Foo.Bar\(1\)", 0, 0)] [TestCase(@"FullyQualifiedName=Issue919.Foo.Baz\(1\)", 1, 1)] - [TestCase(@"Name=Bzzt", 1, 1)] // Sanity check + [TestCase("Name=Bzzt", 1, 1)] // Sanity check [TestCase(@"Name=Bar\(1\)", 0, 0)] [TestCase(@"Name=Baz\(1\)", 1, 1)] - [TestCase(@"", 2, 2)] + [TestCase("", 2, 2)] public void VsTestTestCases(string filter, int executed, int total) { var workspace = Build(); @@ -58,7 +58,7 @@ public void VsTestTestCases(string filter, int executed, int total) } [Test, Platform("Win")] - [TestCase(@"Bzzt", 1, 1)] // Sanity check + [TestCase("Bzzt", 1, 1)] // Sanity check [TestCase(@"Bar\(1\)", 0, 0)] [TestCase(@"Baz\(1\)", 1, 1)] public void VsTestTests(string filter, int executed, int total) @@ -69,13 +69,13 @@ public void VsTestTests(string filter, int executed, int total) } [Test, Platform("Win")] - [TestCase(@"FullyQualifiedName=Issue919.Foo.Bzzt", 1, 1)] // Sanity check + [TestCase("FullyQualifiedName=Issue919.Foo.Bzzt", 1, 1)] // Sanity check [TestCase(@"FullyQualifiedName=Issue919.Foo.Bar\(1\)", 0, 0)] [TestCase(@"FullyQualifiedName=Issue919.Foo.Baz\(1\)", 1, 1)] - [TestCase(@"Name=Bzzt", 1, 1)] // Sanity check + [TestCase("Name=Bzzt", 1, 1)] // Sanity check [TestCase(@"Name=Bar\(1\)", 0, 0)] [TestCase(@"Name=Baz\(1\)", 1, 1)] - [TestCase(@"", 2, 2)] + [TestCase("", 2, 2)] public void DotnetTestCases(string filter, int executed, int total) { var workspace = Build(); diff --git a/src/NUnitTestAdapterTests/AdapterSettingsTests.cs b/src/NUnitTestAdapterTests/AdapterSettingsTests.cs index 1d6c095b..453ee3d4 100644 --- a/src/NUnitTestAdapterTests/AdapterSettingsTests.cs +++ b/src/NUnitTestAdapterTests/AdapterSettingsTests.cs @@ -209,7 +209,7 @@ public void TestOutputSetting() _settings.Load(@"C:\Whatever/my/work/dir"); Assert.That(_settings.UseTestOutputXml); _settings.SetTestOutputFolder(_settings.WorkDirectory); - Assert.That(_settings.TestOutputFolder, Does.Contain(@"/my/work/dir")); + Assert.That(_settings.TestOutputFolder, Does.Contain("/my/work/dir")); } /// diff --git a/src/NUnitTestAdapterTests/AsyncTests.cs b/src/NUnitTestAdapterTests/AsyncTests.cs index 4f767e93..ff4e0437 100644 --- a/src/NUnitTestAdapterTests/AsyncTests.cs +++ b/src/NUnitTestAdapterTests/AsyncTests.cs @@ -49,9 +49,6 @@ private static Task ReturnOne() private static Task ThrowException() { - return Task.Run(() => - { - throw new InvalidOperationException(); - }); + return Task.Run(() => throw new InvalidOperationException()); } } \ No newline at end of file diff --git a/src/NUnitTestAdapterTests/DumpXmlTests.cs b/src/NUnitTestAdapterTests/DumpXmlTests.cs index d007e7e9..bd9c3729 100644 --- a/src/NUnitTestAdapterTests/DumpXmlTests.cs +++ b/src/NUnitTestAdapterTests/DumpXmlTests.cs @@ -75,9 +75,9 @@ public void ThatPathIsCorrectlyParsedInDiscoveryPhase(string path, string expect file.Received().WriteAllText(Arg.Is(o => o.StartsWith(expected, StringComparison.OrdinalIgnoreCase)), Arg.Any()); } - [TestCase(@"/some/Folder/Whatever.dll", @"/some/Folder/Dump/D_Whatever.dll.dump")] - [TestCase(@"/some/Folder/Whatever.dll", @"/some/Folder/Dump")] - [TestCase(@"/some/Folder/Whatever.dll", @"/some/Folder")] + [TestCase("/some/Folder/Whatever.dll", "/some/Folder/Dump/D_Whatever.dll.dump")] + [TestCase("/some/Folder/Whatever.dll", "/some/Folder/Dump")] + [TestCase("/some/Folder/Whatever.dll", "/some/Folder")] [Platform("Unix")] public void ThatPathIsCorrectlyParsedInDiscoveryPhaseOnUnix(string path, string expected) { diff --git a/src/NUnitTestAdapterTests/ExecutionTests.cs b/src/NUnitTestAdapterTests/ExecutionTests.cs index b6f84d40..b56de2f5 100644 --- a/src/NUnitTestAdapterTests/ExecutionTests.cs +++ b/src/NUnitTestAdapterTests/ExecutionTests.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; using NSubstitute; using NUnit.Engine; diff --git a/src/NUnitTestAdapterTests/ExtensionsTests.cs b/src/NUnitTestAdapterTests/ExtensionsTests.cs index c0df4910..a130e670 100644 --- a/src/NUnitTestAdapterTests/ExtensionsTests.cs +++ b/src/NUnitTestAdapterTests/ExtensionsTests.cs @@ -36,7 +36,7 @@ public class ExtensionsTests [TestCase("\r\n")] public void ThatIsNullOrWhiteSpaceHandlesTabs(string value) { - var res = StringExtensions.IsNullOrWhiteSpace(value); + var res = value.IsNullOrWhiteSpace(); Assert.That(res); } @@ -45,7 +45,7 @@ public void ThatIsNullOrWhiteSpaceHandlesTabs(string value) [TestCase("42\n\r")] public void ThatIsNullOrWhiteSpaceHandlesNonWhiteSpace(string value) { - var res = StringExtensions.IsNullOrWhiteSpace(value); + var res = value.IsNullOrWhiteSpace(); Assert.That(res, Is.False); } } \ No newline at end of file diff --git a/src/NUnitTestAdapterTests/Filtering/FilteringTestUtils.cs b/src/NUnitTestAdapterTests/Filtering/FilteringTestUtils.cs index 7dcb965f..588e7720 100644 --- a/src/NUnitTestAdapterTests/Filtering/FilteringTestUtils.cs +++ b/src/NUnitTestAdapterTests/Filtering/FilteringTestUtils.cs @@ -41,11 +41,11 @@ public static ITestCaseFilterExpression CreateVSTestFilterExpression(string filt var filterExpressionWrapper = filterExpressionWrapperType.GetTypeInfo() .GetConstructor(new[] { typeof(string) }) - .Invoke(new object[] { filter }); + .Invoke([filter]); return (ITestCaseFilterExpression)Type.GetType("Microsoft.VisualStudio.TestPlatform.Common.Filtering.TestCaseFilterExpression, Microsoft.VisualStudio.TestPlatform.Common", throwOnError: true).GetTypeInfo() .GetConstructor(new[] { filterExpressionWrapperType }) - .Invoke(new[] { filterExpressionWrapper }); + .Invoke([filterExpressionWrapper]); } public static VsTestFilter CreateTestFilter(ITestCaseFilterExpression filterExpression) diff --git a/src/NUnitTestAdapterTests/Filtering/TestDoubleFilterExpression.cs b/src/NUnitTestAdapterTests/Filtering/TestDoubleFilterExpression.cs index c4cda25c..059943f5 100644 --- a/src/NUnitTestAdapterTests/Filtering/TestDoubleFilterExpression.cs +++ b/src/NUnitTestAdapterTests/Filtering/TestDoubleFilterExpression.cs @@ -29,17 +29,10 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.Filtering; -public sealed class TestDoubleFilterExpression : ITestCaseFilterExpression +public sealed class TestDoubleFilterExpression(string testCaseFilterValue, Func, bool> predicate) + : ITestCaseFilterExpression { - private readonly Func, bool> predicate; - - public TestDoubleFilterExpression(string testCaseFilterValue, Func, bool> predicate) - { - TestCaseFilterValue = testCaseFilterValue; - this.predicate = predicate; - } - - public string TestCaseFilterValue { get; } + public string TestCaseFilterValue { get; } = testCaseFilterValue; public bool MatchTestCase(TestCase testCase, Func propertyValueProvider) { diff --git a/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj b/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj index beb9d8bb..07a2dab9 100644 --- a/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj +++ b/src/NUnitTestAdapterTests/NUnit.TestAdapter.Tests.csproj @@ -14,7 +14,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitDiscoveryTests.cs b/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitDiscoveryTests.cs index 5229d7fe..031ad58d 100644 --- a/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitDiscoveryTests.cs +++ b/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitDiscoveryTests.cs @@ -980,8 +980,8 @@ public void ThatDotNetTestWorks() var sut = new DiscoveryConverter(logger, settings); var ndr = sut.ConvertXml( new NUnitResults(XmlHelper.CreateXmlNode(DotnetXml))); - var fixtures = ndr.TestAssembly.TestFixtures; - Assert.That(fixtures.Count(), Is.EqualTo(3), "Didnt find all fixtures"); + var fixtures = ndr.TestAssembly.TestFixtures.ToList(); + Assert.That(fixtures.Count, Is.EqualTo(3), "Didnt find all fixtures"); foreach (var fixture in fixtures) { Assert.That(fixture.TestCases.Count, Is.EqualTo(3), @@ -1010,7 +1010,7 @@ public void ThatDotNetTestWorks() "; /// - /// See issue 1041 at https://github.com/nunit/nunit3-vs-adapter/issues/1044 + /// See issue 1041 at https://github.com/nunit/nunit3-vs-adapter/issues/1044. /// private const string MixedExplicitTestSourceXmlForIssue1041 = @" diff --git a/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitResultsTests.cs b/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitResultsTests.cs index b126e4a0..4d0e1fb4 100644 --- a/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitResultsTests.cs +++ b/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitResultsTests.cs @@ -21,12 +21,6 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // *********************************************************************** -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace NUnit.VisualStudio.TestAdapter.Tests.NUnitEngineTests; public class NUnitResultsTests diff --git a/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitTestCaseTests.cs b/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitTestCaseTests.cs index b8d30669..60a65aca 100644 --- a/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitTestCaseTests.cs +++ b/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitTestCaseTests.cs @@ -28,11 +28,11 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.NUnitEngineTests; public class NUnitTestCaseTests { - private const string XmlRunnable = @""; + private const string XmlRunnable = ""; - private const string XmlExplicit = @""; + private const string XmlExplicit = ""; - private const string XmlNone = @""; + private const string XmlNone = ""; [Test] diff --git a/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitTestEventTestOutputTests.cs b/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitTestEventTestOutputTests.cs index 2b6f19ba..e82c6984 100644 --- a/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitTestEventTestOutputTests.cs +++ b/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitTestEventTestOutputTests.cs @@ -6,16 +6,16 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.NUnitEngineTests; public class NUnitTestEventTestOutputTests { private const string OutputProgress = - @""; + ""; private const string OutputOut = - @""; + ""; private const string OutputError = - @""; + ""; private const string BlankTestOutput = - @""; + ""; diff --git a/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitTestEventsTests.cs b/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitTestEventsTests.cs index 2b4a9f00..271a2d55 100644 --- a/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitTestEventsTests.cs +++ b/src/NUnitTestAdapterTests/NUnitEngineTests/NUnitTestEventsTests.cs @@ -21,7 +21,6 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // *********************************************************************** -using System.Collections.Generic; using System.Linq; using NUnit.Framework; using NUnit.VisualStudio.TestAdapter.NUnitEngine; @@ -30,7 +29,7 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.NUnitEngineTests; public class NUnitTestEventsTests { - private const string StartSuite = @""; + private const string StartSuite = ""; private readonly string testSuite = @" @@ -53,7 +52,7 @@ public void ThatTestEventIsParsedForTestSuite() Assert.That(sut.FailureMessage, Is.EqualTo("One or more child tests had errors")); } - private readonly string startTest = @""; + private readonly string startTest = ""; [Test] public void ThatTestEventIsParsedForStartTest() @@ -224,7 +223,7 @@ public void ThatTestEventIsParsedForFinishSuiteWithFailure() } /// - /// Exception in OneTimeSetUp + /// Exception in OneTimeSetUp. /// private readonly string testSuiteFinishedWithFailureAndStackTrace = @" @@ -330,7 +329,7 @@ public void ThatTestCaseFailsCanBeParsedWithReason() } private readonly string testCaseExplicitFixtureTime = - @""; + ""; /// /// Issue 811. diff --git a/src/NUnitTestAdapterTests/NUnitEventListenerOutputTests.cs b/src/NUnitTestAdapterTests/NUnitEventListenerOutputTests.cs index d179c7a0..6888e619 100644 --- a/src/NUnitTestAdapterTests/NUnitEventListenerOutputTests.cs +++ b/src/NUnitTestAdapterTests/NUnitEventListenerOutputTests.cs @@ -3,7 +3,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using NSubstitute; using NUnit.Framework; -using NUnit.VisualStudio.TestAdapter.Dump; using NUnit.VisualStudio.TestAdapter.NUnitEngine; namespace NUnit.VisualStudio.TestAdapter.Tests; @@ -32,16 +31,16 @@ public class NUnitEventListenerOutputTests ]]>"; private const string BlankTestOutput = - @""; + ""; private const string TestFinish = - @""; + ""; /// /// For Issue 811. /// private const string TestFinishWithExplicitFixture = - @""; + ""; [SetUp] public void Setup()