chore: initial git load of code space
This commit is contained in:
+81
@@ -0,0 +1,81 @@
|
||||
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.Count, Is.EqualTo(3));
|
||||
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.Count, Is.EqualTo(2));
|
||||
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.Count, Is.GreaterThanOrEqualTo(1));
|
||||
Assert.That(collection.GetRawStatementAt(0), Does.Contain("UPDATE Orders"));
|
||||
Assert.That(collection.GetRawStatementAt(0), Does.Contain("JOIN"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user