Skip to content

Commit

Permalink
ComplexNavigations test refactoring
Browse files Browse the repository at this point in the history
- moving collection navigation related tests to separate test class
- adding split query tests for all these collection-related tests
- removing dedicated split query tests, which were just copies of some of the collection tests
- for now, split query tests are disabled
  • Loading branch information
maumar committed Apr 21, 2021
1 parent f9c4e71 commit e830e9c
Show file tree
Hide file tree
Showing 25 changed files with 6,039 additions and 6,487 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Xunit.Abstractions;

namespace Microsoft.EntityFrameworkCore.Query
{
public class ComplexNavigationsCollectionsQueryInMemoryTest : ComplexNavigationsCollectionsQueryTestBase<ComplexNavigationsQueryInMemoryFixture>
{
public ComplexNavigationsCollectionsQueryInMemoryTest(ComplexNavigationsQueryInMemoryFixture fixture, ITestOutputHelper testOutputHelper)
: base(fixture)
{
//TestLoggerFactory.TestOutputHelper = testOutputHelper;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Xunit.Abstractions;

namespace Microsoft.EntityFrameworkCore.Query
{
public class ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest :
ComplexNavigationsCollectionsSharedTypeQueryTestBase<ComplexNavigationsSharedTypeQueryInMemoryFixture>
{
// ReSharper disable once UnusedParameter.Local
public ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest(
ComplexNavigationsSharedTypeQueryInMemoryFixture fixture,
ITestOutputHelper testOutputHelper)
: base(fixture)
{
//TestLoggerFactory.TestOutputHelper = testOutputHelper;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.EntityFrameworkCore.Query
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.EntityFrameworkCore.Query
{
public abstract class ComplexNavigationsCollectionsQueryRelationalTestBase<TFixture> : ComplexNavigationsCollectionsQueryTestBase<TFixture>
where TFixture : ComplexNavigationsQueryFixtureBase, new()
{
protected ComplexNavigationsCollectionsQueryRelationalTestBase(TFixture fixture)
: base(fixture)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.EntityFrameworkCore.Query
{
public abstract class ComplexNavigationsCollectionsSharedQueryTypeRelationalTestBase<TFixture> : ComplexNavigationsCollectionsSharedTypeQueryTestBase<TFixture>
where TFixture : ComplexNavigationsSharedTypeQueryRelationalFixtureBase, new()
{
protected ComplexNavigationsCollectionsSharedQueryTypeRelationalTestBase(TFixture fixture)
: base(fixture)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;

namespace Microsoft.EntityFrameworkCore.Query
{
public abstract class ComplexNavigationsCollectionsSplitQueryRelationalTestBase<TFixture> : ComplexNavigationsCollectionsQueryTestBase<TFixture>
where TFixture : ComplexNavigationsQueryFixtureBase, new()
{
protected ComplexNavigationsCollectionsSplitQueryRelationalTestBase(TFixture fixture)
: base(fixture)
{
}

protected override Expression RewriteServerQueryExpression(Expression serverQueryExpression)
=> new SplitQueryRewritingExpressionVisitor().Visit(serverQueryExpression);

private class SplitQueryRewritingExpressionVisitor : ExpressionVisitor
{
private readonly MethodInfo _asSplitQueryMethod
= typeof(RelationalQueryableExtensions).GetMethod(nameof(RelationalQueryableExtensions.AsSplitQuery));

protected override Expression VisitExtension(Expression extensionExpression)
{
if (extensionExpression is QueryRootExpression rootExpression)
{
var splitMethod = _asSplitQueryMethod.MakeGenericMethod(rootExpression.EntityType.ClrType);

return Expression.Call(splitMethod, rootExpression);
}

return base.VisitExtension(extensionExpression);
}
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Complex_query_with_let_collection_projection_FirstOrDefault(bool async)
{
return base.Complex_query_with_let_collection_projection_FirstOrDefault(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(bool async)
{
return base.Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Filtered_include_outer_parameter_used_inside_filter(bool async)
{
return base.Filtered_include_outer_parameter_used_inside_filter(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Include_inside_subquery(bool async)
{
return base.Include_inside_subquery(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Lift_projection_mapping_when_pushing_down_subquery(bool async)
{
return base.Lift_projection_mapping_when_pushing_down_subquery(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Null_check_in_anonymous_type_projection_should_not_be_removed(bool async)
{
return base.Null_check_in_anonymous_type_projection_should_not_be_removed(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Null_check_in_Dto_projection_should_not_be_removed(bool async)
{
return base.Null_check_in_Dto_projection_should_not_be_removed(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Project_collection_navigation_composed(bool async)
{
return base.Project_collection_navigation_composed(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Project_collection_navigation_nested_with_take(bool async)
{
return base.Project_collection_navigation_nested_with_take(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Select_nav_prop_collection_one_to_many_required(bool async)
{
return base.Select_nav_prop_collection_one_to_many_required(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Select_subquery_single_nested_subquery(bool async)
{
return base.Select_subquery_single_nested_subquery(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Select_subquery_single_nested_subquery2(bool async)
{
return base.Select_subquery_single_nested_subquery2(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task SelectMany_DefaultIfEmpty_multiple_times_with_joins_projecting_a_collection(bool async)
{
return base.SelectMany_DefaultIfEmpty_multiple_times_with_joins_projecting_a_collection(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Skip_Take_Select_collection_Skip_Take(bool async)
{
return base.Skip_Take_Select_collection_Skip_Take(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Take_Select_collection_Take(bool async)
{
return base.Take_Select_collection_Take(async);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;

namespace Microsoft.EntityFrameworkCore.Query
{
public abstract class ComplexNavigationsCollectionsSplitSharedQueryTypeRelationalTestBase<TFixture> : ComplexNavigationsCollectionsSharedTypeQueryTestBase<TFixture>
where TFixture : ComplexNavigationsSharedTypeQueryRelationalFixtureBase, new()
{
protected ComplexNavigationsCollectionsSplitSharedQueryTypeRelationalTestBase(TFixture fixture)
: base(fixture)
{
}

protected override Expression RewriteServerQueryExpression(Expression serverQueryExpression)
=> new SplitQueryRewritingExpressionVisitor().Visit(serverQueryExpression);

private class SplitQueryRewritingExpressionVisitor : ExpressionVisitor
{
private readonly MethodInfo _asSplitQueryMethod
= typeof(RelationalQueryableExtensions).GetMethod(nameof(RelationalQueryableExtensions.AsSplitQuery));

protected override Expression VisitExtension(Expression extensionExpression)
{
if (extensionExpression is QueryRootExpression rootExpression)
{
var splitMethod = _asSplitQueryMethod.MakeGenericMethod(rootExpression.EntityType.ClrType);

return Expression.Call(splitMethod, rootExpression);
}

return base.VisitExtension(extensionExpression);
}
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Complex_query_with_let_collection_projection_FirstOrDefault(bool async)
{
return base.Complex_query_with_let_collection_projection_FirstOrDefault(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(bool async)
{
return base.Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Filtered_include_outer_parameter_used_inside_filter(bool async)
{
return base.Filtered_include_outer_parameter_used_inside_filter(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Include_inside_subquery(bool async)
{
return base.Include_inside_subquery(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Lift_projection_mapping_when_pushing_down_subquery(bool async)
{
return base.Lift_projection_mapping_when_pushing_down_subquery(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Null_check_in_anonymous_type_projection_should_not_be_removed(bool async)
{
return base.Null_check_in_anonymous_type_projection_should_not_be_removed(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Null_check_in_Dto_projection_should_not_be_removed(bool async)
{
return base.Null_check_in_Dto_projection_should_not_be_removed(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Project_collection_navigation_composed(bool async)
{
return base.Project_collection_navigation_composed(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Project_collection_navigation_nested_with_take(bool async)
{
return base.Project_collection_navigation_nested_with_take(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Select_nav_prop_collection_one_to_many_required(bool async)
{
return base.Select_nav_prop_collection_one_to_many_required(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Select_subquery_single_nested_subquery(bool async)
{
return base.Select_subquery_single_nested_subquery(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Select_subquery_single_nested_subquery2(bool async)
{
return base.Select_subquery_single_nested_subquery2(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task SelectMany_DefaultIfEmpty_multiple_times_with_joins_projecting_a_collection(bool async)
{
return base.SelectMany_DefaultIfEmpty_multiple_times_with_joins_projecting_a_collection(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Skip_Take_Select_collection_Skip_Take(bool async)
{
return base.Skip_Take_Select_collection_Skip_Take(async);
}

[ConditionalTheory(Skip = "Split query not fully supported yet.")]
public override Task Take_Select_collection_Take(bool async)
{
return base.Take_Select_collection_Take(async);
}

[ConditionalTheory(Skip = "Split query bug")]
public override Task Include_reference_collection_order_by_reference_navigation(bool async)
{
return base.Include_reference_collection_order_by_reference_navigation(async);
}
}
}
Loading

0 comments on commit e830e9c

Please sign in to comment.