- 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>
81 lines
2.4 KiB
C#
81 lines
2.4 KiB
C#
using Strata.SqlTools.SqlBreakdown.Classes;
|
|
|
|
namespace Strata.SqlTools.SqlBreakdown.Tests.SqlBreakdownCollectionTests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for SqlBreakdownCollection with CREATE statements.
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class SqlBreakdownCollectionCreateTests : SqlBreakdownCollectionTestBase
|
|
{
|
|
[Test]
|
|
public void ParseBatch_WithCreateTableStatements_ParsesSuccessfully()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
CREATE TABLE Users (
|
|
Id INT PRIMARY KEY,
|
|
Name NVARCHAR(100),
|
|
Email NVARCHAR(100)
|
|
)
|
|
GO
|
|
CREATE TABLE Orders (
|
|
OrderId INT PRIMARY KEY,
|
|
UserId INT FOREIGN KEY REFERENCES Users(Id),
|
|
OrderDate DATETIME
|
|
)
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
Assert.That(collection, Has.Count.EqualTo(2));
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("CREATE TABLE Users"));
|
|
Assert.That(collection.GetRawStatementAt(1), Does.Contain("CREATE TABLE Orders"));
|
|
}
|
|
|
|
[Test]
|
|
public void ParseBatch_WithCreateIndexStatements_ParsesSuccessfully()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
CREATE INDEX idx_Users_Email ON Users(Email)
|
|
GO
|
|
CREATE UNIQUE INDEX idx_Orders_OrderDate ON Orders(OrderDate)
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
Assert.That(collection, Has.Count.EqualTo(2));
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("CREATE INDEX"));
|
|
Assert.That(collection.GetRawStatementAt(1), Does.Contain("UNIQUE"));
|
|
}
|
|
|
|
[Test]
|
|
public void ParseBatch_WithCreateProcedureStatement_ParsesSuccessfully()
|
|
{
|
|
// Arrange
|
|
var collection = new SqlBreakdownCollection();
|
|
var batchSql = @"
|
|
CREATE PROCEDURE sp_GetUserById
|
|
@UserId INT
|
|
AS
|
|
BEGIN
|
|
SELECT * FROM Users WHERE Id = @UserId
|
|
END
|
|
";
|
|
|
|
// Act
|
|
collection.ParseBatch(batchSql);
|
|
|
|
// Assert
|
|
Assert.That(collection.Count, Is.GreaterThanOrEqualTo(1));
|
|
Assert.That(collection.GetRawStatementAt(0), Does.Contain("CREATE PROCEDURE"));
|
|
}
|
|
}
|