Skip to content

Commit 535e3f5

Browse files
authored
Nullable projection (#55)
* Test coverage + support for projection of nullable ints to bools and doubles * Test coverage for nullable int -> enum projection * Removing use of TryParse in nullable numeric -> numeric conversion / Expanding ORM simple type conversion test coverage * Support for projecting from enums and nullable enums -> strings * Support for projecting nullable DateTimes to strings / Removing string conversion test interfaces * Test coverage for projecting nullable DateTime -> DateTime
1 parent 2d24608 commit 535e3f5

File tree

53 files changed

+697
-175
lines changed

Some content is hidden

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

53 files changed

+697
-175
lines changed

AgileMapper.UnitTests.Orms.Ef5.LocalDb/AgileMapper.UnitTests.Orms.Ef5.LocalDb.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
<Project>{66522d44-19f5-4af5-9d43-483a3cd6f958}</Project>
9999
<Name>AgileMapper.UnitTests.Orms</Name>
100100
</ProjectReference>
101+
<ProjectReference Include="..\AgileMapper.UnitTests\AgileMapper.UnitTests.csproj">
102+
<Project>{A3F2D405-8C0B-4033-9EC5-1B64007593FB}</Project>
103+
<Name>AgileMapper.UnitTests</Name>
104+
</ProjectReference>
101105
</ItemGroup>
102106
<ItemGroup>
103107
<None Include="App.config" />

AgileMapper.UnitTests.Orms.Ef5.LocalDb/SimpleTypeConversion/WhenConvertingToDateTimes.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
using Orms.SimpleTypeConversion;
77
using Xunit;
88

9-
public class WhenConvertingToDateTimes :
10-
WhenConvertingToDateTimes<Ef5TestLocalDbContext>,
11-
IStringConverterTest,
12-
IStringConversionValidatorTest
9+
public class WhenConvertingToDateTimes : WhenConvertingToDateTimes<Ef5TestLocalDbContext>
1310
{
1411
public WhenConvertingToDateTimes(LocalDbTestContext<Ef5TestLocalDbContext> context)
1512
: base(context)
@@ -18,11 +15,11 @@ public WhenConvertingToDateTimes(LocalDbTestContext<Ef5TestLocalDbContext> conte
1815

1916
[Fact]
2017
public Task ShouldProjectAParseableString()
21-
=> RunShouldProjectAParseableStringToADateTime();
18+
=> DoShouldProjectAParseableStringToADateTime();
2219

2320
[Fact]
2421
public Task ShouldProjectANullString()
25-
=> RunShouldProjectANullStringToADateTime();
22+
=> DoShouldProjectANullStringToADateTime();
2623

2724
[Fact]
2825
public Task ShouldProjectAnUnparseableString()

AgileMapper.UnitTests.Orms.Ef5.LocalDb/SimpleTypeConversion/WhenConvertingToStrings.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,24 @@ public Task ShouldProjectADoubleToAString()
2424
[Fact]
2525
public Task ShouldProjectADateTimeToAString()
2626
=> DoShouldProjectADateTimeToAString(d => d.ToString("yyyy-%M-%d %H:%m:%s"));
27+
28+
[Fact]
29+
public Task ShouldProjectANullableDateTimeToAString()
30+
=> DoShouldProjectANullableDateTimeToAString(d => d.GetValueOrDefault().ToString("yyyy-%M-%d %H:%m:%s"));
31+
32+
[Fact]
33+
public Task ShouldProjectANullNullableDateTimeToAString()
34+
=> DoShouldProjectANullNullableDateTimeToAString();
35+
36+
[Fact]
37+
public Task ShouldProjectAnEnumToAString()
38+
=> DoShouldProjectAnEnumToAString(t => ((int)t).ToString());
39+
40+
[Fact]
41+
public Task ShouldProjectANullableEnumToAString()
42+
=> DoShouldProjectANullableEnumToAString(t => ((int)t.GetValueOrDefault()).ToString());
43+
44+
[Fact]
45+
public Task ShouldProjectANullNullableEnumToAString() => DoShouldProjectANullNullableEnumToAString();
2746
}
2847
}

AgileMapper.UnitTests.Orms.Ef5/Infrastructure/Ef5TestDbContext.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ protected Ef5TestDbContext(DbConnection dbConnection)
5353

5454
public DbSet<PublicInt> IntItems { get; set; }
5555

56+
public DbSet<PublicNullableInt> NullableIntItems { get; set; }
57+
5658
public DbSet<PublicLong> LongItems { get; set; }
5759

5860
public DbSet<PublicDecimal> DecimalItems { get; set; }
@@ -61,10 +63,14 @@ protected Ef5TestDbContext(DbConnection dbConnection)
6163

6264
public DbSet<PublicDateTime> DateTimeItems { get; set; }
6365

66+
public DbSet<PublicNullableDateTime> NullableDateTimeItems { get; set; }
67+
6468
public DbSet<PublicString> StringItems { get; set; }
6569

6670
public DbSet<PublicTitle> TitleItems { get; set; }
6771

72+
public DbSet<PublicNullableTitle> NullableTitleItems { get; set; }
73+
6874
protected override void OnModelCreating(DbModelBuilder modelBuilder)
6975
{
7076
modelBuilder
@@ -115,6 +121,8 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
115121

116122
IDbSetWrapper<PublicInt> ITestDbContext.IntItems => new Ef5DbSetWrapper<PublicInt>(this);
117123

124+
IDbSetWrapper<PublicNullableInt> ITestDbContext.NullableIntItems => new Ef5DbSetWrapper<PublicNullableInt>(this);
125+
118126
IDbSetWrapper<PublicLong> ITestDbContext.LongItems => new Ef5DbSetWrapper<PublicLong>(this);
119127

120128
IDbSetWrapper<PublicDecimal> ITestDbContext.DecimalItems => new Ef5DbSetWrapper<PublicDecimal>(this);
@@ -123,10 +131,14 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
123131

124132
IDbSetWrapper<PublicDateTime> ITestDbContext.DateTimeItems => new Ef5DbSetWrapper<PublicDateTime>(this);
125133

134+
IDbSetWrapper<PublicNullableDateTime> ITestDbContext.NullableDateTimeItems => new Ef5DbSetWrapper<PublicNullableDateTime>(this);
135+
126136
IDbSetWrapper<PublicString> ITestDbContext.StringItems => new Ef5DbSetWrapper<PublicString>(this);
127137

128138
IDbSetWrapper<PublicTitle> ITestDbContext.TitleItems => new Ef5DbSetWrapper<PublicTitle>(this);
129139

140+
IDbSetWrapper<PublicNullableTitle> ITestDbContext.NullableTitleItems => new Ef5DbSetWrapper<PublicNullableTitle>(this);
141+
130142
Task ITestDbContext.SaveChanges()
131143
{
132144
SaveChanges();

AgileMapper.UnitTests.Orms.Ef5/SimpleTypeConversion/WhenConvertingToDateTimes.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,20 @@
55
using Orms.SimpleTypeConversion;
66
using Xunit;
77

8-
public class WhenConvertingToDateTimes :
9-
WhenConvertingToDateTimes<Ef5TestDbContext>,
10-
IStringConversionFailureTest,
11-
IStringConversionValidationFailureTest
8+
public class WhenConvertingToDateTimes : WhenConvertingToDateTimes<Ef5TestDbContext>
129
{
1310
public WhenConvertingToDateTimes(InMemoryEf5TestContext context)
1411
: base(context)
1512
{
1613
}
1714

1815
[Fact]
19-
public Task ShouldErrorProjectingAParseableString()
20-
=> RunShouldErrorProjectingAParseableStringToADateTime();
16+
public Task ShouldProjectANullableDateTimeToADateTime()
17+
=> DoShouldProjectANullableDateTimeToADateTime();
2118

2219
[Fact]
23-
public Task ShouldErrorProjectingANullString()
24-
=> RunShouldErrorProjectingANullStringToADateTime();
20+
public Task ShouldProjectANullNullableDateTimeToADateTime()
21+
=> DoShouldProjectANullNullableDateTimeToADateTime();
2522

2623
[Fact]
2724
public Task ShouldErrorProjectingAnUnparseableString()

AgileMapper.UnitTests.Orms.Ef5/SimpleTypeConversion/WhenConvertingToDoubles.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
using Orms.SimpleTypeConversion;
66
using Xunit;
77

8-
public class WhenConvertingToDoubles :
9-
WhenConvertingToDoubles<Ef5TestDbContext>,
10-
IStringConversionFailureTest,
11-
IStringConversionValidationFailureTest
12-
8+
public class WhenConvertingToDoubles : WhenConvertingToDoubles<Ef5TestDbContext>
139
{
1410
public WhenConvertingToDoubles(InMemoryEf5TestContext context)
1511
: base(context)

AgileMapper.UnitTests.Orms.Ef5/SimpleTypeConversion/WhenConvertingToGuids.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
using Orms.SimpleTypeConversion;
66
using Xunit;
77

8-
public class WhenConvertingToGuids :
9-
WhenConvertingToGuids<Ef5TestDbContext>,
10-
IStringConversionFailureTest
8+
public class WhenConvertingToGuids : WhenConvertingToGuids<Ef5TestDbContext>
119
{
1210
public WhenConvertingToGuids(InMemoryEf5TestContext context)
1311
: base(context)

AgileMapper.UnitTests.Orms.Ef5/SimpleTypeConversion/WhenConvertingToInts.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
using Orms.SimpleTypeConversion;
66
using Xunit;
77

8-
public class WhenConvertingToInts :
9-
WhenConvertingToInts<Ef5TestDbContext>,
10-
IStringConversionFailureTest,
11-
IStringConversionValidationFailureTest
8+
public class WhenConvertingToInts : WhenConvertingToInts<Ef5TestDbContext>
129

1310
{
1411
public WhenConvertingToInts(InMemoryEf5TestContext context)

AgileMapper.UnitTests.Orms.Ef6.LocalDb/SimpleTypeConversion/WhenConvertingToDateTimes.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
using Orms.SimpleTypeConversion;
77
using Xunit;
88

9-
public class WhenConvertingToDateTimes :
10-
WhenConvertingToDateTimes<Ef6TestLocalDbContext>,
11-
IStringConverterTest,
12-
IStringConversionValidatorTest
9+
public class WhenConvertingToDateTimes : WhenConvertingToDateTimes<Ef6TestLocalDbContext>
1310
{
1411
public WhenConvertingToDateTimes(LocalDbTestContext<Ef6TestLocalDbContext> context)
1512
: base(context)
@@ -18,11 +15,11 @@ public WhenConvertingToDateTimes(LocalDbTestContext<Ef6TestLocalDbContext> conte
1815

1916
[Fact]
2017
public Task ShouldProjectAParseableString()
21-
=> RunShouldProjectAParseableStringToADateTime();
18+
=> DoShouldProjectAParseableStringToADateTime();
2219

2320
[Fact]
2421
public Task ShouldProjectANullString()
25-
=> RunShouldProjectANullStringToADateTime();
22+
=> DoShouldProjectANullStringToADateTime();
2623

2724
[Fact]
2825
public Task ShouldProjectAnUnparseableString()

AgileMapper.UnitTests.Orms.Ef6/AgileMapper.UnitTests.Orms.Ef6.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@
121121
<Project>{66522d44-19f5-4af5-9d43-483a3cd6f958}</Project>
122122
<Name>AgileMapper.UnitTests.Orms</Name>
123123
</ProjectReference>
124+
<ProjectReference Include="..\AgileMapper.UnitTests\AgileMapper.UnitTests.csproj">
125+
<Project>{A3F2D405-8C0B-4033-9EC5-1B64007593FB}</Project>
126+
<Name>AgileMapper.UnitTests</Name>
127+
</ProjectReference>
124128
<ProjectReference Include="..\AgileMapper\AgileMapper.csproj">
125129
<Project>{46d95c53-b4cb-4ee7-9573-5d3ef96099c0}</Project>
126130
<Name>AgileMapper</Name>

0 commit comments

Comments
 (0)