Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from NUnit 3 to NUnit 4 #783

Merged
merged 2 commits into from
May 1, 2024
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
5 changes: 3 additions & 2 deletions tests/NSubstitute.Acceptance.Specs/AutoValuesForSubs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs;

Expand Down Expand Up @@ -109,8 +110,8 @@ public void Should_auto_return_an_empty_string_from_a_func_that_returns_a_string
public void Should_auto_return_for_iqueryable()
{
var sample = Substitute.For<ISample>();
Assert.IsEmpty(sample.Queryable().Select(x => x + 1).ToList());
Assert.NotNull(sample.Queryable().Expression);
ClassicAssert.IsEmpty(sample.Queryable().Select(x => x + 1).ToList());
ClassicAssert.NotNull(sample.Queryable().Expression);
}

[Test]
Expand Down
29 changes: 15 additions & 14 deletions tests/NSubstitute.Acceptance.Specs/CallbackCalling.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NSubstitute.Acceptance.Specs.Infrastructure;
using NSubstitute.Core;
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs;

Expand Down Expand Up @@ -119,7 +120,7 @@ public void FirstIsRunOnce()
Assert.That(callCount, Is.EqualTo(0), "Should not have been called yet");
_something.Count();
_something.Count();
Assert.AreEqual(new List<int> { 1 }, calls);
ClassicAssert.AreEqual(new List<int> { 1 }, calls);
}

[Test]
Expand All @@ -132,7 +133,7 @@ public void AlwaysIsCalledAlways()
Assert.That(callCount, Is.EqualTo(0), "Should not have been called yet");
_something.Count();
_something.Count();
Assert.AreEqual(new List<int> { 1, 2 }, calls);
ClassicAssert.AreEqual(new List<int> { 1, 2 }, calls);
}

[Test]
Expand All @@ -149,7 +150,7 @@ public void ThenIsCalledAfterFirst()
Assert.That(callCount, Is.EqualTo(0), "Should not have been called yet");
_something.Count();
_something.Count();
Assert.AreEqual(new List<int> { 1, 2 }, calls);
ClassicAssert.AreEqual(new List<int> { 1, 2 }, calls);
}

[Test]
Expand All @@ -166,11 +167,11 @@ public void TwoThensAreCalledInRightOrderAfterFirst()
);

_something.Count();
Assert.IsTrue(first);
ClassicAssert.IsTrue(first);
_something.Count();
Assert.IsTrue(then);
ClassicAssert.IsTrue(then);
_something.Count();
Assert.IsTrue(secondThen);
ClassicAssert.IsTrue(secondThen);
}

[Test]
Expand All @@ -187,11 +188,11 @@ public void AlwaysIsCalledEvenIfFirstAndThenIsDefined()
);

_something.Count();
Assert.IsTrue(first);
ClassicAssert.IsTrue(first);
_something.Count();
Assert.IsTrue(then);
ClassicAssert.IsTrue(then);
_something.Count();
Assert.AreEqual(3, callCount);
ClassicAssert.AreEqual(3, callCount);
}

[Test]
Expand All @@ -208,10 +209,10 @@ public void ThenIsCalledAfterFirstThrow()

Assert.That(callCount, Is.EqualTo(0), "Should not have been called yet");
var ex = Assert.Throws<Exception>(() => _something.Count());
Assert.AreSame(exception, ex);
ClassicAssert.AreSame(exception, ex);

_something.Count();
Assert.AreEqual(new List<int> { 1 }, calls);
ClassicAssert.AreEqual(new List<int> { 1 }, calls);
}

[Test]
Expand All @@ -230,10 +231,10 @@ public void ThenIsCalledAfterThenThrow()
Assert.That(callCount, Is.EqualTo(0), "Should not have been called yet");
_something.Count();
var ex = Assert.Throws<Exception>(() => _something.Count());
Assert.AreSame(exception, ex);
ClassicAssert.AreSame(exception, ex);

_something.Count();
Assert.AreEqual(new List<int> { 1, 2 }, calls);
ClassicAssert.AreEqual(new List<int> { 1, 2 }, calls);
}

[Test]
Expand All @@ -250,7 +251,7 @@ public void AlwaysIsCalledEvenThrowIfIsDefined()

