- 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>
92 lines
3.1 KiB
C#
92 lines
3.1 KiB
C#
using Strata.SqlTools.SqlBreakdown.Classes;
|
|
|
|
namespace Strata.SqlTools.SqlBreakdown.Tests.SqlBreakdownCollectionTests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for SqlBreakdownCollection with mixed CRUD operations.
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class SqlBreakdownCollectionMixedCrudTests : SqlBreakdownCollectionTestBase
|
|
{
|
|
[Test]
|
|
public void ParseBatch_WithMixedCrudOperations_ParsesSuccessfully()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
CREATE TABLE Users (
|
|
Id INT PRIMARY KEY,
|
|
Name NVARCHAR(100),
|
|
Email NVARCHAR(100)
|
|
)
|
|
GO
|
|
INSERT INTO Users (Id, Name, Email) VALUES (1, 'John Doe', 'john@example.com')
|
|
GO
|
|
INSERT INTO Users (Id, Name, Email) VALUES (2, 'Jane Smith', 'jane@example.com')
|
|
GO
|
|
SELECT * FROM Users WHERE Id = 1
|
|
GO
|
|
UPDATE Users SET Name = 'John Updated' WHERE Id = 1
|
|
GO
|
|
DELETE FROM Users WHERE Id = 2
|
|
GO
|
|
DROP TABLE Users
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
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"));
|
|
Assert.That(collection.GetRawStatementAt(4), Does.Contain("UPDATE"));
|
|
Assert.That(collection.GetRawStatementAt(5), Does.Contain("DELETE"));
|
|
Assert.That(collection.GetRawStatementAt(6), Does.Contain("DROP"));
|
|
}
|
|
|
|
[Test]
|
|
public void ParseBatch_WithComplexMultipleStatements_ParsesAllStatements()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
CREATE TABLE Products (
|
|
Id INT PRIMARY KEY,
|
|
Name NVARCHAR(100),
|
|
Price DECIMAL(10, 2),
|
|
Quantity INT
|
|
)
|
|
GO
|
|
INSERT INTO Products (Id, Name, Price, Quantity)
|
|
SELECT Id, ProductName, BasePrice, StockQuantity
|
|
FROM StagingProducts
|
|
WHERE IsActive = 1
|
|
GO
|
|
UPDATE Products SET Price = Price * 1.1 WHERE Quantity < 10
|
|
GO
|
|
SELECT p.Name,
|
|
COUNT(oi.Id) AS OrderCount,
|
|
SUM(oi.Quantity) AS TotalSold
|
|
FROM Products p
|
|
LEFT JOIN OrderItems oi ON p.Id = oi.ProductId
|
|
GROUP BY p.Id, p.Name
|
|
HAVING SUM(oi.Quantity) > 100
|
|
GO
|
|
DELETE FROM Products WHERE Quantity = 0 AND LastUpdated < DATEADD(month, -6, GETDATE())
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
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);
|
|
}
|
|
}
|
|
}
|