Files
sql-utilities/tests/Strata.SqlTools.SqlBreakdown.Tests/SqlBreakdownCollectionTests/SqlBreakdownCollectionMixedCrudTests.cs
T
Thom LambandClaude Opus 4.7 67512d23e1 chore(sonar): wrap independent assertions in Assert.Multiple (NUnit2045)
Driven by `dotnet format analyzers --diagnostics NUnit2045`. The fixer
groups consecutive independent `Assert.That(...)` calls into
`Assert.Multiple(() => { ... })`, so a failing assertion no longer
short-circuits the block — every failure inside the group is reported,
which gives much better diagnostics on multi-property tests.

Audit confirmed no Assert.Throws / Assert.Fail / Assert.Catch / Assert.Pass
/ Assert.DoesNotThrow got pulled inside a Multiple block (those need to
short-circuit). All 1180 tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 11:59:47 -05:00

95 lines
3.2 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.Multiple(() =>
{
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);
}
}
}