Skip to content

Commit

Permalink
Fix to #26397 - Query/Test: convert the "no_data" tests in NorthwindA…
Browse files Browse the repository at this point in the history
…ggregateOperatorsQueryTestBase to use AssertQuery

We can use assert methods for individual result operators (min, max, average) as well as AssertSingleResult for ones which use complicated/correlated arguments in the final method.

Fixes #26397
  • Loading branch information
maumar committed Oct 21, 2021
1 parent dbc4314 commit 8bf338f
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ FROM root c
WHERE ((c[""Discriminator""] = ""Order"") AND (c[""OrderID""] = 10248))");
}

public override void Contains_over_keyless_entity_throws()
public override async Task Contains_over_keyless_entity_throws(bool async)
{
// Aggregates. Issue #16146.
AssertTranslationFailed(() =>
{
base.Contains_over_keyless_entity_throws();
return Task.CompletedTask;
});
await AssertTranslationFailed(() => base.Contains_over_keyless_entity_throws(async));

AssertSql(
@"SELECT c
Expand Down Expand Up @@ -266,14 +262,10 @@ FROM root c
OFFSET 0 LIMIT 2");
}

public override void Select_All()
public override async Task Select_All(bool async)
{
// Contains over subquery. Issue #17246.
AssertTranslationFailed(() =>
{
base.Select_All();
return Task.CompletedTask;
});
await AssertTranslationFailed(() => base.Select_All(async));

AssertSql();
}
Expand Down Expand Up @@ -417,108 +409,96 @@ public override async Task Sum_on_float_column_in_subquery(bool async)
AssertSql();
}

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

AssertSql(
@"SELECT AVG(c[""OrderID""]) AS c
FROM root c
WHERE ((c[""Discriminator""] = ""Order"") AND (c[""OrderID""] = -1))");
}

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

AssertSql(
@"SELECT AVG(c[""SupplierID""]) AS c
FROM root c
WHERE ((c[""Discriminator""] = ""Product"") AND (c[""SupplierID""] = -1))");
}

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

AssertSql(
@"SELECT AVG(c[""OrderID""]) AS c
FROM root c
WHERE ((c[""Discriminator""] = ""Order"") AND (c[""OrderID""] = -1))");
}

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

AssertSql(
@"SELECT MIN(c[""OrderID""]) AS c
FROM root c
WHERE ((c[""Discriminator""] = ""Order"") AND (c[""OrderID""] = -1))");
}

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

AssertSql(
@"SELECT MAX(c[""OrderID""]) AS c
FROM root c
WHERE ((c[""Discriminator""] = ""Order"") AND (c[""OrderID""] = -1))");
}

public override void Average_no_data_subquery()
public override async Task Average_no_data_subquery(bool async)
{
// Aggregates. Issue #16146.
AssertTranslationFailed(() =>
{
base.Average_no_data_subquery();
return Task.CompletedTask;
});
await AssertTranslationFailed(() => base.Average_no_data_subquery(async));

AssertSql();
}

public override void Max_no_data_subquery()
public override async Task Max_no_data_subquery(bool async)
{
// Aggregates. Issue #16146.
AssertTranslationFailed(() =>
{
base.Max_no_data_subquery();
return Task.CompletedTask;
});
await AssertTranslationFailed(() => base.Max_no_data_subquery(async));

AssertSql();
}

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

AssertSql(
@"SELECT MAX(c[""SupplierID""]) AS c
FROM root c
WHERE ((c[""Discriminator""] = ""Product"") AND (c[""SupplierID""] = -1))");
}

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

AssertSql(
@"SELECT MAX(c[""OrderID""]) AS c
FROM root c
WHERE ((c[""Discriminator""] = ""Order"") AND (c[""OrderID""] = -1))");
}

public override void Min_no_data_subquery()
public override async Task Min_no_data_subquery(bool async)
{
// Aggregates. Issue #16146.
AssertTranslationFailed(() =>
{
base.Min_no_data_subquery();
return Task.CompletedTask;
});
await AssertTranslationFailed(() => base.Min_no_data_subquery(async));

AssertSql();
}
Expand Down Expand Up @@ -662,19 +642,19 @@ FROM root c
WHERE (c[""Discriminator""] = ""Order"")");
}

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

AssertSql(
@"SELECT MIN(c[""SupplierID""]) AS c
FROM root c
WHERE ((c[""Discriminator""] = ""Product"") AND (c[""SupplierID""] = -1))");
}

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

