Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRY out query translation failure in tests #18964

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,9 @@ private string NormalizeDelimitersInRawString(string sql)
=> Fixture.TestStore.NormalizeDelimitersInRawString(sql);

private void AssertTranslationFailed(Action testCode)
{
Assert.Contains(
=> Assert.Contains(
CoreStrings.TranslationFailed("").Substring(21),
Assert.Throws<InvalidOperationException>(testCode).Message);
}

protected NorthwindContext CreateContext() => Fixture.CreateContext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,8 @@ public virtual void Scalar_Nested_Function_UDF_BCL_Instance()
#endregion

private void AssertTranslationFailed(Action testCode)
{
Assert.Contains(
=> Assert.Contains(
CoreStrings.TranslationFailed("").Substring(21),
Assert.Throws<InvalidOperationException>(testCode).Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7303,13 +7303,6 @@ public virtual Task Byte_array_contains_parameter(bool async)
ss => ss.Set<Squad>().Where(s => s.Banner != null && s.Banner.Contains(someByte)));
}

protected async Task AssertTranslationFailed(Func<Task> testCode)
{
Assert.Contains(
CoreStrings.TranslationFailed("").Substring(21),
(await Assert.ThrowsAsync<InvalidOperationException>(testCode)).Message);
}

protected GearsOfWarContext CreateContext() => Fixture.CreateContext();

protected virtual void ClearLog()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1827,12 +1827,5 @@ private static string CodeFormat(int str)
{
return str.ToString();
}

protected async Task AssertTranslationFailed(Func<Task> testCode)
{
Assert.Contains(
CoreStrings.TranslationFailed("").Substring(21),
(await Assert.ThrowsAsync<InvalidOperationException>(testCode)).Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5462,13 +5462,6 @@ public virtual Task AsQueryable_in_query_server_evals(bool async)
elementAsserter: (e, a) => AssertCollection(e, a, ordered: true));
}

protected async Task AssertTranslationFailed(Func<Task> testCode)
{
Assert.Contains(
CoreStrings.TranslationFailed("").Substring(21),
(await Assert.ThrowsAsync<InvalidOperationException>(testCode)).Message);
}

private static Expression<Func<Order, bool>> ValidYear => a => a.OrderDate.Value.Year == 1998;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1123,12 +1123,5 @@ private class OrderDTO
{
public Customer Customer { get; set; }
}

private async Task AssertTranslationFailed(Func<Task> testCode)
{
Assert.Contains(
CoreStrings.TranslationFailed("").Substring(21),
(await Assert.ThrowsAsync<InvalidOperationException>(testCode)).Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1593,12 +1593,5 @@ public CustomerWrapper(Customer customer)
public string City { get; set; }
public Customer Customer { get; }
}

protected async Task AssertTranslationFailed(Func<Task> testCode)
{
Assert.Contains(
CoreStrings.TranslationFailed("").Substring(21),
(await Assert.ThrowsAsync<InvalidOperationException>(testCode)).Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1991,12 +1991,5 @@ public virtual Task Using_same_parameter_twice_in_query_generates_one_sql_parame
ss => ss.Set<Customer>().Where(c => i + c.CustomerID + i == c.CompanyName)
.Select(c => c.CustomerID));
}

protected async Task AssertTranslationFailed(Func<Task> testCode)
{
Assert.Contains(
CoreStrings.TranslationFailed("").Substring(21),
(await Assert.ThrowsAsync<InvalidOperationException>(testCode)).Message);
}
}
}
7 changes: 7 additions & 0 deletions test/EFCore.Specification.Tests/Query/QueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Xunit;

Expand Down Expand Up @@ -1149,6 +1150,12 @@ protected static IEnumerable<TResult> MaybeDefaultIfEmpty<TResult>(IEnumerable<T
: caller.DefaultIfEmpty();
}

protected static async Task AssertTranslationFailed(Func<Task> query)
=> Assert.Contains(
CoreStrings.TranslationFailed("").Substring(21),
(await Assert.ThrowsAsync<InvalidOperationException>(query))
.Message);

#endregion
}
}
12 changes: 5 additions & 7 deletions test/EFCore.Sqlite.FunctionalTests/BuiltInDataTypesSqliteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,13 +1019,6 @@ public virtual void Cant_query_Sum_of_converted_types()
.Sum(e => e.TestDecimal));
}

private void AssertTranslationFailed(Action testCode)
{
Assert.Contains(
CoreStrings.TranslationFailed("").Substring(21),
Assert.Throws<InvalidOperationException>(testCode).Message);
}

[ConditionalFact]
public virtual void Can_query_negation_of_converted_types()
{
Expand Down Expand Up @@ -1513,6 +1506,11 @@ public virtual void Cant_query_ThenBy_of_converted_types()
Assert.Equal(SqliteStrings.OrderByNotSupported("ulong"), ex.Message);
}

