11using FluentAssertions ;
2+ using FluentAssertions . Extensions ;
23
34using PhenX . EntityFrameworkCore . BulkInsert . Enums ;
45using PhenX . EntityFrameworkCore . BulkInsert . Extensions ;
@@ -35,8 +36,8 @@ public async Task InsertsEntities(InsertStrategy strategy)
3536 // Arrange
3637 var entities = new List < TestEntity >
3738 {
38- new TestEntity { Name = $ "{ _run } _Entity1" } ,
39- new TestEntity { Name = $ "{ _run } _Entity2" }
39+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity1" } ,
40+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity2" }
4041 } ;
4142
4243 // Act
@@ -56,11 +57,13 @@ public async Task InsertEntities_WithJson(InsertStrategy strategy)
5657 {
5758 new TestEntityWithJson
5859 {
60+ TestRun = _run ,
5961 JsonArray = [ 1 ] ,
6062 JsonObject = new JsonDbObject { Code = 1 , Name = "Test1" } ,
6163 } ,
6264 new TestEntityWithJson
6365 {
66+ TestRun = _run ,
6467 JsonArray = [ 2 ] ,
6568 JsonObject = new JsonDbObject { Code = 2 , Name = "Test2" } ,
6669 } ,
@@ -109,8 +112,8 @@ public async Task InsertEntities_MoveRows(InsertStrategy strategy)
109112 // Arrange
110113 var entities = new List < TestEntity >
111114 {
112- new TestEntity { Name = $ "{ _run } _Entity1" } ,
113- new TestEntity { Name = $ "{ _run } _Entity2" }
115+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity1" } ,
116+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity2" }
114117 } ;
115118
116119 // Act
@@ -149,6 +152,7 @@ public async Task InsertEntities_Many(InsertStrategy strategy)
149152 var entities = Enumerable . Range ( 1 , count ) . Select ( i => new TestEntity
150153 {
151154 Identifier = Guid . NewGuid ( ) ,
155+ TestRun = _run ,
152156 Name = $ "{ _run } _Entity{ i } ",
153157 NumericEnumValue = ( NumericEnum ) ( i % 2 ) ,
154158 Price = ( decimal ) ( i * 0.1 ) ,
@@ -176,8 +180,8 @@ public async Task InsertEntities_AndReturn_WithEntityWithValueConverters(InsertS
176180
177181 var entities = new List < TestEntityWithConverters >
178182 {
179- new TestEntityWithConverters ( ) { Name = $ "{ _run } _Entity1", CreatedAt = now , Uri = null } ,
180- new TestEntityWithConverters ( ) { Name = $ "{ _run } _Entity2", CreatedAt = now . AddDays ( - 1 ) , Uri = new Uri ( "http://example.com/test" ) }
183+ new TestEntityWithConverters ( ) { TestRun = _run , Name = $ "{ _run } _Entity1", CreatedAt = now , Uri = null } ,
184+ new TestEntityWithConverters ( ) { TestRun = _run , Name = $ "{ _run } _Entity2", CreatedAt = now . AddDays ( - 1 ) , Uri = new Uri ( "http://example.com/test" ) }
181185 } ;
182186
183187 // Act
@@ -240,8 +244,8 @@ public async Task ThrowsWhenUsingWrongConfigurationType()
240244 // Arrange
241245 var entities = new List < TestEntity >
242246 {
243- new TestEntity { Name = $ "{ _run } _Entity1" } ,
244- new TestEntity { Name = $ "{ _run } _Entity2" }
247+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity1" } ,
248+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity2" }
245249 } ;
246250
247251 // Act & Assert
@@ -277,8 +281,8 @@ public async Task InsertEntities_WithGeneratedGuidId(InsertStrategy strategy)
277281 // Arrange
278282 var entities = new List < TestEntityWithGuidId >
279283 {
280- new TestEntityWithGuidId { Id = Guid . NewGuid ( ) , Name = $ "{ _run } _Entity1" } ,
281- new TestEntityWithGuidId { Id = Guid . NewGuid ( ) , Name = $ "{ _run } _Entity2" }
284+ new TestEntityWithGuidId { TestRun = _run , Id = Guid . NewGuid ( ) , Name = $ "{ _run } _Entity1" } ,
285+ new TestEntityWithGuidId { TestRun = _run , Id = Guid . NewGuid ( ) , Name = $ "{ _run } _Entity2" }
282286 } ;
283287
284288 // Act
@@ -299,16 +303,16 @@ public async Task HandleProgress(InsertStrategy strategy)
299303 // Arrange
300304 var entities = new List < TestEntity >
301305 {
302- new TestEntity { Name = $ "{ _run } _Entity1" } ,
303- new TestEntity { Name = $ "{ _run } _Entity2" } ,
304- new TestEntity { Name = $ "{ _run } _Entity3" } ,
305- new TestEntity { Name = $ "{ _run } _Entity4" } ,
306- new TestEntity { Name = $ "{ _run } _Entity5" } ,
307- new TestEntity { Name = $ "{ _run } _Entity6" } ,
308- new TestEntity { Name = $ "{ _run } _Entity7" } ,
309- new TestEntity { Name = $ "{ _run } _Entity8" } ,
310- new TestEntity { Name = $ "{ _run } _Entity9" } ,
311- new TestEntity { Name = $ "{ _run } _Entity10" } ,
306+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity1" } ,
307+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity2" } ,
308+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity3" } ,
309+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity4" } ,
310+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity5" } ,
311+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity6" } ,
312+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity7" } ,
313+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity8" } ,
314+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity9" } ,
315+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity10" } ,
312316 } ;
313317
314318 long progressCount = 0 ;
@@ -337,10 +341,10 @@ public async Task HandleNoProgress(InsertStrategy strategy)
337341 // Arrange
338342 var entities = new List < TestEntity >
339343 {
340- new TestEntity { Name = $ "{ _run } _Entity1" } ,
341- new TestEntity { Name = $ "{ _run } _Entity2" } ,
342- new TestEntity { Name = $ "{ _run } _Entity3" } ,
343- new TestEntity { Name = $ "{ _run } _Entity4" } ,
344+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity1" } ,
345+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity2" } ,
346+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity3" } ,
347+ new TestEntity { TestRun = _run , Name = $ "{ _run } _Entity4" } ,
344348 } ;
345349
346350 var callCount = 0 ;
@@ -355,4 +359,88 @@ await _context.InsertWithStrategyAsync(strategy, entities, o =>
355359 // Assert
356360 Assert . Equal ( 0 , callCount ) ;
357361 }
362+
363+ [ SkippableTheory ]
364+ [ CombinatorialData ]
365+ public async Task InsertEntities_WithAllSimpleTypes ( InsertStrategy strategy )
366+ {
367+ // Arrange
368+ var entities = new List < TestEntityWithSimpleTypes >
369+ {
370+ new TestEntityWithSimpleTypes
371+ {
372+ TestRun = _run ,
373+ Id = 1 ,
374+ BoolValue = true ,
375+ ByteValue = 1 ,
376+ ByteArrayValue =
377+ [
378+ 1 ,
379+ 2 ,
380+ 3
381+ ] ,
382+ SByteValue = - 1 ,
383+ ShortValue = 2 ,
384+ IntValue = 3 ,
385+ LongValue = 4 ,
386+ FloatValue = 5.5f ,
387+ DoubleValue = 6.6 ,
388+ DecimalValue = 7.7m ,
389+ DateTimeValue = DateTime . UtcNow ,
390+ DateTimeOffsetValue = DateTimeOffset . UtcNow ,
391+ TimeSpanValue = TimeSpan . FromHours ( 1 ) ,
392+ StringValue = "Test String 2" ,
393+ CharValue = 'a' ,
394+ UShortValue = 10 ,
395+ UIntValue = 50 ,
396+ ULongValue = 200 ,
397+ DateOnlyValue = DateOnly . Parse ( "1985-10-31" ) ,
398+ TimeOnlyValue = TimeOnly . Parse ( "12:00:00" ) ,
399+ GuidValue = Guid . NewGuid ( ) ,
400+ } ,
401+ new TestEntityWithSimpleTypes
402+ {
403+ TestRun = _run ,
404+ Id = 2 ,
405+ BoolValue = false ,
406+ ByteValue = 10 ,
407+ ByteArrayValue =
408+ [
409+ 4 ,
410+ 5 ,
411+ 6
412+ ] ,
413+ SByteValue = - 10 ,
414+ ShortValue = 20 ,
415+ IntValue = 30 ,
416+ LongValue = 40 ,
417+ FloatValue = 50.5f ,
418+ DoubleValue = 60.6 ,
419+ DecimalValue = 70.7m ,
420+ DateTimeValue = DateTime . UtcNow . AddDays ( 1 ) ,
421+ DateTimeOffsetValue = DateTimeOffset . UtcNow . AddDays ( 1 ) ,
422+ TimeSpanValue = TimeSpan . FromHours ( 2 ) ,
423+ StringValue = "Test String 2" ,
424+ CharValue = 'b' ,
425+ UShortValue = 50 ,
426+ UIntValue = 20 ,
427+ ULongValue = 100 ,
428+ DateOnlyValue = DateOnly . Parse ( "2023-10-01" ) ,
429+ TimeOnlyValue = TimeOnly . Parse ( "12:00:00" ) ,
430+ GuidValue = Guid . NewGuid ( ) ,
431+ }
432+ } ;
433+
434+ // Act
435+ var insertedEntities = await _context . InsertWithStrategyAsync ( strategy , entities ) ;
436+
437+ // Assert
438+ insertedEntities . Should ( )
439+ . BeEquivalentTo ( entities , o => o
440+ . Using < DateTime > ( ctx => ctx . Subject . Should ( ) . BeCloseTo ( ctx . Expectation , 1 . Seconds ( ) ) ) . WhenTypeIs < DateTime > ( )
441+ . Using < DateTimeOffset > ( ctx => ctx . Subject . Should ( ) . BeCloseTo ( ctx . Expectation , 1 . Seconds ( ) ) ) . WhenTypeIs < DateTimeOffset > ( )
442+ . RespectingRuntimeTypes ( )
443+ . Excluding ( e => e . Id )
444+ ) ;
445+ }
358446}
0 commit comments