Skip to content

Fix NUnit2050 warnings #3522

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

Merged
merged 15 commits into from
Apr 7, 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
2 changes: 0 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ dotnet_diagnostic.NUnit2006.severity = suggestion
dotnet_diagnostic.NUnit2015.severity = suggestion
dotnet_diagnostic.NUnit2031.severity = suggestion
dotnet_diagnostic.NUnit2049.severity = suggestion
# NUnit 4 no longer supports string.Format specification for Assert
dotnet_diagnostic.NUnit2050.severity = suggestion
# The SameAs constraint always fails on value types as the actual and the expected value cannot be the same reference
dotnet_diagnostic.NUnit2040.severity = suggestion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public async Task MultiCriteriaAsync()
{
var driver = Sfi.ConnectionProvider.Driver;
if (!driver.SupportsMultipleQueries)
Assert.Ignore("Driver {0} does not support multi-queries", driver.GetType().FullName);
Assert.Ignore($"Driver {driver.GetType().FullName} does not support multi-queries");

await (SetupPagingDataAsync());

Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/Criteria/ProjectionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public async Task UsingSqlFunctions_Concat_WithCastAsync()
{
if(Dialect is Oracle8iDialect)
{
Assert.Ignore("Not supported by the active dialect:{0}.", Dialect);
Assert.Ignore($"Not supported by the active dialect:{Dialect}.");
}
if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters)
Assert.Ignore("Current dialect does not support this test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ public async Task FetchModeEagerForEagerAsync()
private void SkipFutureTestIfNotSupported()
{
if (Sfi.ConnectionProvider.Driver.SupportsMultipleQueries == false)
Assert.Ignore("Driver {0} does not support multi-queries", Sfi.ConnectionProvider.Driver.GetType().FullName);
Assert.Ignore($"Driver {Sfi.ConnectionProvider.Driver.GetType().FullName} does not support multi-queries");
}

#region Test Setup
Expand Down
19 changes: 9 additions & 10 deletions src/NHibernate.Test/Async/Extralazy/ExtraLazyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public async Task ListAddAsync(bool initialize)
// Have to skip unloaded (non-queued indeed) elements to avoid triggering existence queries on them.
foreach (var item in addedItems.Skip(5))
{
Assert.That(gavin.Companies.Contains(item), Is.True, "Company '{0}' existence", item.Name);
Assert.That(gavin.Companies.Contains(item), Is.True, $"Company '{item.Name}' existence");
}

Assert.That(Sfi.Statistics.FlushCount, Is.EqualTo(0), "Flushes count after checking existence of non-flushed");
Expand Down Expand Up @@ -322,7 +322,7 @@ public async Task ListInsertAsync(bool initialize)
// Have to skip unloaded (non-queued indeed) elements to avoid triggering existence queries on them.
foreach (var item in addedItems.Skip(5))
{
Assert.That(gavin.Companies.Contains(item), Is.True, "Company '{0}' existence", item.Name);
Assert.That(gavin.Companies.Contains(item), Is.True, $"Company '{item.Name}' existence");
}

Assert.That(Sfi.Statistics.FlushCount, Is.EqualTo(0), "Flushes count after existence check");
Expand Down Expand Up @@ -636,7 +636,7 @@ public async Task ListGetSetAsync(bool initialize)
Sfi.Statistics.Clear();
for (var i = 0; i < 10; i++)
{
Assert.That(gavin.Companies[i], Is.EqualTo(addedItems[i]), "Comparing added company at index {0}", i);
Assert.That(gavin.Companies[i], Is.EqualTo(addedItems[i]), $"Comparing added company at index {i}");
}

Assert.That(Sfi.Statistics.FlushCount, Is.EqualTo(0), "Flushes count after adding comparing");
Expand Down Expand Up @@ -676,7 +676,7 @@ public async Task ListGetSetAsync(bool initialize)
Sfi.Statistics.Clear();
for (var i = 0; i < 10; i++)
{
Assert.That(gavin.Companies[i].ListIndex, Is.EqualTo(finalIndexOrder[i]), "Comparing company ListIndex at index {0}", i);
Assert.That(gavin.Companies[i].ListIndex, Is.EqualTo(finalIndexOrder[i]), $"Comparing company ListIndex at index {i}");
}

Assert.That(Sfi.Statistics.FlushCount, Is.EqualTo(0), "Flushes count after comparing");
Expand Down Expand Up @@ -798,7 +798,7 @@ public async Task ListFlushAsync(bool initialize)
{
for (var i = 15; i < 20; i++)
{
Assert.That(gavin.Companies.Remove(addedItems[i]), Is.True, "Removing transient company at index {0}", i);
Assert.That(gavin.Companies.Remove(addedItems[i]), Is.True, $"Removing transient company at index {i}");
}

Assert.That(FindAllOccurrences(sqlLog.GetWholeLog(), "INSERT \n INTO"), Is.EqualTo(10), "Statements count after removing");
Expand Down Expand Up @@ -909,7 +909,7 @@ public async Task ListFlushAsync(bool initialize)

for (var i = 0; i < gavin.Companies.Count; i++)
{
Assert.That(gavin.Companies[i].ListIndex, Is.EqualTo(i), "Comparing company ListIndex at index {0}", i);
Assert.That(gavin.Companies[i].ListIndex, Is.EqualTo(i), $"Comparing company ListIndex at index {i}");
}

if (initialize)
Expand Down Expand Up @@ -1049,7 +1049,7 @@ public async Task ListClearAsync(bool initialize)
Assert.That(collection.Count, Is.EqualTo(6), "Credit cards count after loading again Gavin");
for (var i = 0; i < 10; i++)
{
Assert.That(collection.Contains(addedItems[i]), i < 6 ? Is.True : (IResolveConstraint) Is.False, "Checking existence for item at {0}", i);
Assert.That(collection.Contains(addedItems[i]), i < 6 ? Is.True : (IResolveConstraint) Is.False, $"Checking existence for item at {i}");
}

Assert.That(NHibernateUtil.IsInitialized(collection), Is.False, "Credit cards initialization status after loading again");
Expand Down Expand Up @@ -1140,7 +1140,7 @@ public async Task ListIndexOperationsAsync(bool initialize)

for (var i = 0; i < gavin.Companies.Count; i++)
{
Assert.That(gavin.Companies[i].OriginalIndex, Is.EqualTo(finalIndexOrder[i]), "Comparing company index at {0}", i);
Assert.That(gavin.Companies[i].OriginalIndex, Is.EqualTo(finalIndexOrder[i]), $"Comparing company index at {i}");
}

if (initialize)
Expand Down Expand Up @@ -1882,8 +1882,7 @@ public async Task SetClearAsync(bool initialize)
Assert.That(collection.Count, Is.EqualTo(6), "Permissions count after loading again Gavin");
for (var i = 0; i < 10; i++)
{
Assert.That(collection.Contains(addedItems[i]), i < 6 ? Is.True : (IResolveConstraint) Is.False,
"Checking existence of added element at {0}", i);
Assert.That(collection.Contains(addedItems[i]), i < 6 ? Is.True : (IResolveConstraint) Is.False, $"Checking existence of added element at {i}");
}

Assert.That(NHibernateUtil.IsInitialized(collection), Is.False, "Permissions initialization status after loading again");
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/Hql/Ast/BulkManipulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ public async Task SimpleDeleteOnAnimalAsync()
{
if (Dialect.HasSelfReferentialForeignKeyBug)
{
Assert.Ignore("self referential FK bug", "HQL delete testing");
Assert.Ignore("self referential FK bug - HQL delete testing");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task ReturnedValueIsGuidAsync()
}
catch (NotSupportedException)
{
Assert.Ignore("This test does not apply to {0}", Dialect.Dialect.GetDialect());
Assert.Ignore($"This test does not apply to {Dialect.Dialect.GetDialect()}");
}

var gen = new NativeGuidGenerator();
Expand Down
8 changes: 4 additions & 4 deletions src/NHibernate.Test/Async/Linq/FunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ where lowerName.IndexOf('a') == 0
select lowerName;
var result = await (query.ToListAsync());

Assert.That(result, Is.EqualTo(expected), "Expected {0} but was {1}", string.Join("|", expected), string.Join("|", result));
Assert.That(result, Is.EqualTo(expected), $"Expected {string.Join("|", expected)} but was {string.Join("|", result)}");
await (ObjectDumper.WriteAsync(query));
}

Expand All @@ -220,7 +220,7 @@ where lowerName.IndexOf('a', 2) == -1
select lowerName;
var result = await (query.ToListAsync());

Assert.That(result, Is.EqualTo(expected), "Expected {0} but was {1}", string.Join("|", expected), string.Join("|", result));
Assert.That(result, Is.EqualTo(expected), $"Expected {string.Join("|", expected)} but was {string.Join("|", result)}");
await (ObjectDumper.WriteAsync(query));
}

Expand All @@ -236,7 +236,7 @@ where lowerName.IndexOf("an") == 0
select lowerName;
var result = await (query.ToListAsync());

Assert.That(result, Is.EqualTo(expected), "Expected {0} but was {1}", string.Join("|", expected), string.Join("|", result));
Assert.That(result, Is.EqualTo(expected), $"Expected {string.Join("|", expected)} but was {string.Join("|", result)}");
await (ObjectDumper.WriteAsync(query));
}

Expand All @@ -252,7 +252,7 @@ where lowerName.Contains("a")
select lowerName.IndexOf("a", 1);
var result = await (query.ToListAsync());

Assert.That(result, Is.EqualTo(expected), "Expected {0} but was {1}", string.Join("|", expected), string.Join("|", result));
Assert.That(result, Is.EqualTo(expected), $"Expected {string.Join("|", expected)} but was {string.Join("|", result)}");
await (ObjectDumper.WriteAsync(query));
}

Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/NHSpecificTest/NH1253/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public async Task MultiQuerySingleInListAsync()
{
var driver = Sfi.ConnectionProvider.Driver;
if (!driver.SupportsMultipleQueries)
Assert.Ignore("Driver {0} does not support multi-queries", driver.GetType().FullName);
Assert.Ignore($"Driver {driver.GetType().FullName} does not support multi-queries");

using (var s = OpenSession())
using (var tx = s.BeginTransaction())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public async Task LoadEntityCollectionWithCustomLoaderAsync()
[Test]
public async Task NativeUpdateQueryWithoutResultsAsync()
{
Assume.That(Dialect, Is.InstanceOf<MsSql2000Dialect>(), "This does not apply to {0}", Dialect);
Assume.That(Dialect, Is.InstanceOf<MsSql2000Dialect>(), $"This does not apply to {Dialect}");
Assume.That(WithQueryCache, Is.False, "This test does not use a cacheable query.");
using (ISession session = OpenSession())
{
Expand All @@ -259,7 +259,7 @@ public async Task NativeUpdateQueryWithoutResultsAsync()
[Test]
public async Task NativeScalarQueryWithoutResultsAsync()
{
Assume.That(Dialect, Is.InstanceOf<MsSql2000Dialect>(), "This does not apply to {0}", Dialect);
Assume.That(Dialect, Is.InstanceOf<MsSql2000Dialect>(), $"This does not apply to {Dialect}");
Assume.That(WithQueryCache, Is.False, "This test does not use a cacheable query.");
using (ISession session = OpenSession())
{
Expand All @@ -278,7 +278,7 @@ public async Task NativeScalarQueryWithUndefinedResultsetAsync()
{
if (!(Dialect is MsSql2000Dialect))
{
Assert.Ignore("This does not apply to {0}", Dialect);
Assert.Ignore($"This does not apply to {Dialect}");
}
using (ISession session = OpenSession())
{
Expand All @@ -301,7 +301,7 @@ public async Task NativeScalarQueryWithDefinedResultsetAsync()
{
if (!(Dialect is MsSql2000Dialect))
{
Assert.Ignore("This does not apply to {0}", Dialect);
Assert.Ignore($"This does not apply to {Dialect}");
}
using (ISession session = OpenSession())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public async Task MultiCriteriaQueriesWithIntsShouldExecuteCorrectlyAsync()
{
var driver = Sfi.ConnectionProvider.Driver;
if (!driver.SupportsMultipleQueries)
Assert.Ignore("Driver {0} does not support multi-queries", driver.GetType().FullName);
Assert.Ignore($"Driver {driver.GetType().FullName} does not support multi-queries");

// Test querying IntData
using (ISession session = this.OpenSession())
Expand Down Expand Up @@ -131,7 +131,7 @@ public async Task MultiCriteriaQueriesWithStringsShouldExecuteCorrectlyAsync()
{
var driver = Sfi.ConnectionProvider.Driver;
if (!driver.SupportsMultipleQueries)
Assert.Ignore("Driver {0} does not support multi-queries", driver.GetType().FullName);
Assert.Ignore($"Driver {driver.GetType().FullName} does not support multi-queries");

// Test querying StringData
using (ISession session = this.OpenSession())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public async Task ConnectionPoolCorruptionAfterDeadlockAsync(bool distributed, b
//
// ? This shouldn't happen
//
Assert.Fail("Surprising exception when trying to force a deadlock: {0}", x);
Assert.Fail($"Surprising exception when trying to force a deadlock: {x}");
}

_log.WarnFormat("Initial session seemingly not deadlocked at attempt {0}", tryCount);
Expand Down Expand Up @@ -254,11 +254,11 @@ public async Task ConnectionPoolCorruptionAfterDeadlockAsync(bool distributed, b
}
}

Assert.Fail("{0}; {1} subsequent requests failed.",
missingDeadlock
? "Deadlock not reported on initial request, and initial request failed"
: "Initial request failed",
subsequentFailedRequests);
Assert.Fail(
missingDeadlock
? $"Deadlock not reported on initial request, and initial request failed; {subsequentFailedRequests} subsequent requests failed."
: $"Initial request failed; {subsequentFailedRequests} subsequent requests failed.");

} while (tryCount < 3);
//
// I'll change this to while(true) sometimes so I don't have to keep running the test
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/NHSpecificTest/NH3952/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ public static MethodInfo GetMethodDefinition2<T, TResult>(Func<T, TResult> func,
return method.IsGenericMethod ? method.GetGenericMethodDefinition() : method;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task BugAsync()
}
catch (Exception e)
{
Assert.Fail("Should have thrown MyException, thrown {0} instead", e);
Assert.Fail($"Should have thrown MyException, thrown {e} instead");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void MultiHqlShouldThrowUserExceptionAsync()
{
var driver = Sfi.ConnectionProvider.Driver;
if (!driver.SupportsMultipleQueries)
Assert.Ignore("Driver {0} does not support multi-queries", driver.GetType().FullName);
Assert.Ignore($"Driver {driver.GetType().FullName} does not support multi-queries");

using (var s = OpenSession())
using (s.BeginTransaction())
Expand Down Expand Up @@ -96,7 +96,7 @@ public void MultiCriteriaShouldThrowUserExceptionAsync()
{
var driver = Sfi.ConnectionProvider.Driver;
if (!driver.SupportsMultipleQueries)
Assert.Ignore("Driver {0} does not support multi-queries", driver.GetType().FullName);
Assert.Ignore($"Driver {driver.GetType().FullName} does not support multi-queries");

using (var s = OpenSession())
using (s.BeginTransaction())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,11 @@ public async Task CanUseSessionOutsideOfScopeAfterScopeAsync(bool explicitFlush)
}
var count = 0;
Assert.DoesNotThrowAsync(async () => count = await (s.Query<Person>().CountAsync()), "Failed using the session after scope.");
if (count != 1)
const int expectedCount = 1;
if (count != expectedCount)
// We are not testing that here, so just issue a warning. Do not use DodgeTransactionCompletionDelayIfRequired
// before previous assert. We want to ascertain the session is usable in any cases.
Assert.Warn("Unexpected entity count: {0} instead of {1}. The transaction seems to have a delayed commit.", count, 1);
Assert.Warn($"Unexpected entity count: {count} instead of {expectedCount}. The transaction seems to have a delayed commit.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,11 @@ public async Task CanUseSessionOutsideOfScopeAfterScopeAsync(bool explicitFlush)
}
var count = 0;
Assert.DoesNotThrowAsync(async () => count = await (s.Query<Person>().CountAsync()), "Failed using the session after scope.");
if (count != 1)
const int expectedCount = 1;
if (count != expectedCount)
// We are not testing that here, so just issue a warning. Do not use DodgeTransactionCompletionDelayIfRequired
// before previous assert. We want to ascertain the session is usable in any cases.
Assert.Warn("Unexpected entity count: {0} instead of {1}. The transaction seems to have a delayed commit.", count, 1);
Assert.Warn($"Unexpected entity count: {count} instead of {expectedCount}. The transaction seems to have a delayed commit.");
}
}

Expand Down Expand Up @@ -644,10 +645,9 @@ public async Task SupportsTransactionTimeoutAsync()
Assert.That(
_unhandledExceptions.Count,
Is.EqualTo(0),
"Unhandled exceptions have occurred: {0}",
string.Join(@"
$"Unhandled exceptions have occurred: {string.Join(@"

", _unhandledExceptions));
", _unhandledExceptions)}");

// Despite the Thread sleep and the count of entities to load, this test may get the timeout only for slightly
// more than 10% of the attempts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected override void CreateSchema()
{
// Unfortunateley Assert.Warn and Console.WriteLine at this place seems to be ignored in Rider
// viewer.
Assert.Warn("Creating the schema failed, assuming it already exists. {0}", ex);
Assert.Warn($"Creating the schema failed, assuming it already exists. {ex}");
Console.WriteLine("Creating the schema failed, assuming it already exists.");
Console.WriteLine(ex);
}
Expand Down Expand Up @@ -113,7 +113,7 @@ public async Task ShouldVerifyAsync()
}
catch (SchemaValidationException sve)
{
Assert.Fail("Validation failed: {0}.\n{1}", StringHelper.CollectionToString(sve.ValidationErrors), sve);
Assert.Fail($"Validation failed: {StringHelper.CollectionToString(sve.ValidationErrors)}.\n{sve}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ private void AssertCurrentSession(ISession session, string message)
Assert.That(
Sfi.GetCurrentSession(),
Is.EqualTo(session),
"{0} {1} instead of {2}.", message,
Sfi.GetCurrentSession().GetSessionImplementation().SessionId,
session.GetSessionImplementation().SessionId);
$"{message} {Sfi.GetCurrentSession().GetSessionImplementation().SessionId} instead of {session.GetSessionImplementation().SessionId}.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ private void AssertCurrentSession(ISessionFactory factory, ISession session, str
Assert.That(
factory.GetCurrentSession(),
Is.EqualTo(session),
"{0} {1} instead of {2}.", message,
factory.GetCurrentSession().GetSessionImplementation().SessionId,
session.GetSessionImplementation().SessionId);
$"{message} {factory.GetCurrentSession().GetSessionImplementation().SessionId} instead of {session.GetSessionImplementation().SessionId}.");
}
}
}
}
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void MultiCriteria()
{
var driver = Sfi.ConnectionProvider.Driver;
if (!driver.SupportsMultipleQueries)
Assert.Ignore("Driver {0} does not support multi-queries", driver.GetType().FullName);
Assert.Ignore($"Driver {driver.GetType().FullName} does not support multi-queries");

SetupPagingData();

Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Criteria/ProjectionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void UsingSqlFunctions_Concat_WithCast()
{
if(Dialect is Oracle8iDialect)
{
Assert.Ignore("Not supported by the active dialect:{0}.", Dialect);
Assert.Ignore($"Not supported by the active dialect:{Dialect}.");
}
if (TestDialect.HasBrokenTypeInferenceOnSelectedParameters)
Assert.Ignore("Current dialect does not support this test");
Expand Down
Loading