Skip to content

Commit

Permalink
Add test changes to AddMonths test for Sqlite
Browse files Browse the repository at this point in the history
Sqlite has a peculiar way of adding months, which is by design - we need to compensate in test.

Resolves #25851
  • Loading branch information
maumar committed Oct 5, 2022
1 parent 24c68e0 commit 4320e73
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,29 @@ public override async Task Select_expression_date_add_year(bool async)

public override async Task Select_expression_datetime_add_month(bool async)
{
// Add ticks. Issue #25851.
Assert.Equal(
"1996-12-01T00:00:00.0000000",
(await Assert.ThrowsAsync<EqualException>(
() => base.Select_expression_datetime_add_month(async))).Actual);
await AssertQuery(
async,
ss => ss.Set<Order>()
.Where(o => o.OrderDate != null)
.Select(o => new Order { OrderDate = o.OrderDate.Value.AddMonths(1) }),
e => e.OrderDate,
elementAsserter: (e, a) =>
{
Assert.Equal(e.OrderDate.HasValue, a.OrderDate.HasValue);
if (e.OrderDate.HasValue && a.OrderDate.HasValue)
{
// difference between how Sqlite and everyone else add months
// e.g. when adding 1 month to Jan 31st, we get March 2/3 on Sqlite and Feb 28th/29ths for everyone else
// see notes on issue #25851 for more details
var diff = (e.OrderDate - a.OrderDate).Value;
Assert.True(diff.Days is >= -3 and <= 0);
Assert.Equal(0, diff.Hours);
Assert.Equal(0, diff.Minutes);
Assert.Equal(0, diff.Seconds);
Assert.Equal(0, diff.Milliseconds);
Assert.Equal(0, diff.Microseconds);
}
});

AssertSql(
@"SELECT rtrim(rtrim(strftime('%Y-%m-%d %H:%M:%f', ""o"".""OrderDate"", CAST(1 AS TEXT) || ' months'), '0'), '.') AS ""OrderDate""
Expand Down

0 comments on commit 4320e73

Please sign in to comment.