chore(sonar): adopt Has.Count, Is.Empty, Does.Contain, char overloads in tests (NUnit2046, NUnit2011, CA1866)

- NUnit2046: `Assert.That(x.Count, Is.EqualTo(n))` → `Assert.That(x, Has.Count.EqualTo(n))` (or `Is.Empty` when n==0)
- NUnit2011: `Assert.That(s.Contains(x))` → `Assert.That(s, Does.Contain(x))` for richer failure messages
- CA1866: `.StartsWith("$"|"@"|":")` → `.StartsWith('$'|'@'|':')` char overload

Driven by `dotnet format analyzers --diagnostics NUnit2046 NUnit2011 CA1866`
for the cases the Roslyn fixer handles, plus a regex sweep for the remaining
`Count == n` (n>0) cases which the fixer doesn't address. CA1866 had no
associated code fix and was edited by hand (3 sites in 2 files). All tests
green (1180 passing).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thom Lamb
2026-05-27 11:58:00 -05:00
co-authored by Claude Opus 4.7
parent 5aca8e93fd
commit 505ada5017
24 changed files with 105 additions and 105 deletions
@@ -389,7 +389,7 @@ public class ExceptionHandlingTests
query.AddWithClause("active_users", cteQuery);
// Assert
Assert.That(query.WithClauses.Count, Is.EqualTo(1));
Assert.That(query.WithClauses, Has.Count.EqualTo(1));
Assert.That(query.WithClauses[0].TableName, Is.EqualTo("active_users"));
}
@@ -188,7 +188,7 @@ public class QueryBreakdownExtensionsTests
// Assert
Assert.That(query.IsUsingWithClause, Is.True);
Assert.That(query.WithClauses.Count, Is.EqualTo(1));
Assert.That(query.WithClauses, Has.Count.EqualTo(1));
Assert.That(query.WithClauses[0].TableName, Is.EqualTo("active_users"));
Assert.That(query.SelectClause.Clause, Is.EqualTo("*"));
Assert.That(query.FromClause.Clause, Is.EqualTo("active_users"));
@@ -238,7 +238,7 @@ public class QueryBreakdownExtensionsTests
// Assert
Assert.That(query.IsUsingWithClause, Is.True);
Assert.That(query.WithClauses.Count, Is.EqualTo(2));
Assert.That(query.WithClauses, Has.Count.EqualTo(2));
Assert.That(query.WithClauses[0].TableName, Is.EqualTo("active_users"));
Assert.That(query.WithClauses[1].TableName, Is.EqualTo("recent_orders"));
}
@@ -261,7 +261,7 @@ public class QueryBreakdownExtensionsTests
// Assert
Assert.That(query.IsUsingWithClause, Is.True);
Assert.That(query.WithClauses.Count, Is.EqualTo(1));
Assert.That(query.WithClauses, Has.Count.EqualTo(1));
Assert.That(sql, Does.Contain("active_users (id, name, email)"));
}
@@ -282,7 +282,7 @@ public class QueryBreakdownExtensionsTests
// Assert
Assert.That(query.IsUsingWithClause, Is.True);
Assert.That(query.WithClauses.Count, Is.EqualTo(1));
Assert.That(query.WithClauses, Has.Count.EqualTo(1));
Assert.That(query.WithClauses[0].TableName, Is.EqualTo("active_users"));
}
@@ -356,7 +356,7 @@ public class QueryBreakdownExtensionsTests
var sql = query.GetSql();
// Assert
Assert.That(query.WithClauses.Count, Is.EqualTo(2));
Assert.That(query.WithClauses, Has.Count.EqualTo(2));
Assert.That(sql, Does.Contain("active_users AS"));
Assert.That(sql, Does.Contain("user_orders AS"));
Assert.That(sql, Does.Contain("customer_tier"));
@@ -16,7 +16,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
var collection = new SqlBreakdownCollection();
// Assert
Assert.That(collection.Count, Is.EqualTo(0));
Assert.That(collection, Is.Empty);
Assert.That(collection.IsEmpty, Is.True);
Assert.That(collection.Breakdowns, Is.Empty);
Assert.That(collection.RawStatements, Is.Empty);
@@ -36,7 +36,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
var collection = new SqlBreakdownCollection(mockBreakdowns);
// Assert
Assert.That(collection.Count, Is.EqualTo(2));
Assert.That(collection, Has.Count.EqualTo(2));
Assert.That(collection.IsEmpty, Is.False);
}
@@ -51,7 +51,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
collection.Add(breakdown);
// Assert
Assert.That(collection.Count, Is.EqualTo(1));
Assert.That(collection, Has.Count.EqualTo(1));
Assert.That(collection.GetAt(0), Is.EqualTo(breakdown));
}
@@ -81,7 +81,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
collection.AddRange(breakdowns);
// Assert
Assert.That(collection.Count, Is.EqualTo(3));
Assert.That(collection, Has.Count.EqualTo(3));
}
[Test]
@@ -106,7 +106,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
// Assert
Assert.That(result, Is.True);
Assert.That(collection.Count, Is.EqualTo(0));
Assert.That(collection, Is.Empty);
}
[Test]
@@ -121,7 +121,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
// Assert
Assert.That(result, Is.False);
Assert.That(collection.Count, Is.EqualTo(1));
Assert.That(collection, Has.Count.EqualTo(1));
}
[Test]
@@ -138,7 +138,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
collection.Clear();
// Assert
Assert.That(collection.Count, Is.EqualTo(0));
Assert.That(collection, Is.Empty);
Assert.That(collection.IsEmpty, Is.True);
}
@@ -159,7 +159,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.RawStatements.Count, Is.EqualTo(3));
Assert.That(collection.RawStatements, Has.Count.EqualTo(3));
Assert.That(collection.RawStatements[0], Does.Contain("Table1"));
Assert.That(collection.RawStatements[1], Does.Contain("Table2"));
Assert.That(collection.RawStatements[2], Does.Contain("Table3"));
@@ -182,7 +182,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.RawStatements.Count, Is.EqualTo(3));
Assert.That(collection.RawStatements, Has.Count.EqualTo(3));
}
[Test]
@@ -202,7 +202,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.RawStatements.Count, Is.EqualTo(3));
Assert.That(collection.RawStatements, Has.Count.EqualTo(3));
}
[Test]
@@ -222,7 +222,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.RawStatements.Count, Is.EqualTo(2));
Assert.That(collection.RawStatements, Has.Count.EqualTo(2));
Assert.That(collection.RawStatements[0], Does.Contain("Table1"));
Assert.That(collection.RawStatements[1], Does.Contain("Table2"));
}
@@ -338,7 +338,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
var filtered = collection.Where(b => b.ToString()!.Contains("Table2")).ToList();
// Assert
Assert.That(filtered.Count, Is.EqualTo(1));
Assert.That(filtered, Has.Count.EqualTo(1));
Assert.That(filtered[0].ToString()!, Does.Contain("Table2"));
}
@@ -357,7 +357,7 @@ public class SqlBreakdownCollectionCoreTests : SqlBreakdownCollectionTestBase
var projected = collection.Select(b => b.ToString()!.Length).ToList();
// Assert
Assert.That(projected.Count, Is.EqualTo(2));
Assert.That(projected, Has.Count.EqualTo(2));
Assert.That(projected[0], Is.GreaterThan(0));
}
@@ -31,7 +31,7 @@ public class SqlBreakdownCollectionCreateTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(2));
Assert.That(collection, Has.Count.EqualTo(2));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("CREATE TABLE Users"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("CREATE TABLE Orders"));
}
@@ -51,7 +51,7 @@ public class SqlBreakdownCollectionCreateTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(2));
Assert.That(collection, Has.Count.EqualTo(2));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("CREATE INDEX"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("UNIQUE"));
}
@@ -25,7 +25,7 @@ public class SqlBreakdownCollectionDeleteTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(3));
Assert.That(collection, Has.Count.EqualTo(3));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("DELETE FROM Orders"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("NOT IN"));
Assert.That(collection.GetRawStatementAt(2), Does.Contain("DATEADD"));
@@ -48,7 +48,7 @@ public class SqlBreakdownCollectionDeleteTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(2));
Assert.That(collection, Has.Count.EqualTo(2));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("EXISTS"));
}
@@ -25,7 +25,7 @@ public class SqlBreakdownCollectionDropTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(3));
Assert.That(collection, Has.Count.EqualTo(3));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("DROP TABLE"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("DROP TABLE"));
}
@@ -47,7 +47,7 @@ public class SqlBreakdownCollectionDropTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(3));
Assert.That(collection, Has.Count.EqualTo(3));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("DROP INDEX"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("PROCEDURE"));
Assert.That(collection.GetRawStatementAt(2), Does.Contain("VIEW"));
@@ -25,7 +25,7 @@ public class SqlBreakdownCollectionInsertTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(3));
Assert.That(collection, Has.Count.EqualTo(3));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("INSERT INTO Users"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("Jane Smith"));
Assert.That(collection.GetRawStatementAt(2), Does.Contain("Bob Johnson"));
@@ -48,7 +48,7 @@ public class SqlBreakdownCollectionInsertTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(2));
Assert.That(collection, Has.Count.EqualTo(2));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("INSERT INTO UsersArchive"));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("SELECT"));
}
@@ -70,7 +70,7 @@ public class SqlBreakdownCollectionInsertTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(2));
Assert.That(collection, Has.Count.EqualTo(2));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("BULK INSERT"));
}
}
@@ -37,7 +37,7 @@ public class SqlBreakdownCollectionMixedCrudTests : SqlBreakdownCollectionTestBa
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(7));
Assert.That(collection, Has.Count.EqualTo(7));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("CREATE TABLE"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("INSERT"));
Assert.That(collection.GetRawStatementAt(3), Does.Contain("SELECT"));
@@ -81,8 +81,8 @@ public class SqlBreakdownCollectionMixedCrudTests : SqlBreakdownCollectionTestBa
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(5));
Assert.That(collection.RawStatements.Count, Is.EqualTo(5));
Assert.That(collection, Has.Count.EqualTo(5));
Assert.That(collection.RawStatements, Has.Count.EqualTo(5));
foreach (var statement in collection.RawStatements)
{
Assert.That(statement, Is.Not.Empty);
@@ -23,7 +23,7 @@ public class SqlBreakdownCollectionParameterTests : SqlBreakdownCollectionTestBa
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(2));
Assert.That(collection, Has.Count.EqualTo(2));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("@UserId"));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("@UserEmail"));
}
@@ -43,7 +43,7 @@ public class SqlBreakdownCollectionParameterTests : SqlBreakdownCollectionTestBa
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(2));
Assert.That(collection, Has.Count.EqualTo(2));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("@Name"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("@Status"));
}
@@ -29,7 +29,7 @@ public class SqlBreakdownCollectionSelectTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(2));
Assert.That(collection, Has.Count.EqualTo(2));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("LEFT JOIN"));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("GROUP BY"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("BETWEEN"));
@@ -79,7 +79,7 @@ public class SqlBreakdownCollectionSelectTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(2));
Assert.That(collection, Has.Count.EqualTo(2));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("JOIN"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("IN"));
}
@@ -25,7 +25,7 @@ public class SqlBreakdownCollectionSeparatorTests : SqlBreakdownCollectionTestBa
collection.ParseBatch(batchSql, ";");
// Assert
Assert.That(collection.Count, Is.EqualTo(3));
Assert.That(collection, Has.Count.EqualTo(3));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("Users"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("Orders"));
Assert.That(collection.GetRawStatementAt(2), Does.Contain("Products"));
@@ -48,7 +48,7 @@ public class SqlBreakdownCollectionSeparatorTests : SqlBreakdownCollectionTestBa
collection.ParseBatch(batchSql, "~~~");
// Assert
Assert.That(collection.Count, Is.EqualTo(3));
Assert.That(collection.RawStatements.Count, Is.EqualTo(3));
Assert.That(collection, Has.Count.EqualTo(3));
Assert.That(collection.RawStatements, Has.Count.EqualTo(3));
}
}
@@ -25,7 +25,7 @@ public class SqlBreakdownCollectionUpdateTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(3));
Assert.That(collection, Has.Count.EqualTo(3));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("UPDATE Users"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("Status"));
Assert.That(collection.GetRawStatementAt(2), Does.Contain("Price * 1.1"));
@@ -52,7 +52,7 @@ public class SqlBreakdownCollectionUpdateTests : SqlBreakdownCollectionTestBase
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection.Count, Is.EqualTo(2));
Assert.That(collection, Has.Count.EqualTo(2));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("UPDATE u"));
Assert.That(collection.GetRawStatementAt(1), Does.Contain("Quantity - 1"));
}