-
Notifications
You must be signed in to change notification settings - Fork 67
add test to check LastAccessTime column creation for existing triggers #865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
27ca6a2
d9e29b4
338ba63
decf665
1c0754c
5000872
7daa99c
33b9dfb
32a355f
64c7968
66ce768
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -612,5 +612,48 @@ void TestExceptionMessageSeen(object sender, DataReceivedEventArgs e) | |
| await changesTask; | ||
|
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that the GlobalState table has LastAccessTime column. | ||
| /// </summary> | ||
| /// <remarks>We call StartAsync which initializes the GlobalState and then drop the LastAccessTime column from the table and recall the StartAsync to check if the GlobalState has the column.</remarks> | ||
| [Fact] | ||
| public async void LastAccessTimeColumnTest() | ||
| { | ||
|
|
||
| this.SetChangeTrackingForTable("Products"); | ||
| string userFunctionId = "func-id"; | ||
| IConfiguration configuration = new ConfigurationBuilder().Build(); | ||
| var listener = new SqlTriggerListener<Product>(this.DbConnectionString, "dbo.Products", userFunctionId, Mock.Of<ITriggeredFunctionExecutor>(), Mock.Of<ILogger>(), configuration); | ||
| await listener.StartAsync(CancellationToken.None); | ||
| // Cancel immediately so the listener doesn't start processing the changes | ||
| await listener.StopAsync(CancellationToken.None); | ||
| //Check if LastAccessTime column exists in the GlobalState table | ||
| Assert.Equal(1, this.ExecuteScalar("SELECT 1 FROM sys.columns WHERE Name = N'LastAccessTime' AND Object_ID = Object_ID(N'[az_func].[GlobalState]')")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Assert.True so you can give it a message in case of failure |
||
| // Delete default constraint(s) on LastAccessTime column before dropping it | ||
| string deleteDefaultContraint = @"DECLARE @sql NVARCHAR(MAX) | ||
| WHILE 1=1 | ||
| BEGIN | ||
| SELECT TOP 1 @sql = N'ALTER TABLE [az_func].[GlobalState] DROP CONSTRAINT ['+dc.NAME+N']' | ||
| FROM sys.default_constraints dc | ||
| JOIN sys.columns c | ||
| ON c.default_object_id = dc.object_id | ||
| WHERE dc.parent_object_id = OBJECT_ID('[az_func].[GlobalState]') | ||
| AND c.name = N'LastAccessTime' | ||
| IF @@ROWCOUNT = 0 BREAK | ||
| EXEC (@sql) | ||
| END"; | ||
| this.ExecuteNonQuery(deleteDefaultContraint); | ||
| // Delete the LastAccessTime column from GlobalState table. | ||
| this.ExecuteNonQuery($"ALTER TABLE [az_func].[GlobalState] DROP COLUMN LastAccessTime"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the constant value from SqlTriggerConstants for the table name everywhere you reference it. I would also suggest creating a constant for the LastAccessTime column name |
||
|
|
||
| await listener.StartAsync(CancellationToken.None); | ||
| // Cancel immediately so the listener doesn't start processing the changes | ||
| await listener.StopAsync(CancellationToken.None); | ||
|
|
||
| //Check if LastAccessTime column exists in the GlobalState table | ||
| Assert.Equal(1, this.ExecuteScalar("SELECT 1 FROM sys.columns WHERE Name = N'LastAccessTime' AND Object_ID = Object_ID(N'[az_func].[GlobalState]')")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert.True |
||
|
|
||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good to try and give tests names that say what the test is doing