SonarQube Analysis / sonarqube (pull_request) Successful in 2m59s
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>
88 lines
2.8 KiB
C#
88 lines
2.8 KiB
C#
using Strata.SqlTools.SqlBreakdown.Classes;
|
|
|
|
namespace Strata.SqlTools.SqlBreakdown.Tests.SqlBreakdownCollectionTests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for SqlBreakdownCollection with UPDATE statements.
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class SqlBreakdownCollectionUpdateTests : SqlBreakdownCollectionTestBase
|
|
{
|
|
[Test]
|
|
public void ParseBatch_WithUpdateStatements_ParsesSuccessfully()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
UPDATE Users SET Name = 'John Updated', ModifiedDate = GETDATE() WHERE Id = 1
|
|
GO
|
|
UPDATE Orders SET Status = 'Shipped' WHERE OrderDate < DATEADD(day, -30, GETDATE())
|
|
GO
|
|
UPDATE Products SET Price = Price * 1.1 WHERE Category = 'Electronics'
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
Assert.That(collection, Has.Count.EqualTo(3));
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("UPDATE Users"));
|
|
Assert.That(collection.GetRawStatementAt(1), Does.Contain("Status"));
|
|
Assert.That(collection.GetRawStatementAt(2), Does.Contain("Price * 1.1"));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void ParseBatch_WithUpdateFromSelectStatements_ParsesSuccessfully()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
UPDATE u
|
|
SET u.LastOrderDate = (SELECT MAX(OrderDate) FROM Orders WHERE UserId = u.Id)
|
|
FROM Users u
|
|
WHERE u.Id IN (SELECT DISTINCT UserId FROM Orders)
|
|
GO
|
|
UPDATE Products
|
|
SET Quantity = Quantity - 1
|
|
FROM OrderItems oi
|
|
WHERE Products.Id = oi.ProductId AND oi.OrderId = 100
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
Assert.That(collection, Has.Count.EqualTo(2));
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("UPDATE u"));
|
|
Assert.That(collection.GetRawStatementAt(1), Does.Contain("Quantity - 1"));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void ParseBatch_WithUpdateWithJoinStatements_ParsesSuccessfully()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
UPDATE Orders
|
|
SET OrderStatus = 'Processed'
|
|
FROM Orders o
|
|
JOIN OrderItems oi ON o.OrderId = oi.OrderId
|
|
WHERE oi.Quantity > 50
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
Assert.That(collection, Is.Not.Empty);
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("UPDATE Orders"));
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("JOIN"));
|
|
}
|
|
}
|