@@ -29,23 +29,18 @@ public static void ShouldExecute(WebApplicationBuilder builder)
2929 }
3030
3131 [ Test ]
32- public async Task LastTimeStampRowVersion ( )
32+ public async Task LastTimeStamp ( )
3333 {
3434 await using var database = await LocalDb ( ) ;
3535
3636 var timeStamp = await DeltaExtensions . GetLastTimeStamp ( database . Connection , null ) ;
37+ //seed with an entity so there is something in transaction log
38+ await AddEntity ( database . Connection ) ;
3739 IsNotEmpty ( timeStamp ) ;
3840 IsNotNull ( timeStamp ) ;
3941 Recording . Start ( ) ;
40- await using ( var command = database . Connection . CreateCommand ( ) )
41- {
42- command . CommandText =
43- $ """
44- insert into [Companies] (Id, Content)
45- values ('{ Guid . NewGuid ( ) } ', 'The company')
46- """ ;
47- await command . ExecuteNonQueryAsync ( ) ;
48- }
42+
43+ await AddEntity ( database . Connection ) ;
4944
5045 var newTimeStamp = await DeltaExtensions . GetLastTimeStamp ( database . Connection , null ) ;
5146 IsNotEmpty ( newTimeStamp ) ;
@@ -54,90 +49,85 @@ insert into [Companies] (Id, Content)
5449 }
5550
5651 [ Test ]
57- public async Task LastTimeStampRowVersionOnUpdate ( )
52+ public async Task LastTimeStampOnUpdate ( )
5853 {
5954 await using var database = await LocalDb ( ) ;
6055 await using var connection = database . Connection ;
61- await connection . EnableTracking ( ) ;
6256
63- var companyGuid = Guid . NewGuid ( ) ;
64- await using var addDataCommand = connection . CreateCommand ( ) ;
65- addDataCommand . CommandText =
66- $ """
67- insert into [Companies] (Id, Content)
68- values ('{ companyGuid } ', 'The company')
69- """ ;
70- await addDataCommand . ExecuteNonQueryAsync ( ) ;
57+ var companyGuid = await AddEntity ( connection ) ;
7158
7259 var timeStamp = await DeltaExtensions . GetLastTimeStamp ( connection , null ) ;
7360 IsNotEmpty ( timeStamp ) ;
7461 IsNotNull ( timeStamp ) ;
7562
76- await using ( var updateCommand = connection . CreateCommand ( ) )
77- {
78- updateCommand . CommandText =
79- $ """
80- UPDATE [Companies]
81- SET [Content] = 'New Content Value'
82- WHERE [Id] = @Id;
83- """ ;
84- updateCommand . Parameters . AddWithValue ( "@Id" , companyGuid ) ;
85- await updateCommand . ExecuteNonQueryAsync ( ) ;
86- }
63+ await UpdateEntity ( connection , companyGuid ) ;
8764
8865 var newTimeStamp = await DeltaExtensions . GetLastTimeStamp ( connection , null ) ;
8966 IsNotEmpty ( newTimeStamp ) ;
9067 IsNotNull ( newTimeStamp ) ;
9168 AreNotEqual ( newTimeStamp , timeStamp ) ;
9269 }
9370
71+ static async Task UpdateEntity ( SqlConnection connection , Guid id )
72+ {
73+ await using var command = connection . CreateCommand ( ) ;
74+ command . CommandText =
75+ $ """
76+ update Companies
77+ set Content = 'New Content Value'
78+ where Id = @Id;
79+ """ ;
80+ command . Parameters . AddWithValue ( "@Id" , id ) ;
81+ await command . ExecuteNonQueryAsync ( ) ;
82+ }
83+
9484 [ Test ]
95- public async Task LastTimeStampRowVersionOnDelete ( )
85+ public async Task LastTimeStampOnDelete ( )
9686 {
9787 await using var database = await LocalDb ( ) ;
9888 await using var connection = database . Connection ;
99- await connection . EnableTracking ( ) ;
10089
101- var companyGuid = Guid . NewGuid ( ) ;
102- await using var addDataCommand = connection . CreateCommand ( ) ;
103- addDataCommand . CommandText =
104- $ """
105- insert into [Companies] (Id, Content)
106- values ('{ companyGuid } ', 'The company')
107- """ ;
108- await addDataCommand . ExecuteNonQueryAsync ( ) ;
90+ var companyGuid = await AddEntity ( connection ) ;
10991
11092 var timeStamp = await DeltaExtensions . GetLastTimeStamp ( connection , null ) ;
11193 IsNotEmpty ( timeStamp ) ;
11294 IsNotNull ( timeStamp ) ;
11395
114- await using ( var deleteCommand = connection . CreateCommand ( ) )
115- {
116- deleteCommand . CommandText = $ "delete From Companies where Id=@Id";
117- deleteCommand . Parameters . AddWithValue ( "@Id" , companyGuid ) ;
118- await deleteCommand . ExecuteNonQueryAsync ( ) ;
119- }
96+ await DeleteEntity ( connection , companyGuid ) ;
12097
12198 var newTimeStamp = await DeltaExtensions . GetLastTimeStamp ( connection , null ) ;
12299 IsNotEmpty ( newTimeStamp ) ;
123100 IsNotNull ( newTimeStamp ) ;
124101 AreNotEqual ( newTimeStamp , timeStamp ) ;
125102 }
126103
127- [ Test ]
128- public async Task LastTimeStampRowVersionOnTruncate ( )
104+ static async Task < Guid > AddEntity ( SqlConnection connection )
129105 {
130- await using var database = await LocalDb ( ) ;
131- await using var connection = database . Connection ;
132- await connection . EnableTracking ( ) ;
133-
134- await using var addDataCommand = connection . CreateCommand ( ) ;
135- addDataCommand . CommandText =
106+ var id = Guid . NewGuid ( ) ;
107+ await using var command = connection . CreateCommand ( ) ;
108+ command . CommandText =
136109 $ """
137110 insert into [Companies] (Id, Content)
138- values ('{ Guid . NewGuid ( ) } ', 'The company')
111+ values ('{ id } ', 'The company')
139112 """ ;
140- await addDataCommand . ExecuteNonQueryAsync ( ) ;
113+ await command . ExecuteNonQueryAsync ( ) ;
114+ return id ;
115+ }
116+
117+ static async Task DeleteEntity ( SqlConnection connection , Guid id )
118+ {
119+ await using var command = connection . CreateCommand ( ) ;
120+ command . CommandText = $ "delete From Companies where Id=@Id";
121+ command . Parameters . AddWithValue ( "@Id" , id ) ;
122+ await command . ExecuteNonQueryAsync ( ) ;
123+ }
124+
125+ [ Test ]
126+ public async Task LastTimeStampOnTruncate ( )
127+ {
128+ await using var database = await LocalDb ( ) ;
129+ await using var connection = database . Connection ;
130+ await AddEntity ( connection ) ;
141131
142132 var timeStamp = await DeltaExtensions . GetLastTimeStamp ( connection , null ) ;
143133 IsNotEmpty ( timeStamp ) ;
@@ -191,32 +181,6 @@ public async Task GetLastTimeStampPostgres()
191181 IsNotEmpty ( timeStamp ) ;
192182 }
193183
194- [ Test ]
195- public async Task LastTimeStampRowVersionAndTracking ( )
196- {
197- await using var database = await LocalDb ( ) ;
198-
199- var connection = database . Connection ;
200- await connection . EnableTracking ( ) ;
201- var timeStamp = await DeltaExtensions . GetLastTimeStamp ( connection , null ) ;
202- IsNotEmpty ( timeStamp ) ;
203- IsNotNull ( timeStamp ) ;
204- await using ( var command = connection . CreateCommand ( ) )
205- {
206- command . CommandText =
207- $ """
208- insert into [Companies] (Id, Content)
209- values ('{ Guid . NewGuid ( ) } ', 'The company')
210- """ ;
211- await command . ExecuteNonQueryAsync ( ) ;
212- }
213-
214- var newTimeStamp = await DeltaExtensions . GetLastTimeStamp ( connection , null ) ;
215- IsNotEmpty ( newTimeStamp ) ;
216- IsNotNull ( newTimeStamp ) ;
217- AreNotEqual ( timeStamp , newTimeStamp ) ;
218- }
219-
220184 [ Test ]
221185 public async Task GetDatabasesWithTracking ( )
222186 {
0 commit comments