Skip to content

Commit a89ae6e

Browse files
author
Jason Valdez
committed
Added no parameter constructor to BulkLoader for backward compatibility
1 parent adb91c9 commit a89ae6e

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Linq;
2+
using FluentAssertions;
3+
using ivaldez.Sql.IntegrationTests.Data;
4+
using ivaldez.Sql.SqlBulkLoader;
5+
using Xunit;
6+
7+
namespace ivaldez.Sql.IntegrationTests.BulkLoading
8+
{
9+
public class BulkLoaderForDefaultBulkCopyUtilityTests
10+
{
11+
[Fact]
12+
public void ShouldUseDefaultBulkCopyUtilityWhenNoConstructorParams()
13+
{
14+
var testingDatabaseService = new TestingDatabaseService();
15+
testingDatabaseService.CreateTestDatabase();
16+
17+
var dataGateway = new TestingDataGateway(testingDatabaseService);
18+
19+
dataGateway.DropTable();
20+
dataGateway.CreateSingleSurrogateKeyTable();
21+
22+
var dtos = new[]
23+
{
24+
new SampleSurrogateKey
25+
{
26+
Pk = 100,
27+
TextValue = "JJ",
28+
IntValue = 100,
29+
DecimalValue = 100.99m
30+
},
31+
new SampleSurrogateKey
32+
{
33+
Pk = 200,
34+
TextValue = "ZZ",
35+
IntValue = 999,
36+
DecimalValue = 123.45m
37+
}
38+
};
39+
40+
dataGateway.ExecuteWithConnection(conn =>
41+
{
42+
new BulkLoader()
43+
.InsertWithOptions("Sample", conn, true, dtos)
44+
.Without(c => c.Pk)
45+
.Execute();
46+
});
47+
48+
var databaseDtos = dataGateway.GetAllSampleSurrogateKey().ToArray();
49+
50+
var firstDto = databaseDtos.First(x => x.TextValue == "JJ");
51+
firstDto.IntValue.Should().Be(100);
52+
firstDto.DecimalValue.Should().Be(100.99m);
53+
54+
var secondDto = databaseDtos.First(x => x.TextValue == "ZZ");
55+
secondDto.IntValue.Should().Be(999);
56+
secondDto.DecimalValue.Should().Be(123.45m);
57+
}
58+
}
59+
}

src/IntegrationTests/IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<Compile Include="BulkLoading\BulkLoaderForBatchSizeTests.cs" />
7373
<Compile Include="BulkLoading\BulkLoaderForFieldOptionsTests.cs" />
7474
<Compile Include="BulkLoading\BulkLoaderForPrimaryKeyTests.cs" />
75+
<Compile Include="BulkLoading\BulkLoaderForDefaultBulkCopyUtilityTests.cs" />
7576
<Compile Include="BulkLoading\BulkLoaderGeneralTests.cs" />
7677
<Compile Include="BulkLoading\SqlBulkCopyUtilitySpy.cs" />
7778
<Compile Include="Data\SampleSurrogateKeyDifferentNamesDto.cs" />

src/ivaldez.SqlBulkLoader/BulkLoader.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public class BulkLoader : IBulkLoader
1515
{
1616
private readonly ISqlBulkCopyUtility _sqlBulkCopyUtility;
1717

18+
public BulkLoader()
19+
{
20+
_sqlBulkCopyUtility = new SqlBulkCopyUtility();
21+
}
22+
1823
public BulkLoader(ISqlBulkCopyUtility sqlBulkCopyUtility)
1924
{
2025
_sqlBulkCopyUtility = sqlBulkCopyUtility;

0 commit comments

Comments
 (0)