- 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>
87 lines
2.8 KiB
C#
87 lines
2.8 KiB
C#
using Strata.SqlTools.SqlBreakdown.Classes;
|
|
|
|
namespace Strata.SqlTools.SqlBreakdown.Tests.SqlBreakdownCollectionTests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for SqlBreakdownCollection with SELECT statements.
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class SqlBreakdownCollectionSelectTests : SqlBreakdownCollectionTestBase
|
|
{
|
|
[Test]
|
|
public void ParseBatch_WithComplexSelectStatements_ParsesSuccessfully()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
SELECT u.Id, u.Name, COUNT(o.OrderId) AS OrderCount
|
|
FROM Users u
|
|
LEFT JOIN Orders o ON u.Id = o.UserId
|
|
WHERE u.CreatedDate > '2020-01-01'
|
|
GROUP BY u.Id, u.Name
|
|
HAVING COUNT(o.OrderId) > 0
|
|
ORDER BY OrderCount DESC
|
|
GO
|
|
SELECT * FROM Orders WHERE OrderDate BETWEEN '2020-01-01' AND '2021-12-31'
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
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"));
|
|
}
|
|
|
|
[Test]
|
|
public void ParseBatch_WithSelectWithCommonTableExpression_ParsesSuccessfully()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
WITH UserOrders AS (
|
|
SELECT UserId, OrderId, OrderDate
|
|
FROM Orders
|
|
WHERE OrderDate > '2020-01-01'
|
|
)
|
|
SELECT u.Id, u.Name, uo.OrderId
|
|
FROM Users u
|
|
INNER JOIN UserOrders uo ON u.Id = uo.UserId
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
Assert.That(collection.Count, Is.GreaterThanOrEqualTo(1));
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("WITH UserOrders AS"));
|
|
}
|
|
|
|
[Test]
|
|
public void ParseBatch_WithSelectFromMultipleTables_ParsesSuccessfully()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
SELECT u.Id, u.Name, o.OrderId, p.ProductName
|
|
FROM Users u
|
|
JOIN Orders o ON u.Id = o.UserId
|
|
JOIN OrderItems oi ON o.OrderId = oi.OrderId
|
|
JOIN Products p ON oi.ProductId = p.Id
|
|
WHERE u.Country = 'USA'
|
|
GO
|
|
SELECT * FROM UserProfiles WHERE UserId IN (SELECT Id FROM Users)
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
Assert.That(collection, Has.Count.EqualTo(2));
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("JOIN"));
|
|
Assert.That(collection.GetRawStatementAt(1), Does.Contain("IN"));
|
|
}
|
|
}
|