AssertSql(
@"SELECT MIN(c[""OrderID""]) AS c
Expand Down Expand Up @@ -1349,26 +1329,18 @@ public override async Task Contains_with_local_anonymous_type_array_closure(bool
AssertSql();
}

public override void OfType_Select()
public override async Task OfType_Select(bool async)
{
// Contains over subquery. Issue #15937.
AssertTranslationFailed(() =>
{
base.OfType_Select();
return Task.CompletedTask;
});
await AssertTranslationFailed(() => base.OfType_Select(async));

AssertSql();
}

public override void OfType_Select_OfType_Select()
public override async Task OfType_Select_OfType_Select(bool async)
{
// Contains over subquery. Issue #17246.
AssertTranslationFailed(() =>
{
base.OfType_Select_OfType_Select();
return Task.CompletedTask;
});
await AssertTranslationFailed(() => base.OfType_Select_OfType_Select(async));

AssertSql();
}
Expand Down Expand Up @@ -1420,14 +1392,10 @@ public override async Task OrderBy_Skip_Last_gives_correct_result(bool async)
AssertSql();
}

public override void Contains_over_entityType_should_rewrite_to_identity_equality()
public override async Task Contains_over_entityType_should_rewrite_to_identity_equality(bool async)
{
// Contains over subquery. Issue #17246.
AssertTranslationFailed(() =>
{
base.Contains_over_entityType_should_rewrite_to_identity_equality();
return Task.CompletedTask;
});
await AssertTranslationFailed(() => base.Contains_over_entityType_should_rewrite_to_identity_equality(async));

AssertSql(
@"SELECT c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.TestModels.Northwind;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -24,34 +25,40 @@ public NorthwindAggregateOperatorsQueryInMemoryTest(
}

// InMemory can throw server side exception
public override void Average_no_data_subquery()
public override async Task Average_no_data_subquery(bool async)
{
using var context = CreateContext();
var message = (await Assert.ThrowsAsync<InvalidOperationException>(
() => AssertQueryScalar(
async,
ss => ss.Set<Customer>().Select(c => c.Orders.Where(o => o.OrderID == -1).Average(o => o.OrderID))))).Message;

Assert.Equal(
"Sequence contains no elements",
Assert.Throws<InvalidOperationException>(
() => context.Customers.Select(c => c.Orders.Where(o => o.OrderID == -1).Average(o => o.OrderID)).ToList()).Message);
message);
}

public override void Max_no_data_subquery()
public override async Task Max_no_data_subquery(bool async)
{
using var context = CreateContext();
var message = (await Assert.ThrowsAsync<InvalidOperationException>(
() => AssertQueryScalar(
async,
ss => ss.Set<Customer>().Select(c => c.Orders.Where(o => o.OrderID == -1).Max(o => o.OrderID))))).Message;

Assert.Equal(
"Sequence contains no elements",
Assert.Throws<InvalidOperationException>(
() => context.Customers.Select(c => c.Orders.Where(o => o.OrderID == -1).Max(o => o.OrderID)).ToList()).Message);
message);
}

public override void Min_no_data_subquery()
public override async Task Min_no_data_subquery(bool async)
{
using var context = CreateContext();
var message = (await Assert.ThrowsAsync<InvalidOperationException>(
() => AssertQueryScalar(
async,
ss => ss.Set<Customer>().Select(c => c.Orders.Where(o => o.OrderID == -1).Min(o => o.OrderID))))).Message;

Assert.Equal(
"Sequence contains no elements",
Assert.Throws<InvalidOperationException>(
() => context.Customers.Select(c => c.Orders.Where(o => o.OrderID == -1).Min(o => o.OrderID)).ToList()).Message);
message);
}

public override async Task Average_on_nav_subquery_in_projection(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public override async Task LastOrDefault_when_no_order_by(bool async)
() => base.LastOrDefault_when_no_order_by(async))).Message);
}

public override void Contains_over_keyless_entity_throws()
public override async Task Contains_over_keyless_entity_throws(bool async)
{
Assert.Equal(
CoreStrings.EntityEqualityOnKeylessEntityNotSupported("==", nameof(CustomerQuery)),
(Assert.Throws<InvalidOperationException>(
() => base.Contains_over_keyless_entity_throws())).Message);
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.Contains_over_keyless_entity_throws(async))).Message);
}

protected virtual bool CanExecuteQueryString
Expand Down
Loading

0 comments on commit 8bf338f

Please sign in to comment.