using Strata.SqlTools.SqlBreakdown.Classes; namespace Strata.SqlTools.SqlBreakdown.Tests.SqlBreakdownCollectionTests; /// /// Unit tests for SqlBreakdownCollection with mixed CRUD operations. /// [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); } } }