Skip to content

Commit ed70bf7

Browse files
committed
Fixed the Unit Tests for the batch insert statement builders.
1 parent ab35671 commit ed70bf7

File tree

1 file changed

+50
-25
lines changed

1 file changed

+50
-25
lines changed

RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/StatementBuilders/CreateInsertAllTest.cs

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ public void TestBaseStatementBuilderCreateInsertAll()
4040
var expected = $"" +
4141
$"INSERT INTO [Table] " +
4242
$"( [Field1], [Field2], [Field3] ) " +
43-
$"VALUES " +
44-
$"( @Field1, @Field2, @Field3 ) ;";
43+
$"SELECT [Field1], [Field2], [Field3] " +
44+
$"FROM ( " +
45+
$"VALUES ( @Field1, @Field2, @Field3 , @__RepoDb_OrderColumn_0 ) " +
46+
$") AS T " +
47+
$"( [Field1], [Field2], [Field3] , [__RepoDb_OrderColumn] ) " +
48+
$"ORDER BY [__RepoDb_OrderColumn] ;";
4549

4650
// Assert
4751
Assert.AreEqual(expected, actual);
@@ -64,8 +68,13 @@ public void TestBaseStatementBuilderCreateInsertAllWithQuotedTableSchema()
6468
var expected = $"" +
6569
$"INSERT INTO [dbo].[Table] " +
6670
$"( [Field1], [Field2], [Field3] ) " +
67-
$"VALUES " +
68-
$"( @Field1, @Field2, @Field3 ) ;";
71+
$"SELECT [Field1], [Field2], [Field3] " +
72+
$"FROM " +
73+
$"( " +
74+
$"VALUES ( @Field1, @Field2, @Field3 , @__RepoDb_OrderColumn_0 ) " +
75+
$") AS T " +
76+
$"( [Field1], [Field2], [Field3] , [__RepoDb_OrderColumn] ) " +
77+
$"ORDER BY [__RepoDb_OrderColumn] ;";
6978

7079
// Assert
7180
Assert.AreEqual(expected, actual);
@@ -88,8 +97,14 @@ public void TestBaseStatementBuilderCreateInsertAllWithUnquotedTableSchema()
8897
var expected = $"" +
8998
$"INSERT INTO [dbo].[Table] " +
9099
$"( [Field1], [Field2], [Field3] ) " +
100+
$"SELECT [Field1], [Field2], [Field3] " +
101+
$"FROM " +
102+
$"( " +
91103
$"VALUES " +
92-
$"( @Field1, @Field2, @Field3 ) ;";
104+
$"( @Field1, @Field2, @Field3 , @__RepoDb_OrderColumn_0 ) " +
105+
$") AS T " +
106+
$"( [Field1], [Field2], [Field3] , [__RepoDb_OrderColumn] ) " +
107+
$"ORDER BY [__RepoDb_OrderColumn] ;";
93108

94109
// Assert
95110
Assert.AreEqual(expected, actual);
@@ -113,8 +128,14 @@ public void TestBaseStatementBuilderCreateInsertAllWithPrimary()
113128
var expected = $"" +
114129
$"INSERT INTO [Table] " +
115130
$"( [Field1], [Field2], [Field3] ) " +
131+
$"SELECT [Field1], [Field2], [Field3] " +
132+
$"FROM " +
133+
$"( " +
116134
$"VALUES " +
117-
$"( @Field1, @Field2, @Field3 ) ;";
135+
$"( @Field1, @Field2, @Field3 , @__RepoDb_OrderColumn_0 ) " +
136+
$") AS T " +
137+
$"( [Field1], [Field2], [Field3] , [__RepoDb_OrderColumn] ) " +
138+
$"ORDER BY [__RepoDb_OrderColumn] ;";
118139

119140
// Assert
120141
Assert.AreEqual(expected, actual);
@@ -138,16 +159,15 @@ public void TestBaseStatementBuilderCreateInsertAllForThreeBatches()
138159
var expected = $"" +
139160
$"INSERT INTO [Table] " +
140161
$"( [Field2], [Field3] ) " +
162+
$"SELECT [Field2], [Field3] " +
163+
$"FROM ( " +
141164
$"VALUES " +
142-
$"( @Field2, @Field3 ) ; " +
143-
$"INSERT INTO [Table] " +
144-
$"( [Field2], [Field3] ) " +
145-
$"VALUES " +
146-
$"( @Field2_1, @Field3_1 ) ; " +
147-
$"INSERT INTO [Table] " +
148-
$"( [Field2], [Field3] ) " +
149-
$"VALUES " +
150-
$"( @Field2_2, @Field3_2 ) ;";
165+
$"( @Field2, @Field3 , @__RepoDb_OrderColumn_0 ) , " +
166+
$"( @Field2_1, @Field3_1 , @__RepoDb_OrderColumn_1 ) , " +
167+
$"( @Field2_2, @Field3_2 , @__RepoDb_OrderColumn_2 ) " +
168+
$") AS T " +
169+
$"( [Field2], [Field3] , [__RepoDb_OrderColumn] ) " +
170+
$"ORDER BY [__RepoDb_OrderColumn] ;";
151171

152172
// Assert
153173
Assert.AreEqual(expected, actual);
@@ -171,8 +191,14 @@ public void TestBaseStatementBuilderCreateInsertAllWithHints()
171191
var expected = $"" +
172192
$"INSERT INTO [Table] WITH (TABLOCK) " +
173193
$"( [Field1], [Field2], [Field3] ) " +
194+
$"SELECT [Field1], [Field2], [Field3] " +
195+
$"FROM ( " +
174196
$"VALUES " +
175-
$"( @Field1, @Field2, @Field3 ) ;";
197+
$"( " +
198+
$"@Field1, @Field2, @Field3 , @__RepoDb_OrderColumn_0 ) " +
199+
$") AS T " +
200+
$"( [Field1], [Field2], [Field3] , [__RepoDb_OrderColumn] ) " +
201+
$"ORDER BY [__RepoDb_OrderColumn] ;";
176202

177203
// Assert
178204
Assert.AreEqual(expected, actual);
@@ -197,16 +223,15 @@ public void TestBaseStatementBuilderCreateInsertAllForThreeBatchesWithHints()
197223
var expected = $"" +
198224
$"INSERT INTO [Table] WITH (TABLOCK) " +
199225
$"( [Field2], [Field3] ) " +
226+
$"SELECT [Field2], [Field3] " +
227+
$"FROM ( " +
200228
$"VALUES " +
201-
$"( @Field2, @Field3 ) ; " +
202-
$"INSERT INTO [Table] WITH (TABLOCK) " +
203-
$"( [Field2], [Field3] ) " +
204-
$"VALUES " +
205-
$"( @Field2_1, @Field3_1 ) ; " +
206-
$"INSERT INTO [Table] WITH (TABLOCK) " +
207-
$"( [Field2], [Field3] ) " +
208-
$"VALUES " +
209-
$"( @Field2_2, @Field3_2 ) ;";
229+
$"( @Field2, @Field3 , @__RepoDb_OrderColumn_0 ) , " +
230+
$"( @Field2_1, @Field3_1 , @__RepoDb_OrderColumn_1 ) , " +
231+
$"( @Field2_2, @Field3_2 , @__RepoDb_OrderColumn_2 ) " +
232+
$") AS T " +
233+
$"( [Field2], [Field3] , [__RepoDb_OrderColumn] ) " +
234+
$"ORDER BY [__RepoDb_OrderColumn] ;";
210235

211236
// Assert
212237
Assert.AreEqual(expected, actual);

0 commit comments

Comments
 (0)