From 7f974730d2493c4334804bd273488a92ea69f9fb Mon Sep 17 00:00:00 2001 From: Maurycy Markowski Date: Fri, 8 Jan 2016 14:43:55 -0800 Subject: [PATCH] adding more tests (currently disabled) for left outer join cases as well as some more complex groupjoin + selectmany + defaultifempty queries --- .../ComplexNavigationsQueryTestBase.cs | 248 +++++++++++++++++- .../ComplexNavigationsQuerySqlServerTest.cs | 108 ++++++++ 2 files changed, 355 insertions(+), 1 deletion(-) diff --git a/test/EntityFramework.Core.FunctionalTests/ComplexNavigationsQueryTestBase.cs b/test/EntityFramework.Core.FunctionalTests/ComplexNavigationsQueryTestBase.cs index 88859b71198..0375373d568 100644 --- a/test/EntityFramework.Core.FunctionalTests/ComplexNavigationsQueryTestBase.cs +++ b/test/EntityFramework.Core.FunctionalTests/ComplexNavigationsQueryTestBase.cs @@ -752,7 +752,7 @@ public virtual void Select_nav_prop_collection_one_to_many_required() // issue #3186 ////[ConditionalFact] - public virtual void Select_nav_prop_reference_optional() + public virtual void Select_nav_prop_reference_optional1() { List expected; using (var context = CreateContext()) @@ -778,6 +778,104 @@ public virtual void Select_nav_prop_reference_optional() } } + // issue #4262 + ////[ConditionalFact] + public virtual void Select_nav_prop_reference_optional1_via_DefaultIfEmpty() + { + List expected; + using (var context = CreateContext()) + { + var l1s = context.LevelOne.ToList(); + var l2s = context.LevelTwo.ToList(); + + expected = (from l1 in l1s + join l2 in l2s on l1.Id equals l2.Level1_Optional_Id into groupJoin + from l2 in groupJoin.DefaultIfEmpty() + select l2 == null ? null : l2.Name).ToList(); + } + + ClearLog(); + + using (var context = CreateContext()) + { + var query = from l1 in context.LevelOne + join l2 in context.LevelTwo on l1.Id equals l2.Level1_Optional_Id into groupJoin + from l2 in groupJoin.DefaultIfEmpty() + select l2 == null ? null : l2.Name; + + var result = query.ToList(); + + Assert.Equal(expected.Count, result.Count); + for (int i = 0; i < result.Count; i++) + { + Assert.True(expected.Contains(result[i])); + } + } + } + + // issue #3186 + ////[ConditionalFact] + public virtual void Select_nav_prop_reference_optional2() + { + List expected; + using (var context = CreateContext()) + { + expected = context.LevelOne + .Include(e => e.OneToOne_Optional_FK) + .ToList() + .Select(e => e.OneToOne_Optional_FK.Id).ToList(); + } + + ClearLog(); + + using (var context = CreateContext()) + { + var query = context.LevelOne.Select(e => e.OneToOne_Optional_FK.Id); + var result = query.ToList(); + + Assert.Equal(expected.Count, result.Count); + for (int i = 0; i < result.Count; i++) + { + Assert.True(expected.Contains(result[i])); + } + } + } + + // issue #4262 + ////[ConditionalFact] + public virtual void Select_nav_prop_reference_optional2_via_DefaultIfEmpty() + { + List expected; + using (var context = CreateContext()) + { + var l1s = context.LevelOne.ToList(); + var l2s = context.LevelTwo.ToList(); + + expected = (from l1 in l1s + join l2 in l2s on l1.Id equals l2.Level1_Optional_Id into groupJoin + from l2 in groupJoin.DefaultIfEmpty() + select l2 == null ? null : (int?)l2.Id).ToList(); + } + + ClearLog(); + + using (var context = CreateContext()) + { + var query = from l1 in context.LevelOne + join l2 in context.LevelTwo on l1.Id equals l2.Level1_Optional_Id into groupJoin + from l2 in groupJoin.DefaultIfEmpty() + select l2 == null ? null : (int?)l2.Id; + + var result = query.ToList(); + + Assert.Equal(expected.Count, result.Count); + for (int i = 0; i < result.Count; i++) + { + Assert.True(expected.Contains(result[i])); + } + } + } + // issue #3186 ////[ConditionalFact] public virtual void Where_nav_prop_reference_optional1() @@ -810,6 +908,47 @@ public virtual void Where_nav_prop_reference_optional1() } } + // issue #4262 + ////[ConditionalFact] + public virtual void Where_nav_prop_reference_optional1_via_DefaultIfEmpty() + { + List expected; + using (var context = CreateContext()) + { + var l1s = context.LevelOne.ToList(); + var l2s = context.LevelTwo.ToList(); + + expected = (from l1 in l1s + join l2Left in l2s on l1.Id equals l2Left.Level1_Optional_Id into groupJoinLeft + from l2Left in groupJoinLeft.DefaultIfEmpty() + join l2Right in l2s on l1.Id equals l2Right.Level1_Optional_Id into groupJoinRight + from l2Right in groupJoinRight.DefaultIfEmpty() + where (l2Left == null ? null : l2Left.Name) == "L2 05" || (l2Right == null ? null : l2Right.Name) == "L2 07" + select l1.Id).ToList(); + } + + ClearLog(); + + using (var context = CreateContext()) + { + var query = from l1 in context.LevelOne + join l2Left in context.LevelTwo on l1.Id equals l2Left.Level1_Optional_Id into groupJoinLeft + from l2Left in groupJoinLeft.DefaultIfEmpty() + join l2Right in context.LevelTwo on l1.Id equals l2Right.Level1_Optional_Id into groupJoinRight + from l2Right in groupJoinRight.DefaultIfEmpty() + where (l2Left == null ? null : l2Left.Name) == "L2 05" || (l2Right == null ? null : l2Right.Name) == "L2 07" + select l1.Id; + + var result = query.ToList(); + + Assert.Equal(expected.Count, result.Count); + for (int i = 0; i < result.Count; i++) + { + Assert.True(expected.Contains(result[i])); + } + } + } + // issue #3186 ////[ConditionalFact] public virtual void Where_nav_prop_reference_optional2() @@ -842,6 +981,47 @@ public virtual void Where_nav_prop_reference_optional2() } } + // issue #4262 + ////[ConditionalFact] + public virtual void Where_nav_prop_reference_optional2_via_DefaultIfEmpty() + { + List expected; + using (var context = CreateContext()) + { + var l1s = context.LevelOne.ToList(); + var l2s = context.LevelTwo.ToList(); + + expected = (from l1 in l1s + join l2Left in l2s on l1.Id equals l2Left.Level1_Optional_Id into groupJoinLeft + from l2Left in groupJoinLeft.DefaultIfEmpty() + join l2Right in l2s on l1.Id equals l2Right.Level1_Optional_Id into groupJoinRight + from l2Right in groupJoinRight.DefaultIfEmpty() + where (l2Left == null ? null : l2Left.Name) == "L2 05" || (l2Right == null ? null : l2Right.Name) != "L2 42" + select l1.Id).ToList(); + } + + ClearLog(); + + using (var context = CreateContext()) + { + var query = from l1 in context.LevelOne + join l2Left in context.LevelTwo on l1.Id equals l2Left.Level1_Optional_Id into groupJoinLeft + from l2Left in groupJoinLeft.DefaultIfEmpty() + join l2Right in context.LevelTwo on l1.Id equals l2Right.Level1_Optional_Id into groupJoinRight + from l2Right in groupJoinRight.DefaultIfEmpty() + where (l2Left == null ? null : l2Left.Name) == "L2 05" || (l2Right == null ? null : l2Right.Name) != "L2 42" + select l1.Id; + + var result = query.ToList(); + + Assert.Equal(expected.Count, result.Count); + for (int i = 0; i < result.Count; i++) + { + Assert.True(expected.Contains(result[i])); + } + } + } + // issue #3186 ////[ConditionalFact] public virtual void OrderBy_nav_prop_reference_optional() @@ -872,6 +1052,43 @@ public virtual void OrderBy_nav_prop_reference_optional() } } + // issue #4262 + ////[ConditionalFact] + public virtual void OrderBy_nav_prop_reference_optional_via_DefaultIfEmpty() + { + List expected; + using (var context = CreateContext()) + { + var l1s = context.LevelOne.ToList(); + var l2s = context.LevelTwo.ToList(); + + expected = (from l1 in l1s + join l2 in l2s on l1.Id equals l2.Level1_Optional_Id into groupJoin + from l2 in groupJoin.DefaultIfEmpty() + orderby l2 == null ? null : l2.Name + select l1.Id).ToList(); + } + + ClearLog(); + + using (var context = CreateContext()) + { + var query = from l1 in context.LevelOne + join l2 in context.LevelTwo on l1.Id equals l2.Level1_Optional_Id into groupJoin + from l2 in groupJoin.DefaultIfEmpty() + orderby l2 == null ? null : l2.Name + select l1.Id; + + var result = query.ToList(); + + Assert.Equal(expected.Count, result.Count); + for (int i = 0; i < result.Count; i++) + { + Assert.True(expected.Contains(result[i])); + } + } + } + // issue #3186 ////[ConditionalFact] public virtual void Result_operator_nav_prop_reference_optional() @@ -894,5 +1111,34 @@ public virtual void Result_operator_nav_prop_reference_optional() Assert.Equal(expected, result); } } + + // issue #4262 + ////[ConditionalFact] + public virtual void Result_operator_nav_prop_reference_optional_via_DefaultIfEmpty() + { + int expected; + using (var context = CreateContext()) + { + var l1s = context.LevelOne.ToList(); + var l2s = context.LevelTwo.ToList(); + + expected = (from l1 in l1s + join l2 in l2s on l1.Id equals l2.Level1_Optional_Id into groupJoin + from l2 in groupJoin.DefaultIfEmpty() + select l2).Sum(e => e == null ? 0 : e.Level1_Required_Id); + } + + ClearLog(); + + using (var context = CreateContext()) + { + var result = (from l1 in context.LevelOne + join l2 in context.LevelTwo on l1.Id equals l2.Level1_Optional_Id into groupJoin + from l2 in groupJoin.DefaultIfEmpty() + select l2).Sum(e => e == null ? 0 : e.Level1_Required_Id); + + Assert.Equal(expected, result); + } + } } } diff --git a/test/EntityFramework.MicrosoftSqlServer.FunctionalTests/ComplexNavigationsQuerySqlServerTest.cs b/test/EntityFramework.MicrosoftSqlServer.FunctionalTests/ComplexNavigationsQuerySqlServerTest.cs index 682ed8e6c94..bd49723cc6b 100644 --- a/test/EntityFramework.MicrosoftSqlServer.FunctionalTests/ComplexNavigationsQuerySqlServerTest.cs +++ b/test/EntityFramework.MicrosoftSqlServer.FunctionalTests/ComplexNavigationsQuerySqlServerTest.cs @@ -360,6 +360,114 @@ FROM [Level1] AS [e] Sql); } + public override void Select_nav_prop_reference_optional1() + { + base.Select_nav_prop_reference_optional1(); + + Assert.Equal( + @"", + Sql); + } + + public override void Select_nav_prop_reference_optional1_via_DefaultIfEmpty() + { + base.Select_nav_prop_reference_optional1_via_DefaultIfEmpty(); + + Assert.Equal( + @"", + Sql); + } + + public override void Select_nav_prop_reference_optional2() + { + base.Select_nav_prop_reference_optional2(); + + Assert.Equal( + @"", + Sql); + } + + public override void Select_nav_prop_reference_optional2_via_DefaultIfEmpty() + { + base.Select_nav_prop_reference_optional2_via_DefaultIfEmpty(); + + Assert.Equal( + @"", + Sql); + } + + public override void Where_nav_prop_reference_optional1() + { + base.Where_nav_prop_reference_optional1(); + + Assert.Equal( + @"", + Sql); + } + + public override void Where_nav_prop_reference_optional1_via_DefaultIfEmpty() + { + base.Where_nav_prop_reference_optional1_via_DefaultIfEmpty(); + + Assert.Equal( + @"", + Sql); + } + + public override void Where_nav_prop_reference_optional2() + { + base.Where_nav_prop_reference_optional2(); + + Assert.Equal( + @"", + Sql); + } + + public override void Where_nav_prop_reference_optional2_via_DefaultIfEmpty() + { + base.Where_nav_prop_reference_optional2_via_DefaultIfEmpty(); + + Assert.Equal( + @"", + Sql); + } + + public override void OrderBy_nav_prop_reference_optional() + { + base.OrderBy_nav_prop_reference_optional(); + + Assert.Equal( + @"", + Sql); + } + + public override void OrderBy_nav_prop_reference_optional_via_DefaultIfEmpty() + { + base.OrderBy_nav_prop_reference_optional_via_DefaultIfEmpty(); + + Assert.Equal( + @"", + Sql); + } + + public override void Result_operator_nav_prop_reference_optional() + { + base.Result_operator_nav_prop_reference_optional(); + + Assert.Equal( + @"", + Sql); + } + + public override void Result_operator_nav_prop_reference_optional_via_DefaultIfEmpty() + { + base.Result_operator_nav_prop_reference_optional_via_DefaultIfEmpty(); + + Assert.Equal( + @"", + Sql); + } + // issue #3491 //[Fact] public virtual void Multiple_complex_includes_from_sql()