Skip to content

Commit

Permalink
Fix NUnit warnings NUnit1029 & NUnit1030
Browse files Browse the repository at this point in the history
See also:

- NUnit1029: The number of parameters provided by the TestCaseSource
  does not match the number of parameters in the Test method:
  <https://github.com/nunit/nunit.analyzers/blob/e026ba5ccda583ecb991de0ba16614fcc57a6c1a/documentation/NUnit1029.md>

- NUnit1030: The type of parameter provided by the TestCaseSource
  does not match the type of the parameter in the Test method:
  <https://github.com/nunit/nunit.analyzers/blob/e026ba5ccda583ecb991de0ba16614fcc57a6c1a/documentation/NUnit1030.md>
  • Loading branch information
atifaziz committed Oct 28, 2024
1 parent 03a160c commit c1d0d46
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 32 deletions.
6 changes: 0 additions & 6 deletions MoreLinq.Test/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,3 @@ dotnet_diagnostic.CA1861.severity = none

# IDE0022: Use expression/block body for methods
dotnet_diagnostic.IDE0022.severity = none

# NUnit1030: The type of parameter provided by the TestCaseSource does not match the type of the parameter in the Test method
dotnet_diagnostic.NUnit1030.severity = suggestion

# Nunit1029: The number of parameters provided by the TestCaseSource does not match the number of parameters in the Test method
dotnet_diagnostic.NUnit1029.severity = suggestion
3 changes: 1 addition & 2 deletions MoreLinq.Test/AggregateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ namespace MoreLinq.Test
using Experimental;
using System.Reactive.Linq;
using System.Reflection;
using NUnit.Framework.Interfaces;
using static MoreLinq.Extensions.AppendExtension;
using static FuncModule;

