- 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>
76 lines
2.5 KiB
C#
76 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.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.Count, Is.GreaterThanOrEqualTo(1));
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("DELETE Orders"));
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("INNER JOIN"));
|
|
}
|
|
}
|