Skip to content

Commit

Permalink
rebase, fix sqlite tests and move some ops tests around
Browse files Browse the repository at this point in the history
  • Loading branch information
maumar committed Mar 1, 2023
1 parent 66aa2b9 commit 5b9935f
Show file tree
Hide file tree
Showing 28 changed files with 605 additions and 747 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ from e2 in context.Set<OperatorEntityBool>()
}
}

[ConditionalFact(Skip = "issue #30277")]
[ConditionalFact]
public virtual async Task Projection_with_not_and_negation_on_integer()
{
var contextFactory = await InitializeAsync<OperatorsContext>(seed: Seed);
Expand All @@ -141,4 +141,95 @@ from e5 in context.Set<OperatorEntityLong>()
Assert.Equal(expected[i], actual[i]);
}
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Negate_on_column(bool async)
{
var contextFactory = await InitializeAsync<OperatorsContext>(seed: Seed);
using var context = contextFactory.CreateContext();

var expected = (from e in ExpectedData.OperatorEntitiesInt
where e.Id == -e.Value
select e.Id).ToList();

var actual = (from e in context.Set<OperatorEntityInt>()
where e.Id == -e.Value
select e.Id).ToList();

Assert.Equal(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i], actual[i]);
}
}

[ConditionalFact]
public virtual async Task Double_negate_on_column()
{
var contextFactory = await InitializeAsync<OperatorsContext>(seed: Seed);
using var context = contextFactory.CreateContext();

var expected = (from e in ExpectedData.OperatorEntitiesInt
where -(-e.Value) == e.Value
select e.Id).ToList();

var actual = (from e in context.Set<OperatorEntityInt>()
where -(-e.Value) == e.Value
select e.Id).ToList();

Assert.Equal(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i], actual[i]);
}
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Negate_on_binary_expression(bool async)
{
var contextFactory = await InitializeAsync<OperatorsContext>(seed: Seed);
using var context = contextFactory.CreateContext();

var expected = (from e1 in ExpectedData.OperatorEntitiesInt
from e2 in ExpectedData.OperatorEntitiesInt
where -e1.Value == -(e1.Id + e2.Value)
select new { Id1 = e1.Id, Id2 = e2.Id }).ToList();

var actual = (from e1 in context.Set<OperatorEntityInt>()
from e2 in context.Set<OperatorEntityInt>()
where -e1.Value == -(e1.Id + e2.Value)
select new { Id1 = e1.Id, Id2 = e2.Id }).ToList();


Assert.Equal(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i].Id1, actual[i].Id1);
Assert.Equal(expected[i].Id2, actual[i].Id2);
}
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Negate_on_like_expression(bool async)
{
var contextFactory = await InitializeAsync<OperatorsContext>(seed: Seed);
using var context = contextFactory.CreateContext();

var expected = (from e in ExpectedData.OperatorEntitiesString
where !e.Value.StartsWith("A")
select e.Id).ToList();

var actual = (from e in context.Set<OperatorEntityString>()
where !e.Value.StartsWith("A")
select e.Id).ToList();

Assert.Equal(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i], actual[i]);
}
}
}
21 changes: 0 additions & 21 deletions test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,6 @@ protected override Expression RewriteExpectedQueryExpression(Expression expected
=> new ExpectedQueryRewritingVisitor(Fixture.GetShadowPropertyMappings())
.Visit(expectedQueryExpression);

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Negate_on_binary_expression(bool async)
=> AssertQuery(
async,
ss => ss.Set<Squad>().Where(s => s.Id == -(s.Id + s.Id)));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Negate_on_column(bool async)
=> AssertQuery(
async,
ss => ss.Set<Squad>().Where(s => s.Id == -s.Id));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Negate_on_like_expression(bool async)
=> AssertQuery(
async,
ss => ss.Set<Squad>().Where(s => !s.Name.StartsWith("us")));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Entity_equality_empty(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,6 @@ protected override bool CanExecuteQueryString
public virtual void Check_all_tests_overridden()
=> TestHelpers.AssertAllMethodsOverridden(GetType());

public override async Task Negate_on_binary_expression(bool async)
{
await base.Negate_on_binary_expression(async);

AssertSql(
"""
SELECT [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name]
FROM [Squads] AS [s]
WHERE [s].[Id] = -([s].[Id] + [s].[Id])
""");
}

public override async Task Negate_on_column(bool async)
{
await base.Negate_on_column(async);

AssertSql(
"""
SELECT [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name]
FROM [Squads] AS [s]
WHERE [s].[Id] = -[s].[Id]
""");
}

public override async Task Negate_on_like_expression(bool async)
{
await base.Negate_on_like_expression(async);

AssertSql(
"""
SELECT [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name]
FROM [Squads] AS [s]
WHERE [s].[Name] IS NOT NULL AND NOT ([s].[Name] LIKE N'us%')
""");
}

public override async Task Entity_equality_empty(bool async)
{
await base.Entity_equality_empty(async);
Expand Down Expand Up @@ -2931,82 +2895,6 @@ FROM [Missions] AS [m]
""");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Where_AtTimeZone_datetimeoffset_constant(bool async)
{
using var context = CreateContext();

var query = context.Set<Mission>().Where(
m => EF.Functions.AtTimeZone(m.Timeline, "UTC") == new DateTimeOffset(2, 3, 1, 13, 0, 0, TimeSpan.Zero));

var missions = async
? await query.ToListAsync()
: query.ToList();

var mission = Assert.Single(missions);
Assert.Equal(2, mission.Id);

AssertSql(
"""
SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline]
FROM [Missions] AS [m]
WHERE ([m].[Timeline] AT TIME ZONE 'UTC') = '0002-03-01T13:00:00.0000000+00:00'
""");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Where_AtTimeZone_datetimeoffset_parameter(bool async)
{
using var context = CreateContext();

var dateTime = new DateTimeOffset(2, 3, 1, 13, 0, 0, TimeSpan.Zero);
var timeZone = "UTC";
var query = context.Set<Mission>().Where(m => m.Timeline == EF.Functions.AtTimeZone(dateTime, timeZone));

var missions = async
? await query.ToListAsync()
: query.ToList();

var mission = Assert.Single(missions);
Assert.Equal(2, mission.Id);

AssertSql(
"""
@__dateTime_1='0002-03-01T13:00:00.0000000+00:00'
@__timeZone_2='UTC' (Size = 8000) (DbType = AnsiString)
SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline]
FROM [Missions] AS [m]
WHERE [m].[Timeline] = (@__dateTime_1 AT TIME ZONE @__timeZone_2)
""");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Where_AtTimeZone_datetimeoffset_column(bool async)
{
using var context = CreateContext();

var query = context.Set<Mission>()
.Where(m => EF.Functions.AtTimeZone(m.Timeline, "UTC") == new DateTimeOffset(2, 3, 1, 13, 0, 0, TimeSpan.Zero));

var missions = async
? await query.ToListAsync()
: query.ToList();

var mission = Assert.Single(missions);
Assert.Equal(2, mission.Id);

AssertSql(
"""
SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline]
FROM [Missions] AS [m]
WHERE ([m].[Timeline] AT TIME ZONE 'UTC') = '0002-03-01T13:00:00.0000000+00:00'
""");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Where_AtTimeZone_datetime_constant(bool async)
Expand All @@ -3026,7 +2914,7 @@ public virtual async Task Where_AtTimeZone_datetime_constant(bool async)
"""
SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline]
FROM [Missions] AS [m]
WHERE [m].[Timeline] = (CAST('0010-05-03T12:00:00.0000000' AS datetime2) AT TIME ZONE 'UTC')
WHERE [m].[Timeline] = CAST('0010-05-03T12:00:00.0000000' AS datetime2) AT TIME ZONE 'UTC'
""");
}

Expand Down Expand Up @@ -3054,7 +2942,7 @@ public virtual async Task Where_AtTimeZone_datetime_parameter(bool async)
SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline]
FROM [Missions] AS [m]
WHERE [m].[Timeline] = (@__dateTime_1 AT TIME ZONE @__timeZone_2)
WHERE [m].[Timeline] = @__dateTime_1 AT TIME ZONE @__timeZone_2
""");
}

Expand All @@ -3078,7 +2966,7 @@ public virtual async Task Where_AtTimeZone_datetime_column(bool async)
"""
SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note]
FROM [Tags] AS [t]
WHERE ([t].[IssueDate] AT TIME ZONE 'UTC') = '0015-03-07T00:00:00.0000000+00:00'
WHERE [t].[IssueDate] AT TIME ZONE 'UTC' = '0015-03-07T00:00:00.0000000+00:00'
""");
}

Expand Down Expand Up @@ -9297,13 +9185,13 @@ public override async Task Where_TimeOnly_IsBetween(bool async)
"""
SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline]
FROM [Missions] AS [m]
WHERE (CASE
WHERE CASE
WHEN [m].[Time] >= '10:00:00' THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END & CASE
WHEN [m].[Time] < '11:00:00' THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END) = CAST(1 AS bit)
END = CAST(1 AS bit)
""");
}

Expand Down
Loading

0 comments on commit 5b9935f

Please sign in to comment.