Skip to content

Commit 0ca8c4e

Browse files
committed
Fix visibility of methods used in compiled models, add tests
1 parent ac1da96 commit 0ca8c4e

7 files changed

Lines changed: 89 additions & 12 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using Microsoft.EntityFrameworkCore.SqlServer.Storage;
2+
using NodaTime;
3+
using System;
4+
using Xunit;
5+
6+
namespace SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime.Tests
7+
{
8+
public class MappingDefaultsTest
9+
{
10+
[Fact]
11+
public void Duration_Defaults()
12+
{
13+
var durationDefault = DurationTypeMapping.Default;
14+
15+
Assert.NotNull(durationDefault);
16+
17+
Assert.Equal("time", durationDefault.StoreType);
18+
Assert.Equal("'02:30:01'", durationDefault.GenerateSqlLiteral(Duration.FromTimeSpan(new TimeSpan(2, 30, 1))));
19+
}
20+
21+
[Fact]
22+
public void Instant_Defaults()
23+
{
24+
var instantDefault = InstantTypeMapping.Default;
25+
26+
Assert.NotNull(instantDefault);
27+
28+
Assert.Equal("datetime2", instantDefault.StoreType);
29+
Assert.Equal("'2024-02-14T00:14:00.0000000Z'", instantDefault.GenerateSqlLiteral(Instant.FromUtc(2024, 02, 14, 0, 14)));
30+
}
31+
32+
[Fact]
33+
public void LocalDateTime_Defaults()
34+
{
35+
var localDateTimeDefault = LocalDateTimeTypeMapping.Default;
36+
37+
Assert.NotNull(localDateTimeDefault);
38+
39+
Assert.Equal("datetime2", localDateTimeDefault.StoreType);
40+
Assert.Equal("'2024-04-01T13:15:00.0000000'", localDateTimeDefault.GenerateSqlLiteral(new LocalDateTime(2024, 04, 01, 13, 15)));
41+
}
42+
43+
[Fact]
44+
public void LocalDate_Defaults()
45+
{
46+
var localDateDefault = LocalDateTypeMapping.Default;
47+
48+
Assert.NotNull(localDateDefault);
49+
50+
Assert.Equal("date", localDateDefault.StoreType);
51+
Assert.Equal("'2024-03-30'", localDateDefault.GenerateSqlLiteral(new LocalDate(2024, 03, 30)));
52+
}
53+
54+
[Fact]
55+
public void LocalTime_Defaults()
56+
{
57+
var localTimeDefault = LocalTimeTypeMapping.Default;
58+
59+
Assert.NotNull(localTimeDefault);
60+
61+
Assert.Equal("time", localTimeDefault.StoreType);
62+
Assert.Equal("'19:40:00'", localTimeDefault.GenerateSqlLiteral(new LocalTime(19, 40)));
63+
}
64+
65+
[Fact]
66+
public void OffsetDateTime_Defaults()
67+
{
68+
var offsetDateTimeDefault = OffsetDateTimeTypeMapping.Default;
69+
70+
Assert.NotNull(offsetDateTimeDefault);
71+
72+
Assert.Equal("datetimeoffset", offsetDateTimeDefault.StoreType);
73+
var localDateTime = new LocalDateTime(2024, 04, 01, 17, 15);
74+
Assert.Equal("'2024-04-01T17:15:00.0000000+02:00'", offsetDateTimeDefault.GenerateSqlLiteral(new OffsetDateTime(localDateTime, Offset.FromHours(2))));
75+
}
76+
}
77+
}

src/SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime/Storage/DurationValueConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public DurationValueConverter()
1111
{
1212
}
1313

14-
private static TimeSpan toProvider(Duration duration)
14+
public static TimeSpan toProvider(Duration duration)
1515
{
1616
return duration.ToTimeSpan();
1717
}
1818

19-
private static Duration fromProvider(TimeSpan timeSpan)
19+
public static Duration fromProvider(TimeSpan timeSpan)
2020
{
2121
return Duration.FromTimeSpan(timeSpan);
2222
}

src/SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime/Storage/InstantValueConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public InstantValueConverter()
1111
{
1212
}
1313

14-
private static DateTime toProvider(Instant instant)
14+
public static DateTime toProvider(Instant instant)
1515
{
1616
return instant.ToDateTimeUtc();
1717
}
1818

19-
private static Instant fromProvider(DateTime dateTime)
19+
public static Instant fromProvider(DateTime dateTime)
2020
{
2121
return Instant.FromDateTimeUtc(DateTime.SpecifyKind(dateTime, DateTimeKind.Utc));
2222
}

src/SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime/Storage/LocalDateTimeValueConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public LocalDateTimeValueConverter()
1111
{
1212
}
1313

14-
private static DateTime toProvider(LocalDateTime localDateTime)
14+
public static DateTime toProvider(LocalDateTime localDateTime)
1515
{
1616
return localDateTime.ToDateTimeUnspecified();
1717
}
1818

19-
private static LocalDateTime fromProvider(DateTime dateTime)
19+
public static LocalDateTime fromProvider(DateTime dateTime)
2020
{
2121
return LocalDateTime.FromDateTime(dateTime);
2222
}

src/SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime/Storage/LocalDateValueConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public LocalDateValueConverter()
1111
{
1212
}
1313

14-
private static DateTime toProvider(LocalDate localDate)
14+
public static DateTime toProvider(LocalDate localDate)
1515
{
1616
return localDate.ToDateTimeUnspecified();
1717
}
1818

19-
private static LocalDate fromProvider(DateTime dateTime)
19+
public static LocalDate fromProvider(DateTime dateTime)
2020
{
2121
return LocalDate.FromDateTime(dateTime);
2222
}

src/SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime/Storage/LocalTimeValueConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public LocalTimeValueConverter()
1111
{
1212
}
1313

14-
private static TimeSpan toProvider(LocalTime localTime)
14+
public static TimeSpan toProvider(LocalTime localTime)
1515
{
1616
return new TimeSpan(localTime.TickOfDay);
1717
}
1818

19-
private static LocalTime fromProvider(TimeSpan dateTime)
19+
public static LocalTime fromProvider(TimeSpan dateTime)
2020
{
2121
return LocalTime.FromTicksSinceMidnight(dateTime.Ticks);
2222
}

src/SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime/Storage/OffsetDateTimeValueConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public OffsetDateTimeValueConverter()
1111
{
1212
}
1313

14-
private static DateTimeOffset toProvider(OffsetDateTime offsetDateTime)
14+
public static DateTimeOffset toProvider(OffsetDateTime offsetDateTime)
1515
{
1616
return offsetDateTime.ToDateTimeOffset();
1717
}
1818

19-
private static OffsetDateTime fromProvider(DateTimeOffset dateTimeOffset)
19+
public static OffsetDateTime fromProvider(DateTimeOffset dateTimeOffset)
2020
{
2121
return OffsetDateTime.FromDateTimeOffset(dateTimeOffset);
2222
}

0 commit comments

Comments
 (0)