Assert.Throws<Exception>(() => _something.Count());
Assert.Throws<Exception>(() => _something.Count());
Assert.AreEqual(2, callCount);
ClassicAssert.AreEqual(2, callCount);
}

[Test]
Expand Down
5 changes: 3 additions & 2 deletions tests/NSubstitute.Acceptance.Specs/ClearSubstitute.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NSubstitute.ClearExtensions;
using NSubstitute.Exceptions;
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs;

Expand Down Expand Up @@ -40,7 +41,7 @@ public void Clear_results()
var substitute = Substitute.For<ICalculator>();
substitute.Add(1, 1).Returns(12);
substitute.ClearSubstitute(ClearOptions.ReturnValues);
Assert.AreEqual(0, substitute.Add(1, 1));
ClassicAssert.AreEqual(0, substitute.Add(1, 1));
}

[Test]
Expand All @@ -53,6 +54,6 @@ public void Clear_callbacks()
substitute.Add(1, 1);
substitute.Add(1, 1);
substitute.Add(1, 1);
Assert.AreEqual(0, count);
ClassicAssert.AreEqual(0, count);
}
}
9 changes: 5 additions & 4 deletions tests/NSubstitute.Acceptance.Specs/CompatArgsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Reflection;
using NSubstitute.Compatibility;
using NSubstitute.Compatibility;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using System.Reflection;

namespace NSubstitute.Acceptance.Specs;

Expand All @@ -17,7 +18,7 @@ public void CompatAndCompatArgInstanceShouldBeInSync()
var compatInstanceMembers =
typeof(CompatArg).GetMethods(flags).Select(DescribeMethod).OrderBy(x => x);

Assert.AreEqual(
ClassicAssert.AreEqual(
compatMembers.ToList(), compatInstanceMembers.ToList(),
"Arg.Compat and CompatArg should have static/instance versions of the same methods"
);
Expand All @@ -32,7 +33,7 @@ public void CompatAndArgShouldBeInSync()
var compatMembers =
typeof(Arg.Compat).GetMethods(flags).Select(DescribeMethod).OrderBy(x => x);

Assert.AreEqual(
ClassicAssert.AreEqual(
argMembers.ToList(), compatMembers.ToList(),
"Arg and Arg.Compat should have the same methods (just vary by out/ref)"
);
Expand Down
9 changes: 5 additions & 4 deletions tests/NSubstitute.Acceptance.Specs/EventChecking.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NSubstitute.Exceptions;
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs;

Expand All @@ -25,7 +26,7 @@ public void Check_if_nullHandlers_are_ignored()
source.Started += () => raised = true;
source.Started += Raise.Event<Action>();

Assert.IsTrue(raised);
ClassicAssert.IsTrue(raised);
}

[Test]
Expand All @@ -40,9 +41,9 @@ public void Check_if_multiple_handlers_get_called()
source.Started += () => raised3 = true;
source.Started += Raise.Event<Action>();

Assert.IsTrue(raised1, "The first handler was not called");
Assert.IsTrue(raised2, "The second handler was not called");
Assert.IsTrue(raised3, "The third handler was not called");
ClassicAssert.IsTrue(raised1, "The first handler was not called");
ClassicAssert.IsTrue(raised2, "The second handler was not called");
ClassicAssert.IsTrue(raised3, "The third handler was not called");
}

public interface IEngine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs.FieldReports;

Expand All @@ -10,8 +11,8 @@ public void Equals_should_work_as_expected_for_class_substitutes()
var firstSub = Substitute.For<AClass>();
var secondSub = Substitute.For<AClass>();

Assert.AreEqual(firstSub, firstSub);
Assert.AreNotEqual(firstSub, secondSub);
ClassicAssert.AreEqual(firstSub, firstSub);
ClassicAssert.AreNotEqual(firstSub, secondSub);
}

