You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
225 lines
10 KiB
C#
225 lines
10 KiB
C#
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System.Threading.Tasks;
|
|
using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities;
|
|
using Microsoft.EntityFrameworkCore.Query;
|
|
using Microsoft.EntityFrameworkCore.TestUtilities;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace EntityFrameworkCore.Jet.FunctionalTests.Query
|
|
{
|
|
public class CompiledQueryJetTest : CompiledQueryTestBase<NorthwindQueryJetFixture<NoopModelCustomizer>>
|
|
{
|
|
public CompiledQueryJetTest(NorthwindQueryJetFixture<NoopModelCustomizer> fixture, ITestOutputHelper testOutputHelper)
|
|
: base(fixture)
|
|
{
|
|
fixture.TestSqlLoggerFactory.Clear();
|
|
//fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
|
|
}
|
|
|
|
public override void DbSet_query()
|
|
{
|
|
base.DbSet_query();
|
|
|
|
AssertSql(
|
|
$@"SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`",
|
|
//
|
|
$@"SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`");
|
|
}
|
|
|
|
public override void DbSet_query_first()
|
|
{
|
|
base.DbSet_query_first();
|
|
|
|
AssertSql(
|
|
$@"SELECT TOP 1 `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
ORDER BY `c`.`CustomerID`");
|
|
}
|
|
|
|
public override void Query_ending_with_include()
|
|
{
|
|
base.Query_ending_with_include();
|
|
|
|
AssertSql(
|
|
$@"SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`, `o`.`OrderID`, `o`.`CustomerID`, `o`.`EmployeeID`, `o`.`OrderDate`
|
|
FROM `Customers` AS `c`
|
|
LEFT JOIN `Orders` AS `o` ON `c`.`CustomerID` = `o`.`CustomerID`
|
|
ORDER BY `c`.`CustomerID`, `o`.`OrderID`");
|
|
}
|
|
|
|
public override void Untyped_context()
|
|
{
|
|
base.Untyped_context();
|
|
|
|
AssertSql(
|
|
$@"SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`",
|
|
//
|
|
$@"SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`");
|
|
}
|
|
|
|
public override void Query_with_single_parameter()
|
|
{
|
|
base.Query_with_single_parameter();
|
|
|
|
AssertSql(
|
|
$@"{AssertSqlHelper.Declaration("@__customerID='ALFKI' (Size = 5)")}
|
|
|
|
SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` = {AssertSqlHelper.Parameter("@__customerID")}",
|
|
//
|
|
$@"{AssertSqlHelper.Declaration("@__customerID='ANATR' (Size = 5)")}
|
|
|
|
SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` = {AssertSqlHelper.Parameter("@__customerID")}");
|
|
}
|
|
|
|
public override void First_query_with_single_parameter()
|
|
{
|
|
base.First_query_with_single_parameter();
|
|
|
|
AssertSql(
|
|
$@"{AssertSqlHelper.Declaration("@__customerID='ALFKI' (Size = 5)")}
|
|
|
|
SELECT TOP 1 `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` = {AssertSqlHelper.Parameter("@__customerID")}",
|
|
//
|
|
$@"{AssertSqlHelper.Declaration("@__customerID='ANATR' (Size = 5)")}
|
|
|
|
SELECT TOP 1 `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` = {AssertSqlHelper.Parameter("@__customerID")}");
|
|
}
|
|
|
|
public override void Query_with_two_parameters()
|
|
{
|
|
base.Query_with_two_parameters();
|
|
|
|
AssertSql(
|
|
$@"{AssertSqlHelper.Declaration("@__customerID='ALFKI' (Size = 5)")}
|
|
|
|
SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` = {AssertSqlHelper.Parameter("@__customerID")}",
|
|
//
|
|
$@"{AssertSqlHelper.Declaration("@__customerID='ANATR' (Size = 5)")}
|
|
|
|
SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` = {AssertSqlHelper.Parameter("@__customerID")}");
|
|
}
|
|
|
|
public override void Query_with_three_parameters()
|
|
{
|
|
base.Query_with_three_parameters();
|
|
|
|
AssertSql(
|
|
$@"{AssertSqlHelper.Declaration("@__customerID='ALFKI' (Size = 5)")}
|
|
|
|
SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` = {AssertSqlHelper.Parameter("@__customerID")}",
|
|
//
|
|
$@"{AssertSqlHelper.Declaration("@__customerID='ANATR' (Size = 5)")}
|
|
|
|
SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` = {AssertSqlHelper.Parameter("@__customerID")}");
|
|
}
|
|
|
|
public override void Query_with_contains()
|
|
{
|
|
base.Query_with_contains();
|
|
|
|
AssertSql(
|
|
$@"SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` IN ('ALFKI')",
|
|
//
|
|
$@"SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` IN ('ANATR')");
|
|
}
|
|
|
|
public override void Query_with_closure()
|
|
{
|
|
base.Query_with_closure();
|
|
|
|
AssertSql(
|
|
$@"SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` = 'ALFKI'",
|
|
//
|
|
$@"SELECT `c`.`CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region`
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` = 'ALFKI'");
|
|
}
|
|
|
|
public override async Task DbQuery_query_async()
|
|
{
|
|
await base.DbQuery_query_async();
|
|
|
|
AssertSql(
|
|
$@"SELECT `c`.`CustomerID` + '' as `CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region` FROM `Customers` AS `c`",
|
|
//
|
|
$@"SELECT `c`.`CustomerID` + '' as `CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region` FROM `Customers` AS `c`");
|
|
}
|
|
|
|
public override void DbQuery_query_first()
|
|
{
|
|
base.DbQuery_query_first();
|
|
|
|
AssertSql(
|
|
$@"SELECT TOP 1 `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`
|
|
FROM (
|
|
SELECT `c`.`CustomerID` + '' as `CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region` FROM `Customers` AS `c`
|
|
) AS `c`
|
|
ORDER BY `c`.`CompanyName`");
|
|
}
|
|
|
|
public override async Task DbQuery_query_first_async()
|
|
{
|
|
await base.DbQuery_query_first_async();
|
|
|
|
AssertSql(
|
|
$@"SELECT TOP 1 `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`
|
|
FROM (
|
|
SELECT `c`.`CustomerID` + '' as `CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region` FROM `Customers` AS `c`
|
|
) AS `c`
|
|
ORDER BY `c`.`CompanyName`");
|
|
}
|
|
|
|
public override void DbQuery_query()
|
|
{
|
|
base.DbQuery_query();
|
|
|
|
AssertSql(
|
|
$@"SELECT `c`.`CustomerID` + '' as `CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region` FROM `Customers` AS `c`",
|
|
//
|
|
$@"SELECT `c`.`CustomerID` + '' as `CustomerID`, `c`.`Address`, `c`.`City`, `c`.`CompanyName`, `c`.`ContactName`, `c`.`ContactTitle`, `c`.`Country`, `c`.`Fax`, `c`.`Phone`, `c`.`PostalCode`, `c`.`Region` FROM `Customers` AS `c`");
|
|
}
|
|
|
|
public override void Compiled_query_when_does_not_end_in_query_operator()
|
|
{
|
|
base.Compiled_query_when_does_not_end_in_query_operator();
|
|
|
|
AssertSql(
|
|
$@"{AssertSqlHelper.Declaration("@__customerID='ALFKI' (Size = 5)")}
|
|
|
|
SELECT COUNT(*)
|
|
FROM `Customers` AS `c`
|
|
WHERE `c`.`CustomerID` = {AssertSqlHelper.Parameter("@__customerID")}");
|
|
}
|
|
|
|
private void AssertSql(params string[] expected)
|
|
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
|
|
}
|
|
}
|