[TestFixture]
public class AggregateTest
{
public static IEnumerable<ITestCaseData> AccumulatorsTestSource(string name, int count) =>
public static IEnumerable<TestCaseData> AccumulatorsTestSource(string name, int count) =>

/* Generates an invocation as follows for 2 accumulators:
Expand Down
11 changes: 5 additions & 6 deletions MoreLinq.Test/NullArgumentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace MoreLinq.Test
using System.Reflection;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using StackTrace = System.Diagnostics.StackTrace;

[TestFixture]
Expand All @@ -38,7 +37,7 @@ public void NotNull(Action testCase) =>
public void CanBeNull(Action testCase) =>
testCase();

static IEnumerable<ITestCaseData> GetNotNullTestCases() =>
static IEnumerable<TestCaseData> GetNotNullTestCases() =>
GetTestCases(canBeNull: false, testCaseFactory: (method, args, paramName) => () =>
{
Exception? e = null;
Expand All @@ -61,15 +60,15 @@ static IEnumerable<ITestCaseData> GetNotNullTestCases() =>
Assert.That(actualType, Is.SameAs(typeof(MoreEnumerable)));
});

static IEnumerable<ITestCaseData> GetCanBeNullTestCases() =>
static IEnumerable<TestCaseData> GetCanBeNullTestCases() =>
GetTestCases(canBeNull: true, testCaseFactory: (method, args, _) => () => method.Invoke(null, args));

static IEnumerable<ITestCaseData> GetTestCases(bool canBeNull, Func<MethodInfo, object?[], string, Action> testCaseFactory) =>
static IEnumerable<TestCaseData> GetTestCases(bool canBeNull, Func<MethodInfo, object?[], string, Action> testCaseFactory) =>
from m in typeof(MoreEnumerable).GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)
from t in CreateTestCases(m, canBeNull, testCaseFactory)
select t;

static IEnumerable<ITestCaseData> CreateTestCases(MethodInfo methodDefinition, bool canBeNull, Func<MethodInfo, object?[], string, Action> testCaseFactory)
static IEnumerable<TestCaseData> CreateTestCases(MethodInfo methodDefinition, bool canBeNull, Func<MethodInfo, object?[], string, Action> testCaseFactory)
{
var method = InstantiateMethod(methodDefinition);
var parameters = method.GetParameters().ToList();
Expand All @@ -82,7 +81,7 @@ where IsReferenceType(param) && CanBeNull(param) == canBeNull
param.Name ?? throw new NullReferenceException())
#pragma warning restore CA2201 // Do not raise reserved exception types
let testName = GetTestName(methodDefinition, param)
select (ITestCaseData)new TestCaseData(testCase).SetName(testName);
select new TestCaseData(testCase).SetName(testName);
}

static string GetTestName(MethodInfo definition, ParameterInfo parameter) =>
Expand Down
3 changes: 1 addition & 2 deletions MoreLinq.Test/OrderedMergeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ namespace MoreLinq.Test
{
using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.Interfaces;

[TestFixture]
public class OrderedMergeTest
{
public static readonly IEnumerable<ITestCaseData> TestData =
public static readonly IEnumerable<TestCaseData> TestData =
from e in new[]
{
new
Expand Down
3 changes: 1 addition & 2 deletions MoreLinq.Test/PadStartTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ namespace MoreLinq.Test
using System;
using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.Interfaces;

[TestFixture]
public class PadStartTest
{
static readonly IEnumerable<ITestCaseData> PadStartWithNegativeWidthCases =
static readonly IEnumerable<TestCaseData> PadStartWithNegativeWidthCases =
from e in new (string Name, TestDelegate Delegate)[]
{
("DefaultPadding" , static () => new object[0].PadStart(-1)),
Expand Down
3 changes: 1 addition & 2 deletions MoreLinq.Test/PadTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ namespace MoreLinq.Test
using System;
using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.Interfaces;

[TestFixture]
public class PadTest
{
static readonly IEnumerable<ITestCaseData> PadNegativeWidthCases =
static readonly IEnumerable<TestCaseData> PadNegativeWidthCases =
from e in new (string Name, TestDelegate Delegate)[]
{
("DefaultPadding" , static () => new object[0].Pad(-1)),
Expand Down
3 changes: 1 addition & 2 deletions MoreLinq.Test/PrependTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace MoreLinq.Test
{
using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using static MoreLinq.Extensions.PrependExtension;

[TestFixture]
Expand Down Expand Up @@ -64,7 +63,7 @@ public int[] PrependMany(int[] head, int[] tail)
return tail.Aggregate(head.AsEnumerable(), MoreEnumerable.Prepend).ToArray();
}

public static IEnumerable<ITestCaseData> PrependManySource =>
public static IEnumerable<TestCaseData> PrependManySource =>
from x in Enumerable.Range(0, 11)
from y in Enumerable.Range(1, 11)
select new
Expand Down
3 changes: 1 addition & 2 deletions MoreLinq.Test/ReturnTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace MoreLinq.Test
using System;
using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.Interfaces;

public class ReturnTest
{
Expand Down Expand Up @@ -136,7 +135,7 @@ public void TestIndexOfAnItemNotContainedIsNegativeOne()
Assert.That(SomeSingleton.List.IndexOf(new object()), Is.EqualTo(-1));
}

static IEnumerable<ITestCaseData> UnsupportedActions(string testName) =>
static IEnumerable<TestCaseData> UnsupportedActions(string testName) =>
from ma in new (string MethodName, Action Action)[]
{
("Add" , () => SomeSingleton.List.Add(new object())),
Expand Down
3 changes: 1 addition & 2 deletions MoreLinq.Test/SkipUntilTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace MoreLinq.Test
{
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using System.Collections.Generic;

[TestFixture]
Expand Down Expand Up @@ -60,7 +59,7 @@ public void SkipUntilEvaluatesPredicateLazily()
sequence.AssertSequenceEqual(0, 1, 2);
}

public static readonly IEnumerable<ITestCaseData> TestData =
public static readonly IEnumerable<TestCaseData> TestData =
from e in new[]
{
new { Source = new int[0] , Min = 0, Expected = new int[0] }, // empty sequence
Expand Down
7 changes: 3 additions & 4 deletions MoreLinq.Test/TrySingleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace MoreLinq.Test
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using Experimental;

[TestFixture]
Expand Down Expand Up @@ -64,10 +63,10 @@ public void TrySingleWithSingletonCollection<T>(IEnumerable<T> source, T result)
Assert.That(value, Is.EqualTo(result));
}

static readonly ITestCaseData[] SingletonCollectionTestCases =
static readonly TestCaseData[] SingletonCollectionTestCases =
[
new TestCaseData(new BreakingSingleElementCollection<int>(10), 10),
new TestCaseData(new BreakingSingleElementReadOnlyCollection<int>(20), 20)
new(new BreakingSingleElementCollection<int>(10), 10),
new(new BreakingSingleElementReadOnlyCollection<int>(20), 20)
];

class BreakingSingleElementCollectionBase<T> : IEnumerable<T>
Expand Down
3 changes: 1 addition & 2 deletions MoreLinq.Test/ZipLongestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ namespace MoreLinq.Test
using System;
using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using Tuple = System.ValueTuple;

[TestFixture]
public class ZipLongestTest
{
public static readonly IEnumerable<ITestCaseData> TestData =
public static readonly IEnumerable<TestCaseData> TestData =
from e in new[]
{
new { A = Seq<int>( ), B = Seq("foo", "bar", "baz"), Result = Seq<(int, string?)>((0, "foo"), (0, "bar"), (0, "baz")) },
Expand Down

0 comments on commit c1d0d46

Please sign in to comment.