Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ranma42 committed May 28, 2024
1 parent f36e99d commit 5af627e
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 33 deletions.
11 changes: 5 additions & 6 deletions test/EFCore.Sqlite.FunctionalTests/BuiltInDataTypesSqliteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ public virtual void Cant_query_Max_of_converted_types()
}

[ConditionalFact]
public virtual void Cant_query_Average_of_converted_types()
public virtual void Can_query_Average_of_converted_types()
{
using var context = CreateContext();
context.Add(
Expand All @@ -958,11 +958,10 @@ public virtual void Cant_query_Average_of_converted_types()
context.SaveChanges();

Assert.Equal(
SqliteStrings.AggregateOperationNotSupported(nameof(Queryable.Average), typeof(decimal).ShortDisplayName()),
Assert.Throws<NotSupportedException>(
() => context.Set<BuiltInNullableDataTypes>()
.Where(e => e.PartitionId == 202)
.Average(e => e.TestNullableDecimal)).Message);
1.000000000000002m,
context.Set<BuiltInNullableDataTypes>()
.Where(e => e.PartitionId == 202)
.Average(e => e.TestNullableDecimal));
}

[ConditionalFact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,68 @@ INSERT INTO ZeroKey VALUES (NULL)
""");

public override async Task Average_with_cast()
=> Assert.Equal(
SqliteStrings.AggregateOperationNotSupported("Average", "decimal"),
(await Assert.ThrowsAsync<NotSupportedException>(base.Average_with_cast)).Message);
{
await base.Average_with_cast();

AssertSql(
"""
SELECT "p"."Id", "p"."DecimalColumn", "p"."DoubleColumn", "p"."FloatColumn", "p"."IntColumn", "p"."LongColumn", "p"."NullableDecimalColumn", "p"."NullableDoubleColumn", "p"."NullableFloatColumn", "p"."NullableIntColumn", "p"."NullableLongColumn", "p"."Price"
FROM "Prices" AS "p"
""",
//
"""
SELECT ef_avg("p"."Price")
FROM "Prices" AS "p"
""",
//
"""
SELECT AVG(CAST("p"."IntColumn" AS REAL))
FROM "Prices" AS "p"
""",
//
"""
SELECT AVG(CAST("p"."NullableIntColumn" AS REAL))
FROM "Prices" AS "p"
""",
//
"""
SELECT AVG(CAST("p"."LongColumn" AS REAL))
FROM "Prices" AS "p"
""",
//
"""
SELECT AVG(CAST("p"."NullableLongColumn" AS REAL))
FROM "Prices" AS "p"
""",
//
"""
SELECT CAST(AVG("p"."FloatColumn") AS REAL)
FROM "Prices" AS "p"
""",
//
"""
SELECT CAST(AVG("p"."NullableFloatColumn") AS REAL)
FROM "Prices" AS "p"
""",
//
"""
SELECT AVG("p"."DoubleColumn")
FROM "Prices" AS "p"
""",
//
"""
SELECT AVG("p"."NullableDoubleColumn")
FROM "Prices" AS "p"
""",
//
"""
SELECT ef_avg("p"."DecimalColumn")
FROM "Prices" AS "p"
""",
//
"""
SELECT ef_avg("p"."NullableDecimalColumn")
FROM "Prices" AS "p"
""");
}
}
17 changes: 13 additions & 4 deletions test/EFCore.Sqlite.FunctionalTests/Query/Ef6GroupBySqliteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ public Ef6GroupBySqliteTest(Ef6GroupBySqliteFixture fixture, ITestOutputHelper t
}

public override async Task Average_Grouped_from_LINQ_101(bool async)
=> Assert.Equal(
SqliteStrings.AggregateOperationNotSupported("Average", "decimal"),
(await Assert.ThrowsAsync<NotSupportedException>(
() => base.Average_Grouped_from_LINQ_101(async))).Message);
{
await base.Average_Grouped_from_LINQ_101(async);

AssertSql(
"""
SELECT "p"."Category", ef_avg("p"."UnitPrice") AS "AveragePrice"
FROM "ProductForLinq" AS "p"
GROUP BY "p"."Category"
""");
}

public override async Task Max_Grouped_from_LINQ_101(bool async)
=> Assert.Equal(
Expand Down Expand Up @@ -49,6 +55,9 @@ public override async Task Group_Join_from_LINQ_101(bool async)
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.Group_Join_from_LINQ_101(async))).Message);

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

public class Ef6GroupBySqliteFixture : Ef6GroupByFixtureBase, ITestSqlLoggerFactory
{
public TestSqlLoggerFactory TestSqlLoggerFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,76 @@ SELECT COALESCE(ef_sum(ef_divide(CAST("o"."Quantity" AS TEXT), '2.0')), '0.0')
}

public override async Task Average_with_division_on_decimal(bool async)
=> Assert.Equal(
SqliteStrings.AggregateOperationNotSupported("Average", "decimal"),
(await Assert.ThrowsAsync<NotSupportedException>(
async () => await base.Average_with_division_on_decimal(async)))
.Message);
{
await base.Average_with_division_on_decimal(async);

AssertSql(
"""
SELECT ef_avg(ef_divide(CAST("o"."Quantity" AS TEXT), '2.09'))
FROM "Order Details" AS "o"
""");
}

public override async Task Average_with_division_on_decimal_no_significant_digits(bool async)
=> Assert.Equal(
SqliteStrings.AggregateOperationNotSupported("Average", "decimal"),
(await Assert.ThrowsAsync<NotSupportedException>(
async () => await base.Average_with_division_on_decimal_no_significant_digits(async)))
.Message);
{
await base.Average_with_division_on_decimal_no_significant_digits(async);

AssertSql(
"""
SELECT ef_avg(ef_divide(CAST("o"."Quantity" AS TEXT), '2.0'))
FROM "Order Details" AS "o"
""");
}



public override async Task Average_over_max_subquery_is_client_eval(bool async)
=> Assert.Equal(
SqliteStrings.AggregateOperationNotSupported("Average", "decimal"),
(await Assert.ThrowsAsync<NotSupportedException>(
async () => await base.Average_over_max_subquery_is_client_eval(async)))
.Message);
{
await base.Average_over_max_subquery_is_client_eval(async);

AssertSql(
"""
@__p_0='3'
SELECT ef_avg(CAST((
SELECT AVG(CAST(5 + (
SELECT MAX("o0"."ProductID")
FROM "Order Details" AS "o0"
WHERE "o"."OrderID" = "o0"."OrderID") AS REAL))
FROM "Orders" AS "o"
WHERE "c0"."CustomerID" = "o"."CustomerID") AS TEXT))
FROM (
SELECT "c"."CustomerID"
FROM "Customers" AS "c"
ORDER BY "c"."CustomerID"
LIMIT @__p_0
) AS "c0"
""");
}

public override async Task Average_over_nested_subquery_is_client_eval(bool async)
=> Assert.Equal(
SqliteStrings.AggregateOperationNotSupported("Average", "decimal"),
(await Assert.ThrowsAsync<NotSupportedException>(
async () => await base.Average_over_nested_subquery_is_client_eval(async)))
.Message);
{
await base.Average_over_nested_subquery_is_client_eval(async);

AssertSql(
"""
@__p_0='3'
SELECT ef_avg(CAST((
SELECT AVG(5.0 + (
SELECT AVG(CAST("o0"."ProductID" AS REAL))
FROM "Order Details" AS "o0"
WHERE "o"."OrderID" = "o0"."OrderID"))
FROM "Orders" AS "o"
WHERE "c0"."CustomerID" = "o"."CustomerID") AS TEXT))
FROM (
SELECT "c"."CustomerID"
FROM "Customers" AS "c"
ORDER BY "c"."CustomerID"
LIMIT @__p_0
) AS "c0"
""");
}

public override async Task Multiple_collection_navigation_with_FirstOrDefault_chained(bool async)
=> Assert.Equal(
Expand Down

0 comments on commit 5af627e

Please sign in to comment.