private void AssertTranslationFailed(Action testCode)
=> Assert.Contains(
CoreStrings.TranslationFailed("").Substring(21),
Assert.Throws<InvalidOperationException>(testCode).Message);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,77 +16,41 @@ public GearsOfWarQuerySqliteTest(GearsOfWarQuerySqliteFixture fixture, ITestOutp
//Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

// SQLite client-eval
public override Task Where_datetimeoffset_date_component(bool async)
{
return AssertTranslationFailed(() => base.Where_datetimeoffset_date_component(async));
}
=> AssertTranslationFailed(() => base.Where_datetimeoffset_date_component(async));

// SQLite client-eval
public override Task Where_datetimeoffset_day_component(bool async)
{
return AssertTranslationFailed(() => base.Where_datetimeoffset_date_component(async));
}
=> AssertTranslationFailed(() => base.Where_datetimeoffset_date_component(async));

// SQLite client-eval
public override Task Where_datetimeoffset_dayofyear_component(bool async)
{
return AssertTranslationFailed(() => base.Where_datetimeoffset_dayofyear_component(async));
}
=> AssertTranslationFailed(() => base.Where_datetimeoffset_dayofyear_component(async));

// SQLite client-eval
public override Task Where_datetimeoffset_hour_component(bool async)
{
return AssertTranslationFailed(() => base.Where_datetimeoffset_hour_component(async));
}
=> AssertTranslationFailed(() => base.Where_datetimeoffset_hour_component(async));

// SQLite client-eval
public override Task Where_datetimeoffset_millisecond_component(bool async)
{
return AssertTranslationFailed(() => base.Where_datetimeoffset_millisecond_component(async));
}
=> AssertTranslationFailed(() => base.Where_datetimeoffset_millisecond_component(async));

// SQLite client-eval
public override Task Where_datetimeoffset_minute_component(bool async)
{
return AssertTranslationFailed(() => base.Where_datetimeoffset_minute_component(async));
}
=> AssertTranslationFailed(() => base.Where_datetimeoffset_minute_component(async));

// SQLite client-eval
public override Task Where_datetimeoffset_month_component(bool async)
{
return AssertTranslationFailed(() => base.Where_datetimeoffset_month_component(async));
}
=> AssertTranslationFailed(() => base.Where_datetimeoffset_month_component(async));

// SQLite client-eval
public override Task Where_datetimeoffset_now(bool async)
{
return AssertTranslationFailed(() => base.Where_datetimeoffset_now(async));
}
=> AssertTranslationFailed(() => base.Where_datetimeoffset_now(async));

// SQLite client-eval
public override Task Where_datetimeoffset_second_component(bool async)
{
return AssertTranslationFailed(() => base.Where_datetimeoffset_second_component(async));
}
=> AssertTranslationFailed(() => base.Where_datetimeoffset_second_component(async));

// SQLite client-eval
public override Task Where_datetimeoffset_utcnow(bool async)
{
return AssertTranslationFailed(() => base.Where_datetimeoffset_utcnow(async));
}
=> AssertTranslationFailed(() => base.Where_datetimeoffset_utcnow(async));

// SQLite client-eval
public override Task Where_datetimeoffset_year_component(bool async)
{
return AssertTranslationFailed(() => base.Where_datetimeoffset_year_component(async));
}
=> AssertTranslationFailed(() => base.Where_datetimeoffset_year_component(async));

// SQLite client-eval
public override Task DateTimeOffset_Contains_Less_than_Greater_than(bool async)
{
return AssertTranslationFailed(() => base.DateTimeOffset_Contains_Less_than_Greater_than(async));
}
=> AssertTranslationFailed(() => base.DateTimeOffset_Contains_Less_than_Greater_than(async));

// Sqlite does not support cross/outer apply
public override Task Correlated_collections_inner_subquery_predicate_references_outer_qsre(bool async) => null;
Expand All @@ -105,9 +69,7 @@ public override Task DateTimeOffset_Contains_Less_than_Greater_than(bool async)

[ConditionalTheory(Skip = "Issue #17230")]
public override Task Project_collection_navigation_nested_with_take_composite_key(bool async)
{
return base.Project_collection_navigation_nested_with_take_composite_key(async);
}
=> base.Project_collection_navigation_nested_with_take_composite_key(async);

public override async Task Select_datetimeoffset_comparison_in_projection(bool async)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,16 @@ public NorthwindAggregateOperatorsQuerySqliteTest(NorthwindQuerySqliteFixture<No
//Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

// SQLite client-eval
public override async Task Sum_with_division_on_decimal(bool async)
{
Assert.StartsWith(
"The LINQ expression",
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.Sum_with_division_on_decimal(async)))
.Message);
}
public override Task Sum_with_division_on_decimal(bool async)
=> AssertTranslationFailed(() => base.Sum_with_division_on_decimal(async));

// SQLite client-eval
public override async Task Sum_with_division_on_decimal_no_significant_digits(bool async)
{
Assert.StartsWith(
"The LINQ expression",
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.Sum_with_division_on_decimal_no_significant_digits(async)))
.Message);
}
public override Task Sum_with_division_on_decimal_no_significant_digits(bool async)
=> AssertTranslationFailed(() => base.Sum_with_division_on_decimal_no_significant_digits(async));

// SQLite client-eval
public override async Task Average_with_division_on_decimal(bool async)
{
Assert.StartsWith(
"The LINQ expression",
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.Average_with_division_on_decimal(async)))
.Message);
}
public override Task Average_with_division_on_decimal(bool async)
=> AssertTranslationFailed(() => base.Average_with_division_on_decimal(async));

// SQLite client-eval
public override async Task Average_with_division_on_decimal_no_significant_digits(bool async)
{
Assert.StartsWith(
"The LINQ expression",
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.Average_with_division_on_decimal_no_significant_digits(async)))
.Message);
}
public override Task Average_with_division_on_decimal_no_significant_digits(bool async)
=> AssertTranslationFailed(() => base.Average_with_division_on_decimal_no_significant_digits(async));
}
}
Loading