Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avinash-phaniraj-readify committed Nov 30, 2018
1 parent 7786688 commit 0d65ccc
Showing 1 changed file with 62 additions and 2 deletions.
64 changes: 62 additions & 2 deletions MiscTests/JoinPostGroupByTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ from theDevice in emptyDevice.DefaultIfEmpty()
}

[Fact]
public void EfCoreTestLinqQuery_FailsTranslatingDefaultIfEmpty()
public void EfCoreTestLinqQuery_FailsTranslatingDefaultIfEmptyToSql()
{
base.EFContext(context => {

Expand Down Expand Up @@ -75,7 +75,7 @@ from theDevice in emptyDevice.DefaultIfEmpty()
}

[Fact]
public void EfCoreTestLinqQuery_Fails()
public void EfCoreTestLinqQuery_FailsWithInvalidSelectClause()
{
base.EFContext(context => {

Expand Down Expand Up @@ -105,5 +105,65 @@ from theDevice in emptyDevice.DefaultIfEmpty()
});
}

[Fact]
public void EfCoreTestLinqQuery_FailsWhenCountIsUsed()
{
base.EFContext(context => {

var q1 = from employee in context.Set<EFCore.Employee>()
join device in context.Set<EFCore.EmployeeDevice>() 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<EFCore.EmployeeDetails>() on q.Id equals details.EmployeeId
select new { q.Id, details.Details };

var exception = Assert.Throws<InvalidOperationException>(() => 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<EFCore.Employee>()
join device in context.Set<EFCore.EmployeeDevice>() 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<EFCore.EmployeeDetails>() on q.Id equals details.EmployeeId
select new { q.Id, details };

var exception = Assert.Throws<IndexOutOfRangeException>(() => q3.ToList());
});
}
}
}

0 comments on commit 0d65ccc

Please sign in to comment.