Skip to content

Commit 7355375

Browse files
authored
Merge pull request #3 from JasonDV/feature/AddPostgreSQL
Feature/add postgre sql
2 parents 9f058aa + d46b8a2 commit 7355375

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1906
-35
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System.Linq;
2+
using FluentAssertions;
3+
using ivaldez.Sql.IntegrationPostgreSqlTests.Data;
4+
using ivaldez.SqlBulkLoader.PostgreSql;
5+
using Xunit;
6+
7+
namespace ivaldez.Sql.IntegrationPostgreSqlTests.BulkLoading
8+
{
9+
public class BulkLoaderForBatchSizeTests
10+
{
11+
[Fact]
12+
public void ShouldBatchBulkCopyCommandsByOptionValue()
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+
var sqlBulkCopyUtilitySpy = new SqlBulkCopyUtilitySpy();
41+
42+
dataGateway.ExecuteWithConnection(conn =>
43+
{
44+
new BulkLoader(sqlBulkCopyUtilitySpy)
45+
.InsertWithOptions("sample", conn, true, dtos)
46+
.IdentityColumn(c => c.Pk)
47+
.SetBatchSize(1)
48+
.Execute();
49+
});
50+
51+
sqlBulkCopyUtilitySpy.BulkCopyCalled.Should().Be(2);
52+
53+
var databaseDtos = dataGateway.GetAllSampleSurrogateKey().ToArray();
54+
55+
var firstDto = databaseDtos.First(x => x.TextValue == "JJ");
56+
firstDto.IntValue.Should().Be(100);
57+
firstDto.DecimalValue.Should().Be(100.99m);
58+
59+
var secondDto = databaseDtos.First(x => x.TextValue == "ZZ");
60+
secondDto.IntValue.Should().Be(999);
61+
secondDto.DecimalValue.Should().Be(123.45m);
62+
}
63+
}
64+
}
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.IntegrationPostgreSqlTests.Data;
4+
using ivaldez.SqlBulkLoader.PostgreSql;
5+
using Xunit;
6+
7+
namespace ivaldez.Sql.IntegrationPostgreSqlTests.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+
.IdentityColumn(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+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
using System.Linq;
2+
using FluentAssertions;
3+
using ivaldez.Sql.IntegrationPostgreSqlTests.Data;
4+
using ivaldez.SqlBulkLoader.PostgreSql;
5+
using Xunit;
6+
7+
namespace ivaldez.Sql.IntegrationPostgreSqlTests.BulkLoading
8+
{
9+
public class BulkLoaderForFieldOptionsTests
10+
{
11+
12+
[Fact]
13+
public void ShouldRespectRenamedFields()
14+
{
15+
var testingDatabaseService = new TestingDatabaseService();
16+
testingDatabaseService.CreateTestDatabase();
17+
18+
var dataGateway = new TestingDataGateway(testingDatabaseService);
19+
20+
dataGateway.DropTable();
21+
dataGateway.CreateSingleSurrogateKeyTable();
22+
23+
var dtos = new[]
24+
{
25+
new SampleSurrogateKeyDifferentNamesDto
26+
{
27+
Pk = 100,
28+
TextValueExtra = "JJ",
29+
IntValueExtra = 100,
30+
DecimalValueExtra = 100.99m
31+
},
32+
new SampleSurrogateKeyDifferentNamesDto
33+
{
34+
Pk = 200,
35+
TextValueExtra = "ZZ",
36+
IntValueExtra = 999,
37+
DecimalValueExtra = 123.45m
38+
}
39+
};
40+
41+
dataGateway.ExecuteWithConnection(conn =>
42+
{
43+
BulkLoaderFactory.Create()
44+
.InsertWithOptions("sample", conn, true, dtos)
45+
.IdentityColumn(c => c.Pk)
46+
.With(c => c.TextValueExtra, "TextValue")
47+
.With(c => c.IntValueExtra, "IntValue")
48+
.With(c => c.DecimalValueExtra, "DecimalValue")
49+
.Execute();
50+
});
51+
52+
var databaseDtos = dataGateway.GetAllSampleSurrogateKey().ToArray();
53+
54+
var firstDto = databaseDtos.First(x => x.TextValue == "JJ");
55+
firstDto.Pk.Should().Be(100);
56+
firstDto.IntValue.Should().Be(100);
57+
firstDto.DecimalValue.Should().Be(100.99m);
58+
59+
var secondDto = databaseDtos.First(x => x.TextValue == "ZZ");
60+
secondDto.Pk.Should().Be(200);
61+
secondDto.IntValue.Should().Be(999);
62+
secondDto.DecimalValue.Should().Be(123.45m);
63+
}
64+
65+
[Fact]
66+
public void ShouldRespectTheWithoutOption()
67+
{
68+
var testingDatabaseService = new TestingDatabaseService();
69+
testingDatabaseService.CreateTestDatabase();
70+
71+
var dataGateway = new TestingDataGateway(testingDatabaseService);
72+
73+
dataGateway.DropTable();
74+
dataGateway.CreateSingleSurrogateKeyTable();
75+
76+
var dtos = new[]
77+
{
78+
new SampleSurrogateKey()
79+
{
80+
Pk = 100,
81+
TextValue = "JJ",
82+
IntValue = 100,
83+
DecimalValue = 100.99m
84+
},
85+
new SampleSurrogateKey
86+
{
87+
Pk = 200,
88+
TextValue = "ZZ",
89+
IntValue = 999,
90+
DecimalValue = 123.45m
91+
}
92+
};
93+
94+
dataGateway.ExecuteWithConnection(conn =>
95+
{
96+
BulkLoaderFactory.Create()
97+
.InsertWithOptions("sample", conn, true, dtos)
98+
.IdentityColumn(c => c.Pk)
99+
.Without("DecimalValue")
100+
.Without(t => t.IntValue)
101+
.Execute();
102+
});
103+
104+
var databaseDtos = dataGateway.GetAllSampleSurrogateKey().ToArray();
105+
106+
var firstDto = databaseDtos.First(x => x.TextValue == "JJ");
107+
firstDto.Pk.Should().Be(100);
108+
firstDto.IntValue.Should().BeNull();
109+
firstDto.DecimalValue.Should().BeNull();
110+
111+
var secondDto = databaseDtos.First(x => x.TextValue == "ZZ");
112+
secondDto.Pk.Should().Be(200);
113+
secondDto.IntValue.Should().BeNull();
114+
secondDto.DecimalValue.Should().BeNull();
115+
}
116+
117+
[Fact]
118+
public void ShouldHaveAccessToRenameRules()
119+
{
120+
var testingDatabaseService = new TestingDatabaseService();
121+
testingDatabaseService.CreateTestDatabase();
122+
123+
var dataGateway = new TestingDataGateway(testingDatabaseService);
124+
125+
dataGateway.DropTable();
126+
dataGateway.CreateSingleSurrogateKeyTable();
127+
128+
var dtos = new[]
129+
{
130+
new SampleSurrogateKeyDifferentNamesDto
131+
{
132+
Pk = 100,
133+
TextValueExtra = "JJ",
134+
IntValueExtra = 100,
135+
DecimalValueExtra = 100.99m
136+
},
137+
new SampleSurrogateKeyDifferentNamesDto
138+
{
139+
Pk = 200,
140+
TextValueExtra = "ZZ",
141+
IntValueExtra = 999,
142+
DecimalValueExtra = 123.45m
143+
}
144+
};
145+
146+
var bulkLoader = BulkLoaderFactory.Create()
147+
.InsertWithOptions("sample", null, true, dtos)
148+
.With(c => c.TextValueExtra, "TextValue")
149+
.With(c => c.IntValueExtra, "IntValue")
150+
.With(c => c.DecimalValueExtra, "DecimalValue");
151+
152+
var renameRules = bulkLoader.GetRenameRules();
153+
renameRules.Keys.Count().Should().Be(3);
154+
renameRules.First(x => x.Key == "TextValueExtra").Value.Should().Be("TextValue");
155+
renameRules.First(x => x.Key == "IntValueExtra").Value.Should().Be("IntValue");
156+
renameRules.First(x => x.Key == "DecimalValueExtra").Value.Should().Be("DecimalValue");
157+
}
158+
}
159+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.Linq;
2+
using FluentAssertions;
3+
using ivaldez.Sql.IntegrationPostgreSqlTests.Data;
4+
using ivaldez.SqlBulkLoader.PostgreSql;
5+
using Xunit;
6+
7+
namespace ivaldez.Sql.IntegrationPostgreSqlTests.BulkLoading
8+
{
9+
public class BulkLoaderForNoBatchTests
10+
{
11+
[Fact]
12+
public void ShouldNotBatchWhenOptionSelected()
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+
var sqlBulkCopyUtilitySpy = new SqlBulkCopyUtilitySpy();
41+
42+
dataGateway.ExecuteWithConnection(conn =>
43+
{
44+
new BulkLoader(sqlBulkCopyUtilitySpy)
45+
.InsertWithOptions("sample", conn, true, dtos)
46+
.IdentityColumn(c => c.Pk)
47+
.SetBatchSize(1)
48+
.NoBatch()
49+
.Execute();
50+
});
51+
52+
sqlBulkCopyUtilitySpy.BulkCopyCalled.Should().Be(1);
53+
54+
var databaseDtos = dataGateway.GetAllSampleSurrogateKey().ToArray();
55+
56+
var firstDto = databaseDtos.First(x => x.TextValue == "JJ");
57+
firstDto.IntValue.Should().Be(100);
58+
firstDto.DecimalValue.Should().Be(100.99m);
59+
60+
var secondDto = databaseDtos.First(x => x.TextValue == "ZZ");
61+
secondDto.IntValue.Should().Be(999);
62+
secondDto.DecimalValue.Should().Be(123.45m);
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)