- 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>
74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
using Strata.SqlTools.SqlBreakdown.Classes;
|
|
|
|
namespace Strata.SqlTools.SqlBreakdown.Tests.SqlBreakdownCollectionTests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for SqlBreakdownCollection with parameterized statements.
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class SqlBreakdownCollectionParameterTests : SqlBreakdownCollectionTestBase
|
|
{
|
|
[Test]
|
|
public void ParseBatch_WithParameterizedInsertStatements_PreservesParameters()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
INSERT INTO Users (Id, Name, Email) VALUES (@UserId, @UserName, @UserEmail)
|
|
GO
|
|
INSERT INTO Orders (OrderId, UserId, OrderDate) VALUES (@OrderId, @UserId, @OrderDate)
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
Assert.That(collection, Has.Count.EqualTo(2));
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("@UserId"));
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("@UserEmail"));
|
|
}
|
|
|
|
[Test]
|
|
public void ParseBatch_WithParameterizedUpdateStatements_PreservesParameters()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
UPDATE Users SET Name = @Name, Email = @Email WHERE Id = @UserId
|
|
GO
|
|
UPDATE Orders SET Status = @Status, ModifiedDate = @ModifiedDate WHERE OrderId = @OrderId
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
Assert.That(collection, Has.Count.EqualTo(2));
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("@Name"));
|
|
Assert.That(collection.GetRawStatementAt(1), Does.Contain("@Status"));
|
|
}
|
|
|
|
[Test]
|
|
public void GetCombinedSql_WithMixedCrudOperations_CombinesCorrectly()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
collection.ParseBatch(@"
|
|
INSERT INTO Users (Id, Name) VALUES (1, 'John')
|
|
GO
|
|
UPDATE Users SET Name = 'Jane' WHERE Id = 1
|
|
GO
|
|
DELETE FROM Users WHERE Id = 1
|
|
");
|
|
|
|
// Act
|
|
var combined = collection.GetCombinedSql();
|
|
|
|
// Assert
|
|
Assert.That(combined, Does.Contain("INSERT"));
|
|
Assert.That(combined, Does.Contain("UPDATE"));
|
|
Assert.That(combined, Does.Contain("DELETE"));
|
|
Assert.That(combined, Does.Contain("GO"));
|
|
}
|
|
}
|