Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/snippets/Snippets.NUnit/AttributeExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void AnotherManualTest()
[TestFixture]
public class TimeoutAttributeExamples
{
#pragma warning disable CS0618 // Type or member is obsolete[Explicit("This doesnt work on .net, only .netframework")]
#pragma warning disable CS0618 // Type or member is obsolete[Explicit("This doesn't work on .net, only .netframework")]
#region TimeoutExample
[Test]
[Timeout(1000)] // 1 second timeout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void RunningTestUntilCanceled(CancellationToken cancellationToken)
#endregion

#region TestCaseSourceWithCancellationToken
private static int[] _simpleValues = { 2, 4, 6, 8 };
private static int[] _simpleValues = [2, 4, 6, 8];

[TestCaseSource(nameof(_simpleValues)), CancelAfter(1_000)]
public void TestCaseSourceWithCancellationToken(int a, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework;

namespace Snippets.NUnit.Attributes;

Expand All @@ -19,7 +14,7 @@ public void TestMethod1()
}
#endregion

private int count1 = 0;
private int count1;
#region RepeatWithFaultAndOutputAttributeExample
[Test, Explicit("Issue 5031 must be fixed")]
[Repeat(5, StopOnFailure = false)]
Expand All @@ -34,7 +29,7 @@ public void TestMethod2()

#region RepeatWithFaultAttributeExample

private int count2 = 0;
private int count2;

[Test,Explicit] // Marking the test as Explicit to avoid failing our doc build. You can skip this.
[Repeat(5, StopOnFailure = false)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Threading.Tasks;
using NUnit.Framework;

namespace Snippets.NUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ public ParameterizedTestFixture(params char[] eqArguments)
{
_eq1 = eqArguments[0].ToString();
_eq2 = eqArguments[1].ToString();
if (eqArguments.Length > 2)
_neq = eqArguments[2].ToString();
else
_neq = null;
_neq = eqArguments.Length > 2
? eqArguments[2].ToString()
: null;
}

[Test]
Expand Down Expand Up @@ -121,8 +120,8 @@ public void TestMyArgTypes(T1 t1, T2 t2)
#endregion

#region SpecifyTypeArgsSeparately
[TestFixture(100.0, 42, TypeArgs = new[] { typeof(double), typeof(int) })]
[TestFixture(42, 100.0, TypeArgs = new[] { typeof(int), typeof(double) })]
[TestFixture(100.0, 42, TypeArgs = [typeof(double), typeof(int)])]
[TestFixture(42, 100.0, TypeArgs = [typeof(int), typeof(double)])]
public class SpecifyTypeArgsSeparately<T1, T2>
where T1 : notnull
where T2 : notnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ public MyTestClass(string word, int num) { /* ... */ }

/* Tests */

static object[] FixtureArgs = {
static object[] FixtureArgs =
[
new object[] { "Question", 1 },
new object[] { "Answer", 42 }
};
];
}
#endregion
}
Expand All @@ -34,10 +35,11 @@ public MyTestClass(string word, int num) { /* ... */ }

public class AnotherClass
{
public static object[] FixtureArgs = {
public static object[] FixtureArgs =
[
new object[] { "Question", 1 },
new object[] { "Answer", 42 }
};
];
}
#endregion
}
Expand Down
28 changes: 14 additions & 14 deletions docs/snippets/Snippets.NUnit/ClassicAssertExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void Contains_Examples()
var list = new List<int> { 1, 2, 3, 4, 5 };
ClassicAssert.Contains(3, list);

var array = new string[] { "apple", "banana", "cherry" };
var array = new[] { "apple", "banana", "cherry" };
ClassicAssert.Contains("banana", array);
}
#endregion
Expand Down Expand Up @@ -188,7 +188,7 @@ public void Empty_Examples()
ClassicAssert.IsEmpty(new List<string>());

