@@ -64,11 +64,10 @@ private void ValidateSchema(SqlDataReader reader)
64
64
65
65
[ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsJsonSupported ) ) ]
66
66
public void TestJsonWrite ( )
67
- {
68
- string tableName = DataTestUtility . GetUniqueNameForSqlServer ( "Json_Test" ) ;
69
- string spName = DataTestUtility . GetUniqueNameForSqlServer ( "spJson_WriteTest" ) ;
70
-
71
- string tableCreate = "CREATE TABLE " + tableName + " (Data json)" ;
67
+ {
68
+ string tableName = "jsonWriteTest" ;
69
+ string spName = "spJsonWriteTest" ;
70
+
72
71
string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)" ;
73
72
string spCreate = "CREATE PROCEDURE " + spName + " (@jsonData json) AS " + tableInsert ;
74
73
@@ -79,10 +78,10 @@ public void TestJsonWrite()
79
78
using ( SqlCommand command = connection . CreateCommand ( ) )
80
79
{
81
80
//Create Table
82
- command . CommandText = tableCreate ;
83
- command . ExecuteNonQuery ( ) ;
81
+ DataTestUtility . CreateTable ( connection , tableName , "(data json)" ) ;
84
82
85
83
//Create SP for writing json values
84
+ DataTestUtility . DropStoredProcedure ( connection , spName ) ;
86
85
command . CommandText = spCreate ;
87
86
command . ExecuteNonQuery ( ) ;
88
87
@@ -116,17 +115,17 @@ public void TestJsonWrite()
116
115
}
117
116
118
117
DataTestUtility . DropTable ( connection , tableName ) ;
118
+ DataTestUtility . DropStoredProcedure ( connection , spName ) ;
119
119
}
120
120
}
121
121
}
122
122
123
123
[ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsJsonSupported ) ) ]
124
124
public async Task TestJsonWriteAsync ( )
125
125
{
126
- string tableName = DataTestUtility . GetUniqueNameForSqlServer ( "Json_Test" ) ;
127
- string spName = DataTestUtility . GetUniqueNameForSqlServer ( "spJson_WriteTest" ) ;
126
+ string tableName = "jsonWriteTest" ;
127
+ string spName = "spJsonWriteTest" ;
128
128
129
- string tableCreate = "CREATE TABLE " + tableName + " (Data json)" ;
130
129
string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)" ;
131
130
string spCreate = "CREATE PROCEDURE " + spName + " (@jsonData json) AS " + tableInsert ;
132
131
@@ -137,10 +136,10 @@ public async Task TestJsonWriteAsync()
137
136
using ( SqlCommand command = connection . CreateCommand ( ) )
138
137
{
139
138
//Create Table
140
- command . CommandText = tableCreate ;
141
- await command . ExecuteNonQueryAsync ( ) ;
139
+ DataTestUtility . CreateTable ( connection , tableName , "(data json)" ) ;
142
140
143
141
//Create SP for writing json values
142
+ DataTestUtility . DropStoredProcedure ( connection , spName ) ;
144
143
command . CommandText = spCreate ;
145
144
await command . ExecuteNonQueryAsync ( ) ;
146
145
@@ -172,31 +171,33 @@ public async Task TestJsonWriteAsync()
172
171
int rowsAffected3 = await command . ExecuteNonQueryAsync ( ) ;
173
172
ValidateRowsAffected ( rowsAffected3 ) ;
174
173
}
174
+
175
+ DataTestUtility . DropTable ( connection , tableName ) ;
176
+ DataTestUtility . DropStoredProcedure ( connection , spName ) ;
175
177
}
176
178
}
177
179
}
178
180
179
181
[ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsJsonSupported ) ) ]
180
182
public void TestJsonRead ( )
181
183
{
182
- string tableName = DataTestUtility . GetUniqueNameForSqlServer ( "Json_Test" ) ;
183
- string spName = DataTestUtility . GetUniqueNameForSqlServer ( "spJson_ReadTest" ) ;
184
+ string tableName = "jsonReadTest" ;
185
+ string spName = "spJsonReadTest" ;
184
186
185
- string tableCreate = "CREATE TABLE " + tableName + " (Data json)" ;
186
187
string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)" ;
187
188
string tableRead = "SELECT * FROM " + tableName ;
188
- string spCreate = "CREATE PROCEDURE " + spName + "AS " + tableRead ;
189
+ string spCreate = "CREATE PROCEDURE " + spName + " AS " + tableRead ;
189
190
190
191
using ( SqlConnection connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
191
192
{
192
193
connection . Open ( ) ;
193
194
using ( SqlCommand command = connection . CreateCommand ( ) )
194
195
{
195
196
//Create Table
196
- command . CommandText = tableCreate ;
197
- command . ExecuteNonQuery ( ) ;
197
+ DataTestUtility . CreateTable ( connection , tableName , "(data json)" ) ;
198
198
199
199
//Create SP for reading from json column
200
+ DataTestUtility . DropStoredProcedure ( connection , spName ) ;
200
201
command . CommandText = spCreate ;
201
202
command . ExecuteNonQuery ( ) ;
202
203
@@ -231,31 +232,31 @@ public void TestJsonRead()
231
232
}
232
233
233
234
DataTestUtility . DropTable ( connection , tableName ) ;
235
+ DataTestUtility . DropStoredProcedure ( connection , spName ) ;
234
236
}
235
237
}
236
238
}
237
239
238
240
[ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsJsonSupported ) ) ]
239
241
public async Task TestJsonReadAsync ( )
240
242
{
241
- string tableName = DataTestUtility . GetUniqueNameForSqlServer ( "Json_Test" ) ;
242
- string spName = DataTestUtility . GetUniqueNameForSqlServer ( "spJson_ReadTest" ) ;
243
+ string tableName = "jsonReadTest" ;
244
+ string spName = "spJsonReadTest" ;
243
245
244
- string tableCreate = "CREATE TABLE " + tableName + " (Data json)" ;
245
246
string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)" ;
246
247
string tableRead = "SELECT * FROM " + tableName ;
247
- string spCreate = "CREATE PROCEDURE " + spName + "AS " + tableRead ;
248
+ string spCreate = "CREATE PROCEDURE " + spName + " AS " + tableRead ;
248
249
249
250
using ( SqlConnection connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
250
251
{
251
252
await connection . OpenAsync ( ) ;
252
253
using ( SqlCommand command = connection . CreateCommand ( ) )
253
254
{
254
255
//Create Table
255
- command . CommandText = tableCreate ;
256
- await command . ExecuteNonQueryAsync ( ) ;
256
+ DataTestUtility . CreateTable ( connection , tableName , "(data json)" ) ;
257
257
258
258
//Create SP for reading from json column
259
+ DataTestUtility . DropStoredProcedure ( connection , spName ) ;
259
260
command . CommandText = spCreate ;
260
261
await command . ExecuteNonQueryAsync ( ) ;
261
262
@@ -288,6 +289,9 @@ public async Task TestJsonReadAsync()
288
289
await ValidateRowsAsync ( reader2 ) ;
289
290
reader2 . Close ( ) ;
290
291
}
292
+
293
+ DataTestUtility . DropTable ( connection , tableName ) ;
294
+ DataTestUtility . DropStoredProcedure ( connection , spName ) ;
291
295
}
292
296
}
293
297
}
0 commit comments