From 0d65ccc9c44a4b96db6be6cf80a14b00884a643a Mon Sep 17 00:00:00 2001 From: Avinash Phaniraj Date: Fri, 30 Nov 2018 11:32:36 +1100 Subject: [PATCH] Added tests --- MiscTests/JoinPostGroupByTest.cs | 64 +++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/MiscTests/JoinPostGroupByTest.cs b/MiscTests/JoinPostGroupByTest.cs index 5cca77d..016c0d5 100644 --- a/MiscTests/JoinPostGroupByTest.cs +++ b/MiscTests/JoinPostGroupByTest.cs @@ -45,7 +45,7 @@ from theDevice in emptyDevice.DefaultIfEmpty() } [Fact] - public void EfCoreTestLinqQuery_FailsTranslatingDefaultIfEmpty() + public void EfCoreTestLinqQuery_FailsTranslatingDefaultIfEmptyToSql() { base.EFContext(context => { @@ -75,7 +75,7 @@ from theDevice in emptyDevice.DefaultIfEmpty() } [Fact] - public void EfCoreTestLinqQuery_Fails() + public void EfCoreTestLinqQuery_FailsWithInvalidSelectClause() { base.EFContext(context => { @@ -105,5 +105,65 @@ from theDevice in emptyDevice.DefaultIfEmpty() }); } + [Fact] + public void EfCoreTestLinqQuery_FailsWhenCountIsUsed() + { + base.EFContext(context => { + + var q1 = from employee in context.Set() + join device in context.Set() on employee.Id equals device.EmployeeId into emptyDevice + from theDevice in emptyDevice.DefaultIfEmpty() + select new { employee.Id, theDevice.Device }; + + var q2 = from q in q1 + group q by new + { + q.Id, + } into s + select new + { + Id = s.Key.Id, + DeviceCount = s.Count(a=> a.Device != null) + }; + + var q3 = from q in q2 + join details in context.Set() on q.Id equals details.EmployeeId + select new { q.Id, details.Details }; + + var exception = Assert.Throws(() => q3.ToList()); + + Assert.Equal("Error generated for warning 'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning: The LINQ expression 'GroupBy(new <>f__AnonymousType3`1(Id = [employee].Id), new <>f__AnonymousType6`2(Id = [employee].Id, Device = [theDevice]?.Device))' could not be translated and will be evaluated locally.'. This exception can be suppressed or logged by passing event ID 'RelationalEventId.QueryClientEvaluationWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.", exception.Message); + }); + } + + + [Fact] + public void EfCoreTestLinqQuery_FailsWithIndexOutOfRange() + { + base.EFContext(context => { + + var q1 = from employee in context.Set() + join device in context.Set() on employee.Id equals device.EmployeeId into emptyDevice + from theDevice in emptyDevice.DefaultIfEmpty() + select new { employee.Id, theDevice.Device }; + + var q2 = from q in q1 + group q by new + { + q.Id, + } into s + select new + { + Id = s.Key.Id, + DeviceCount = s.Count(a => a.Device != null) + }; + + var q3 = from q in q2 + join details in context.Set() on q.Id equals details.EmployeeId + select new { q.Id, details }; + + var exception = Assert.Throws(() => q3.ToList()); + }); + } } }