ClassicAssert.IsNotEmpty("Hello");
ClassicAssert.IsNotEmpty(new int[] { 1, 2, 3 });
ClassicAssert.IsNotEmpty(new[] { 1, 2, 3 });
ClassicAssert.IsNotEmpty(new List<string> { "item" });
}
#endregion
Expand Down Expand Up @@ -227,10 +227,10 @@ public class CollectionAssertExamples
[Test]
public void CollectionAssert_Basic_Examples()
{
var list1 = new int[] { 1, 2, 3 };
var list2 = new int[] { 1, 2, 3 };
var list3 = new int[] { 3, 2, 1 };
var list4 = new int[] { 1, 2, 4 };
var list1 = new[] { 1, 2, 3 };
var list2 = new[] { 1, 2, 3 };
var list3 = new[] { 3, 2, 1 };
var list4 = new[] { 1, 2, 4 };

// Collections are equal (same order)
CollectionAssert.AreEqual(list1, list2);
Expand All @@ -250,7 +250,7 @@ public void CollectionAssert_Basic_Examples()
[Test]
public void CollectionAssert_Contains_Examples()
{
var list = new int[] { 1, 2, 3, 4, 5 };
var list = new[] { 1, 2, 3, 4, 5 };

CollectionAssert.Contains(list, 3);
CollectionAssert.DoesNotContain(list, 10);
Expand All @@ -261,9 +261,9 @@ public void CollectionAssert_Contains_Examples()
[Test]
public void CollectionAssert_Subset_Examples()
{
var superset = new int[] { 1, 2, 3, 4, 5 };
var subset = new int[] { 2, 4 };
var notSubset = new int[] { 1, 6 };
var superset = new[] { 1, 2, 3, 4, 5 };
var subset = new[] { 2, 4 };
var notSubset = new[] { 1, 6 };

CollectionAssert.IsSubsetOf(subset, superset);
CollectionAssert.IsNotSubsetOf(notSubset, superset);
Expand All @@ -275,7 +275,7 @@ public void CollectionAssert_Subset_Examples()
public void CollectionAssert_Empty_Examples()
{
var emptyList = new int[] { };
var nonEmptyList = new int[] { 1, 2, 3 };
var nonEmptyList = new[] { 1, 2, 3 };

CollectionAssert.IsEmpty(emptyList);
CollectionAssert.IsNotEmpty(nonEmptyList);
Expand All @@ -286,8 +286,8 @@ public void CollectionAssert_Empty_Examples()
[Test]
public void CollectionAssert_Ordered_Examples()
{
var orderedList = new int[] { 1, 2, 3, 4, 5 };
var reverseOrderedList = new int[] { 5, 4, 3, 2, 1 };
var orderedList = new[] { 1, 2, 3, 4, 5 };
var reverseOrderedList = new[] { 5, 4, 3, 2, 1 };

CollectionAssert.IsOrdered(orderedList);
CollectionAssert.IsOrdered(reverseOrderedList, Comparer<int>.Create((x, y) => y.CompareTo(x)));
Expand All @@ -300,7 +300,7 @@ public void CollectionAssert_Ordered_Examples()
[Test]
public void CollectionAssert_ItemType_Examples()
{
var stringList = new string[] { "a", "b", "c" };
var stringList = new[] { "a", "b", "c" };
var mixedList = new object[] { "string", 123, null };

CollectionAssert.AllItemsAreInstancesOfType(stringList, typeof(string));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ClassicVsConstraintAssertions
public void TheTest()
{
#region ConstraintWithoutClassicEquivalent
int[] array = { 1, 2, 3 };
int[] array = [1, 2, 3];
Assert.That(array, Has.Exactly(1).EqualTo(3));
Assert.That(array, Has.Exactly(2).GreaterThan(1));
Assert.That(array, Has.Exactly(3).LessThan(100));
Expand Down
1 change: 0 additions & 1 deletion docs/snippets/Snippets.NUnit/CustomConstraints.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using NUnit.Framework;
using NUnit.Framework.Constraints;
using static Snippets.NUnit.CustomConstraints;

Expand Down
4 changes: 2 additions & 2 deletions docs/snippets/Snippets.NUnit/TestCaseDataExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public void ExplicitTypeArgs<T>(T input)

private static IEnumerable<TestCaseData> ExplicitTypeArgsTestCases()
{
yield return new TestCaseData(2) { TypeArgs = new[] { typeof(long) } };
yield return new TestCaseData(2L) { TypeArgs = new[] { typeof(long) } };
yield return new TestCaseData(2) { TypeArgs = [typeof(long)] };
yield return new TestCaseData(2L) { TypeArgs = [typeof(long)] };
}
}
#endregion
Expand Down
6 changes: 3 additions & 3 deletions docs/snippets/Snippets.NUnit/TestCaseSourceExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public void DivideTest(int n, int d, int q)
}

public static object[] DivideCases =
{
[
new object[] { 12, 3, 4 },
new object[] { 12, 2, 6 },
new object[] { 12, 4, 3 }
};
];
}
#endregion
#region ParameterizedSource
Expand Down Expand Up @@ -130,7 +130,7 @@ public void TestOfPersonAge((Person P, bool Expected) td)
Assert.That(res, Is.EqualTo(td.Expected));
}

public static IEnumerable<(Person, bool)> TestCases()
private static IEnumerable<(Person, bool)> TestCases()
{
yield return (new Person { Name = "John", Age = 10 }, false);
yield return (new Person { Name = "Jane", Age = 30 }, true);
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/Snippets.NUnitLite/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void IgnoredTest()
[Test]
public void FailingTest()
{
Assert.That(()=>Assert.Fail(),Throws.TypeOf<AssertionException>());
Assert.That(Assert.Fail,Throws.TypeOf<AssertionException>());
}


Expand Down
2 changes: 2 additions & 0 deletions docs/snippets/Snippets.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=netframework/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Loading