33using PhenX . EntityFrameworkCore . BulkInsert . Enums ;
44using PhenX . EntityFrameworkCore . BulkInsert . Extensions ;
55using PhenX . EntityFrameworkCore . BulkInsert . MySql ;
6- using PhenX . EntityFrameworkCore . BulkInsert . Options ;
76using PhenX . EntityFrameworkCore . BulkInsert . SqlServer ;
87using PhenX . EntityFrameworkCore . BulkInsert . Tests . DbContainer ;
98using PhenX . EntityFrameworkCore . BulkInsert . Tests . DbContext ;
@@ -45,7 +44,7 @@ public async Task InsertsEntities(InsertStrategy strategy)
4544
4645 // Assert
4746 insertedEntities . Should ( ) . BeEquivalentTo ( entities ,
48- o => o . RespectingRuntimeTypes ( ) . Excluding ( ( TestEntity e ) => e . Id ) ) ;
47+ o => o . RespectingRuntimeTypes ( ) . Excluding ( e => e . Id ) ) ;
4948 }
5049
5150 [ SkippableTheory ]
@@ -64,7 +63,7 @@ public async Task InsertEntities_WithJson(InsertStrategy strategy)
6463
6564 // Assert
6665 insertedEntities . Should ( ) . BeEquivalentTo ( entities ,
67- o => o . RespectingRuntimeTypes ( ) . Excluding ( ( TestEntityWithJson e ) => e . Id ) ) ;
66+ o => o . RespectingRuntimeTypes ( ) . Excluding ( e => e . Id ) ) ;
6867 }
6968
7069 [ SkippableFact ]
@@ -90,100 +89,7 @@ public async Task InsertEntities_AndReturn_AsyncEnumerable()
9089
9190 // Assert
9291 insertedEntities . Should ( ) . BeEquivalentTo ( entities ,
93- o => o . RespectingRuntimeTypes ( ) . Excluding ( ( TestEntity e ) => e . Id ) ) ;
94- }
95-
96- [ SkippableTheory ]
97- [ CombinatorialData ]
98- public async Task InsertEntities_MultipleTimes ( InsertStrategy strategy )
99- {
100- Skip . If ( _context . IsProvider ( ProviderType . PostgreSql ) ) ;
101- Skip . If ( _context . IsProvider ( ProviderType . SqlServer ) ) ;
102-
103- // Arrange
104- var entities = new List < TestEntity >
105- {
106- new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity1" } ,
107- new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity2" }
108- } ;
109-
110- // Act
111- await _context . InsertWithStrategyAsync ( strategy , entities ) ;
112-
113- foreach ( var entity in entities )
114- {
115- entity . NumericEnumValue = NumericEnum . Second ;
116- }
117-
118- var insertedEntities = await _context . InsertWithStrategyAsync ( strategy , entities ,
119- onConflict : new OnConflictOptions < TestEntity >
120- {
121- Update = e => e ,
122- } ) ;
123-
124- // Assert
125- insertedEntities . Should ( ) . BeEquivalentTo ( entities ,
126- o => o . RespectingRuntimeTypes ( ) . Excluding ( ( TestEntity e ) => e . Id ) ) ;
127- }
128-
129- [ SkippableTheory ]
130- [ CombinatorialData ]
131- public async Task InsertEntities_MultipleTimes_WithGuidId ( InsertStrategy strategy )
132- {
133- // Arrange
134- var entities = new List < TestEntityWithGuidId >
135- {
136- new TestEntityWithGuidId { Id = Guid . NewGuid ( ) , Name = $ "{ _run } _Entity1" } ,
137- new TestEntityWithGuidId { Id = Guid . NewGuid ( ) , Name = $ "{ _run } _Entity2" }
138- } ;
139-
140- // Act
141- await _context . ExecuteBulkInsertAsync ( entities ) ;
142-
143- foreach ( var entity in entities )
144- {
145- entity . Name = $ "Updated_{ entity . Name } ";
146- }
147-
148- var insertedEntities = await _context . InsertWithStrategyAsync ( strategy , entities ,
149- onConflict : new OnConflictOptions < TestEntityWithGuidId >
150- {
151- Update = e => e ,
152- } ) ;
153-
154- // Assert
155- insertedEntities . Should ( ) . BeEquivalentTo ( entities ,
156- o => o . RespectingRuntimeTypes ( ) . Excluding ( ( TestEntityWithGuidId e ) => e . Id ) ) ;
157- }
158-
159- [ SkippableTheory ]
160- [ CombinatorialData ]
161- public async Task InsertEntities_MultipleTimes_With_Conflict_On_Id ( InsertStrategy strategy )
162- {
163- // Arrange
164- var entities = new List < TestEntity >
165- {
166- new TestEntity { Name = $ "{ _run } _Entity1" } ,
167- new TestEntity { Name = $ "{ _run } _Entity2" }
168- } ;
169-
170- // Act
171- var insertedEntities0 = await _context . InsertWithStrategyAsync ( strategy , entities ) ;
172- foreach ( var entity in insertedEntities0 )
173- {
174- entity . Name = $ "Updated_{ entity . Name } ";
175- }
176-
177- var insertedEntities1 = await _context . InsertWithStrategyAsync ( strategy , insertedEntities0 ,
178- o => o . CopyGeneratedColumns = true ,
179- onConflict : new OnConflictOptions < TestEntity >
180- {
181- Update = e => e ,
182- } ) ;
183-
184- // Assert
185- insertedEntities1 . Should ( ) . BeEquivalentTo ( insertedEntities0 ,
186- o => o . RespectingRuntimeTypes ( ) . Excluding ( ( TestEntity e ) => e . Id ) ) ;
92+ o => o . RespectingRuntimeTypes ( ) . Excluding ( e => e . Id ) ) ;
18793 }
18894
18995 [ SkippableTheory ]
@@ -205,149 +111,7 @@ public async Task InsertEntities_MoveRows(InsertStrategy strategy)
205111
206112 // Assert
207113 insertedEntities . Should ( ) . BeEquivalentTo ( entities ,
208- o => o . RespectingRuntimeTypes ( ) . Excluding ( ( TestEntity e ) => e . Id ) ) ;
209- }
210-
211- [ SkippableTheory ]
212- [ InlineData ( InsertStrategy . InsertReturn ) ]
213- [ InlineData ( InsertStrategy . InsertReturnAsync ) ]
214- public async Task InsertEntities_WithConflict_SingleColumn ( InsertStrategy strategy )
215- {
216- Skip . If ( _context . IsProvider ( ProviderType . MySql ) ) ;
217-
218- // Arrange
219- _context . TestEntities . Add ( new TestEntity { Name = $ "{ _run } _Entity1" } ) ;
220- _context . SaveChanges ( ) ;
221- _context . ChangeTracker . Clear ( ) ;
222-
223- var entities = new List < TestEntity >
224- {
225- new TestEntity { Name = $ "{ _run } _Entity1" } ,
226- new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity2" } ,
227- } ;
228-
229- // Act
230- var insertedEntities = await _context . InsertWithStrategyAsync ( strategy , entities , o =>
231- {
232- o . MoveRows = true ;
233- } , new OnConflictOptions < TestEntity >
234- {
235- Match = e => new
236- {
237- e . Name ,
238- } ,
239- Update = e => new TestEntity
240- {
241- Name = e . Name + " - Conflict" ,
242- } ,
243- } ) ;
244-
245- // Assert
246- Assert . Equal ( 2 , insertedEntities . Count ) ;
247- Assert . Contains ( insertedEntities , e => e . Name == $ "{ _run } _Entity1 - Conflict") ;
248- Assert . Contains ( insertedEntities , e => e . Name == $ "{ _run } _Entity2") ;
249- }
250-
251- [ SkippableTheory ]
252- [ InlineData ( InsertStrategy . Insert ) ]
253- [ InlineData ( InsertStrategy . InsertAsync ) ]
254- public async Task InsertEntities_WithConflict_DoNothing ( InsertStrategy strategy )
255- {
256- Skip . If ( _context . IsProvider ( ProviderType . MySql ) ) ;
257-
258- // Arrange
259- _context . TestEntities . Add ( new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity1" } ) ;
260- _context . SaveChanges ( ) ;
261- _context . ChangeTracker . Clear ( ) ;
262-
263- var entities = new List < TestEntity >
264- {
265- new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity1" } ,
266- new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity2" } ,
267- } ;
268-
269- // Act
270- var insertedEntities = await _context . InsertWithStrategyAsync ( strategy , entities , o =>
271- {
272- o . MoveRows = true ;
273- } , new OnConflictOptions < TestEntity >
274- {
275- Match = e => new { e . Name }
276- } ) ;
277-
278- // Assert
279- Assert . Equal ( 2 , insertedEntities . Count ) ;
280- Assert . Contains ( insertedEntities , e => e . Name == $ "{ _run } _Entity1") ;
281- Assert . Contains ( insertedEntities , e => e . Name == $ "{ _run } _Entity2") ;
282- }
283-
284- [ SkippableTheory ]
285- [ InlineData ( InsertStrategy . InsertReturn ) ]
286- [ InlineData ( InsertStrategy . InsertReturnAsync ) ]
287- public async Task InsertEntities_WithConflict_Condition ( InsertStrategy strategy )
288- {
289- Skip . If ( _context . IsProvider ( ProviderType . MySql ) ) ;
290-
291- // Arrange
292- _context . TestEntities . Add ( new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity1", Price = 10 } ) ;
293- _context . SaveChanges ( ) ;
294- _context . ChangeTracker . Clear ( ) ;
295-
296- var entities = new List < TestEntity >
297- {
298- new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity1", Price = 20 } ,
299- new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity2", Price = 30 } ,
300- } ;
301-
302- // Act
303- var insertedEntities = await _context . InsertWithStrategyAsync ( strategy , entities , o =>
304- {
305- o . MoveRows = true ;
306- } , new OnConflictOptions < TestEntity >
307- {
308- Match = e => new { e . Name } ,
309- Update = e => new TestEntity { Price = e . Price } ,
310- Condition = "EXCLUDED.some_price > test_entity.some_price"
311- } ) ;
312-
313- // Assert
314- Assert . Equal ( 2 , insertedEntities . Count ) ;
315- Assert . Contains ( insertedEntities , e => e . Name == $ "{ _run } _Entity1" && e . Price == 20 ) ;
316- Assert . Contains ( insertedEntities , e => e . Name == $ "{ _run } _Entity2" && e . Price == 30 ) ;
317- }
318-
319- [ SkippableTheory ]
320- [ InlineData ( InsertStrategy . InsertReturn ) ]
321- [ InlineData ( InsertStrategy . InsertReturnAsync ) ]
322- public async Task InsertEntities_WithConflict_MultipleColumns ( InsertStrategy strategy )
323- {
324- Skip . If ( _context . IsProvider ( ProviderType . MySql ) ) ;
325-
326- // Arrange
327- _context . TestEntities . Add ( new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity1", Price = 10 } ) ;
328- _context . SaveChanges ( ) ;
329- _context . ChangeTracker . Clear ( ) ;
330-
331- var entities = new List < TestEntity >
332- {
333- new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity1", Price = 20 , Identifier = Guid . NewGuid ( ) } ,
334- new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity2", Price = 30 , Identifier = Guid . NewGuid ( ) } ,
335- } ;
336-
337- // Act
338- var insertedEntities = await _context . InsertWithStrategyAsync ( strategy , entities , o =>
339- {
340- o . MoveRows = true ;
341- } , new OnConflictOptions < TestEntity >
342- {
343- Match = e => new { e . Name } ,
344- Update = e => new TestEntity { Name = e . Name + " - Conflict" , Price = 0 }
345- } ) ;
346-
347- // Assert
348- Assert . Equal ( 2 , insertedEntities . Count ) ;
349- Assert . Contains ( insertedEntities , e => e . Name == $ "{ _run } _Entity2") ;
350- Assert . Contains ( insertedEntities , e => e . Name == $ "{ _run } _Entity1 - Conflict" && e . Price == 0 ) ;
114+ o => o . RespectingRuntimeTypes ( ) . Excluding ( e => e . Id ) ) ;
351115 }
352116
353117 [ SkippableTheory ]
@@ -370,7 +134,7 @@ public async Task InsertEntities_DoesNothing_WhenEntitiesAreEmpty(InsertStrategy
370134 public async Task InsertEntities_Many ( InsertStrategy strategy )
371135 {
372136 // Arrange
373- const int count = 156055 ;
137+ const int count = 56055 ;
374138
375139 var entities = Enumerable . Range ( 1 , count ) . Select ( i => new TestEntity
376140 {
@@ -411,7 +175,7 @@ public async Task InsertEntities_AndReturn_WithEntityWithValueConverters(InsertS
411175
412176 // Assert
413177 insertedEntities . Should ( ) . BeEquivalentTo ( entities ,
414- o => o . RespectingRuntimeTypes ( ) . Excluding ( ( TestEntityWithConverters e ) => e . Id ) ) ;
178+ o => o . RespectingRuntimeTypes ( ) . Excluding ( e => e . Id ) ) ;
415179 }
416180
417181 [ SkippableTheory ]
@@ -432,7 +196,7 @@ public async Task InsertEntities_WithOpenTransaction_CommitsSuccessfully(InsertS
432196
433197 // Assert
434198 insertedEntities . Should ( ) . BeEquivalentTo ( entities ,
435- o => o . RespectingRuntimeTypes ( ) . Excluding ( ( TestEntity e ) => e . Id ) ) ;
199+ o => o . RespectingRuntimeTypes ( ) . Excluding ( e => e . Id ) ) ;
436200 }
437201
438202 [ SkippableTheory ]
@@ -456,7 +220,7 @@ public async Task InsertEntities_WithOpenTransaction_RollsBackOnFailure(InsertSt
456220 var insertedEntities = _context . TestEntities . Where ( x => x . TestRun == _run ) . ToList ( ) ;
457221 Assert . Empty ( insertedEntities ) ;
458222 }
459-
223+
460224 [ SkippableFact ]
461225 public async Task ThrowsWhenUsingWrongConfigurationType ( )
462226 {
@@ -474,23 +238,23 @@ public async Task ThrowsWhenUsingWrongConfigurationType()
474238 if ( _context . IsProvider ( ProviderType . SqlServer ) )
475239 {
476240 await Assert . ThrowsAsync < InvalidOperationException > ( async ( ) =>
477- await _context . ExecuteBulkInsertAsync ( entities , ( MySqlBulkInsertOptions o ) =>
241+ await _context . ExecuteBulkInsertAsync ( entities , ( MySqlBulkInsertOptions _ ) =>
478242 {
479243 } ) ) ;
480244 }
481245
482246 if ( _context . IsProvider ( ProviderType . MySql ) )
483247 {
484248 await Assert . ThrowsAsync < InvalidOperationException > ( async ( ) =>
485- await _context . ExecuteBulkInsertAsync ( entities , ( SqlServerBulkInsertOptions o ) =>
249+ await _context . ExecuteBulkInsertAsync ( entities , ( SqlServerBulkInsertOptions _ ) =>
486250 {
487251 } ) ) ;
488252 }
489253
490254 if ( _context . IsProvider ( ProviderType . PostgreSql ) )
491255 {
492256 await Assert . ThrowsAsync < InvalidOperationException > ( async ( ) =>
493- await _context . ExecuteBulkInsertAsync ( entities , ( SqlServerBulkInsertOptions o ) =>
257+ await _context . ExecuteBulkInsertAsync ( entities , ( SqlServerBulkInsertOptions _ ) =>
494258 {
495259 } ) ) ;
496260 }
0 commit comments