public class AClass { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NSubstitute.Acceptance.Specs.Infrastructure;
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs.FieldReports;

Expand All @@ -16,11 +17,11 @@ public void ShouldNotUseTheConfiguredValueDuringSubsequentSetup()
target.Echo(Arg.Is(1)).Returns("10", "11", "12");

// Assert
Assert.AreEqual("00", target.Echo(0));
Assert.AreEqual("10", target.Echo(1));
Assert.AreEqual("01", target.Echo(0));
Assert.AreEqual("11", target.Echo(1));
Assert.AreEqual("02", target.Echo(0));
Assert.AreEqual("12", target.Echo(1));
ClassicAssert.AreEqual("00", target.Echo(0));
ClassicAssert.AreEqual("10", target.Echo(1));
ClassicAssert.AreEqual("01", target.Echo(0));
ClassicAssert.AreEqual("11", target.Echo(1));
ClassicAssert.AreEqual("02", target.Echo(0));
ClassicAssert.AreEqual("12", target.Echo(1));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs.FieldReports;

Expand All @@ -15,6 +16,6 @@ public void DelegateReturnsOutParameter()

foo(out bar);

Assert.AreEqual(42, bar);
ClassicAssert.AreEqual(42, bar);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs.FieldReports;

Expand All @@ -24,7 +25,7 @@ public void ReturnsMultipleValuesInParallel()

var results = Task.WhenAll(runningTask1, runningTask2).Result;

Assert.Contains(ret1, results);
Assert.Contains(ret2, results);
ClassicAssert.Contains(ret1, results);
ClassicAssert.Contains(ret2, results);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NSubstitute.Acceptance.Specs.Infrastructure;
using NSubstitute.ExceptionExtensions;
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs.FieldReports;

Expand Down Expand Up @@ -29,7 +30,7 @@ public void ShouldBePossibleToReConfigureThrowingConfiguration()

// Assert
Assert.Throws<InvalidOperationException>(() => deliver.Send(new Message1()));
Assert.AreSame(response, deliver.Send(new Message2()));
ClassicAssert.AreSame(response, deliver.Send(new Message2()));
}

[Test]
Expand All @@ -44,6 +45,6 @@ public void ShouldBePossibleToConfigureConstantAfterThrowForAny()

// Assert
Assert.Throws<InvalidOperationException>(() => something.Echo(100));
Assert.AreEqual("42", something.Echo(42));
ClassicAssert.AreEqual("42", something.Echo(42));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs.FieldReports;

Expand All @@ -22,6 +23,6 @@ public interface X
public void Should_create_substitute()
{
var sut = Substitute.For<X>();
Assert.NotNull(sut);
ClassicAssert.NotNull(sut);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs.FieldReports;

Expand All @@ -21,9 +22,9 @@ public void Returns_and_arg_do_for_method()
sub.Say("hello").Returns("world");
var resultOfHowdy = sub.Say("howdy");

Assert.AreEqual("", resultOfHowdy);
Assert.AreEqual("howdy", lastArgUsedInCallToSayMethod);
Assert.AreEqual("world", sub.Say("hello"));
ClassicAssert.AreEqual("", resultOfHowdy);
ClassicAssert.AreEqual("howdy", lastArgUsedInCallToSayMethod);
ClassicAssert.AreEqual("world", sub.Say("hello"));
}

[Test]
Expand All @@ -36,8 +37,8 @@ public void Returns_and_arg_do_for_property()
sub.Name = "Jane";
sub.Name.Returns("Bob");

Assert.AreEqual("Jane", name);
Assert.AreEqual("Bob", sub.Name);
ClassicAssert.AreEqual("Jane", name);
ClassicAssert.AreEqual("Bob", sub.Name);
}

[Test]
Expand All @@ -51,7 +52,7 @@ public void Returns_and_when_do()

sub.Name.Returns("Bob");

Assert.AreEqual("Jane", name);
Assert.AreEqual("Bob", sub.Name);
ClassicAssert.AreEqual("Jane", name);
ClassicAssert.AreEqual("Bob", sub.Name);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs.FieldReports;

Expand All @@ -12,6 +13,6 @@ public void Stub_any_string_and_call_with_null()
var foo = Substitute.For<IFoo>();
foo.Bar(Arg.Any<string>(), Arg.Any<double>()).ReturnsForAnyArgs("hello");

Assert.AreEqual("hello", foo.Bar(null, 0));
ClassicAssert.AreEqual("hello", foo.Bar(null, 0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions tests/NSubstitute.Acceptance.Specs/OutAndRefParameters.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NSubstitute.Exceptions;
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace NSubstitute.Acceptance.Specs;

Expand Down
Loading
Loading