Files
sql-utilities/tests/Strata.SqlTools.SqlBreakdown.Tests/SqlBreakdownCollectionTests/SqlBreakdownCollectionDeleteTests.cs
T
Thom LambandClaude Opus 4.7 4fe9eb36e6
SonarQube Analysis / sonarqube (pull_request) Successful in 2m59s
chore(sonar): second sweep — catch .Length, Is.Not.Empty, and newly-exposed Multiple groups (NUnit2046, NUnit2045)
Re-runs `dotnet format analyzers --diagnostics NUnit2046 NUnit2045` after
the Tier 2 Assert.Multiple wrap, which exposed:

- `Has.Length.EqualTo(n)` rewrites for `string[]`/array `.Length` checks
  (the first pass only knew about `.Count`).
- `Is.Not.Empty` rewrites for `Count, Is.GreaterThan(0)`.
- A handful of new NUnit2045 groups that became wrappable once the
  initial Multiple blocks settled the surrounding indentation.

Tests still 1180/1180 passing.

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

79 lines
2.5 KiB
C#

using Strata.SqlTools.SqlBreakdown.Classes;
namespace Strata.SqlTools.SqlBreakdown.Tests.SqlBreakdownCollectionTests;
/// <summary>
/// Unit tests for SqlBreakdownCollection with DELETE statements.
/// </summary>
[TestFixture]
public class SqlBreakdownCollectionDeleteTests : SqlBreakdownCollectionTestBase
{
[Test]
public void ParseBatch_WithDeleteStatements_ParsesSuccessfully()
{
// Arrange
var collection = new SqlBreakdownCollection();
var batchSql = @"
DELETE FROM Orders WHERE OrderDate < '2019-01-01'
GO
DELETE FROM UserProfiles WHERE UserId NOT IN (SELECT Id FROM Users)
GO
DELETE FROM AuditLog WHERE LogDate < DATEADD(year, -2, GETDATE())
";
// Act
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection, Has.Count.EqualTo(3));
Assert.Multiple(() =>
{
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"));
});
}
[Test]
public void ParseBatch_WithDeleteFromSelectStatements_ParsesSuccessfully()
{
// Arrange
var collection = new SqlBreakdownCollection();
var batchSql = @"
DELETE o FROM Orders o
WHERE NOT EXISTS (SELECT 1 FROM OrderItems oi WHERE oi.OrderId = o.OrderId)
GO
DELETE FROM Users
WHERE Id IN (SELECT UserId FROM Orders WHERE OrderStatus = 'Cancelled')
";
// Act
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection, Has.Count.EqualTo(2));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("EXISTS"));
}
[Test]
public void ParseBatch_WithDeleteWithJoinStatements_ParsesSuccessfully()
{
// Arrange
var collection = new SqlBreakdownCollection();
var batchSql = @"
DELETE Orders
FROM Orders o
INNER JOIN OrderStatuses os ON o.StatusId = os.Id
WHERE os.StatusName = 'Archived'
";
// Act
collection.ParseBatch(batchSql);
// Assert
Assert.That(collection, Is.Not.Empty);
Assert.That(collection.GetRawStatementAt(0), Does.Contain("DELETE Orders"));
Assert.That(collection.GetRawStatementAt(0), Does.Contain("INNER JOIN"));
}
}