Skip to content

Commit

Permalink
Fix to #25834 - Query/Test: northwind tests don't have predefined ent…
Browse files Browse the repository at this point in the history
…ity asserters

Also minor test fixes that were found as a result of fixing this.

Fixes #25834
  • Loading branch information
maumar committed Sep 2, 2021
1 parent 7912a3a commit 2fe45a4
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,23 @@ public IReadOnlyDictionary<Type, object> GetEntityAsserters()
}
}
},
{
typeof(NestedReferenceDerived), (e, a) =>
{
Assert.Equal(e == null, a == null);
if (a != null)
{
var ee = (NestedReferenceDerived)e;
var aa = (NestedReferenceDerived)a;
Assert.Equal(ee.Id, aa.Id);
Assert.Equal(ee.Name, aa.Name);
Assert.Equal(ee.ParentReferenceId, aa.ParentReferenceId);
Assert.Equal(ee.ParentCollectionId, aa.ParentCollectionId);
}
}
},
{
typeof(NonEntityBase), (e, a) =>
{
Expand Down
146 changes: 145 additions & 1 deletion test/EFCore.Specification.Tests/Query/NorthwindQueryFixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.TestModels.Northwind;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Xunit;

namespace Microsoft.EntityFrameworkCore.Query
{
Expand Down Expand Up @@ -90,7 +91,150 @@ public IReadOnlyDictionary<Type, object> GetEntitySorters()
}.ToDictionary(e => e.Key, e => (object)e.Value);

public IReadOnlyDictionary<Type, object> GetEntityAsserters()
=> null;
=> new Dictionary<Type, Action<object, object>>
{
{
typeof(Customer), (e, a) =>
{
Assert.Equal(e == null, a == null);
if (a != null)
{
var ee = (Customer)e;
var aa = (Customer)a;
Assert.Equal(ee.CustomerID, aa.CustomerID);
Assert.Equal(ee.Address, aa.Address);
Assert.Equal(ee.CompanyName, aa.CompanyName);
Assert.Equal(ee.ContactName, aa.ContactName);
Assert.Equal(ee.ContactTitle, aa.ContactTitle);
Assert.Equal(ee.Country, aa.Country);
Assert.Equal(ee.Fax, aa.Fax);
Assert.Equal(ee.Phone, aa.Phone);
Assert.Equal(ee.PostalCode, aa.PostalCode);
}
}
},
{
typeof(CustomerQuery), (e, a) =>
{
Assert.Equal(e == null, a == null);
if (a != null)
{
var ee = (CustomerQuery)e;
var aa = (CustomerQuery)a;
Assert.Equal(ee.CompanyName, aa.CompanyName);
Assert.Equal(ee.Address, aa.Address);
Assert.Equal(ee.City, aa.City);
Assert.Equal(ee.ContactName, aa.ContactName);
Assert.Equal(ee.ContactTitle, aa.ContactTitle);
}
}
},
{
typeof(Order), (e, a) =>
{
Assert.Equal(e == null, a == null);
if (a != null)
{
var ee = (Order)e;
var aa = (Order)a;
Assert.Equal(ee.OrderID, aa.OrderID);
Assert.Equal(ee.CustomerID, aa.CustomerID);
Assert.Equal(ee.EmployeeID, aa.EmployeeID);
Assert.Equal(ee.OrderDate, aa.OrderDate);
}
}
},
{
typeof(OrderQuery), (e, a) =>
{
Assert.Equal(e == null, a == null);
if (a != null)
{
var ee = (OrderQuery)e;
var aa = (OrderQuery)a;
Assert.Equal(ee.CustomerID, aa.CustomerID);
}
}
},
{
typeof(Employee), (e, a) =>
{
Assert.Equal(e == null, a == null);
if (a != null)
{
var ee = (Employee)e;
var aa = (Employee)a;
Assert.Equal(ee.EmployeeID, aa.EmployeeID);
Assert.Equal(ee.Title, aa.Title);
Assert.Equal(ee.City, aa.City);
Assert.Equal(ee.Country, aa.Country);
Assert.Equal(ee.FirstName, aa.FirstName);
}
}
},
{
typeof(Product), (e, a) =>
{
Assert.Equal(e == null, a == null);
if (a != null)
{
var ee = (Product)e;
var aa = (Product)a;
Assert.Equal(ee.ProductID, aa.ProductID);
Assert.Equal(ee.ProductName, aa.ProductName);
Assert.Equal(ee.SupplierID, aa.SupplierID);
Assert.Equal(ee.UnitPrice, aa.UnitPrice);
Assert.Equal(ee.UnitsInStock, aa.UnitsInStock);
}
}
},
{
typeof(ProductQuery), (e, a) =>
{
Assert.Equal(e == null, a == null);
if (a != null)
{
var ee = (ProductQuery)e;
var aa = (ProductQuery)a;
Assert.Equal(ee.ProductID, aa.ProductID);
Assert.Equal(ee.CategoryName, aa.CategoryName);
Assert.Equal(ee.ProductName, aa.ProductName);
}
}
},
{
typeof(OrderDetail), (e, a) =>
{
Assert.Equal(e == null, a == null);
if (a != null)
{
var ee = (OrderDetail)e;
var aa = (OrderDetail)a;
Assert.Equal(ee.OrderID, aa.OrderID);
Assert.Equal(ee.ProductID, aa.ProductID);
Assert.Equal(ee.Quantity, aa.Quantity);
Assert.Equal(ee.UnitPrice, aa.UnitPrice);
Assert.Equal(ee.Discount, aa.Discount);
}
}
},
}.ToDictionary(e => e.Key, e => (object)e.Value);

protected override string StoreName { get; } = "Northwind";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2240,7 +2240,7 @@ public virtual Task Collection_include_over_result_of_single_non_scalar(bool asy
elementSorter: e => e.c.CustomerID,
elementAsserter: (e, a) =>
{
AssertInclude(e, a,
AssertInclude(e.c, a.c,
new ExpectedInclude<Customer>(c => c.Orders),
new ExpectedInclude<Order>(o => o.OrderDetails, "Orders"));
AssertInclude(e.SingleOrder, a.SingleOrder, new ExpectedInclude<Order>(o => o.OrderDetails));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,10 @@ private void AssertIncludeEntity<TElement>(TElement expected, TElement actual, I
((Action<TElement, TElement>)asserter)(expected, actual);
ProcessIncludes(expected, actual, expectedIncludes);
}
else
{
throw new InvalidOperationException($"Couldn't find entity asserter for entity type: '{typeof(TElement).Name}'.");
}
}

private void AssertIncludeCollection<TElement>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.EntityFrameworkCore.Query
Expand All @@ -18,5 +20,17 @@ public NorthwindSplitIncludeNoTrackingQuerySqlServerTest(
Fixture.TestSqlLoggerFactory.Clear();
//Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

[ConditionalTheory(Skip = "Issue#21202")]
public override async Task Include_collection_skip_take_no_order_by(bool async)
{
await base.Include_collection_skip_take_no_order_by(async);
}

[ConditionalTheory(Skip = "Issue#21202")]
public override async Task Include_collection_skip_no_order_by(bool async)
{
await base.Include_collection_skip_no_order_by(async);
}
}
}

0 comments on commit 2fe45a4

Please sign in to comment.