Skip to content

Commit

Permalink
Fix some test determinism issue
Browse files Browse the repository at this point in the history
Following #19828
  • Loading branch information
roji committed Aug 18, 2021
1 parent 0ba1695 commit 87bc08d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
48 changes: 29 additions & 19 deletions test/EFCore.Specification.Tests/Query/NorthwindJoinQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -799,26 +799,36 @@ public virtual Task SelectMany_with_client_eval_with_constructor(bool async)
.OrderBy(c => c.CustomerID)
.Select(
c => new CustomerViewModel(
c.CustomerID, c.City,
c.CustomerID,
c.City,
c.Orders.SelectMany(
o => o.OrderDetails
.Where(od => od.OrderID < 11000)
.Select(od => new OrderDetailViewModel(od.OrderID, od.ProductID)))
// .OrderBy(od => od.OrderID)
.ToArray())),
assertOrder: true);
assertOrder: true,
elementAsserter: (e, a) =>
{
Assert.Equal(e.CustomerID, a.CustomerID);
Assert.Equal(e.City, a.City);
Assert.Equal(
e.Views.OrderBy(od => od.OrderID).ThenBy(od => od.ProductID),
a.Views.OrderBy(od => od.OrderID).ThenBy(od => od.ProductID));
});
}

private class CustomerViewModel
{
private readonly string _customerID;
private readonly string _city;
private readonly OrderDetailViewModel[] _views;
public string CustomerID { get; }
public string City { get; }
public OrderDetailViewModel[] Views { get; }

public CustomerViewModel(string customerID, string city, OrderDetailViewModel[] views)
{
_customerID = customerID;
_city = city;
_views = views;
CustomerID = customerID;
City = city;
Views = views;
}

public override bool Equals(object obj)
Expand All @@ -834,23 +844,23 @@ public override bool Equals(object obj)
}

private bool Equals(CustomerViewModel customerViewModel)
=> _customerID == customerViewModel._customerID
&& _city == customerViewModel._city
&& _views.SequenceEqual(customerViewModel._views);
=> CustomerID == customerViewModel.CustomerID
&& City == customerViewModel.City
&& Views.SequenceEqual(customerViewModel.Views);

public override int GetHashCode()
=> HashCode.Combine(_customerID, _city);
=> HashCode.Combine(CustomerID, City);
}

private class OrderDetailViewModel
{
private readonly int _orderID;
private readonly int _productID;
public int OrderID { get; }
public int ProductID { get; }

public OrderDetailViewModel(int orderID, int productID)
{
_orderID = orderID;
_productID = productID;
OrderID = orderID;
ProductID = productID;
}

public override bool Equals(object obj)
Expand All @@ -866,11 +876,11 @@ public override bool Equals(object obj)
}

private bool Equals(OrderDetailViewModel orderDetailViewModel)
=> _orderID == orderDetailViewModel._orderID
&& _productID == orderDetailViewModel._productID;
=> OrderID == orderDetailViewModel.OrderID
&& ProductID == orderDetailViewModel.ProductID;

public override int GetHashCode()
=> HashCode.Combine(_orderID, _productID);
=> HashCode.Combine(OrderID, ProductID);
}

[ConditionalTheory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,7 @@ public virtual Task Where_collection_navigation_ToList_Contains(bool async)
return AssertQuery(
async,
ss => ss.Set<Customer>()
.Select(c => c.Orders.ToList())
.Select(c => c.Orders.OrderBy(o => o.OrderID).ToList())
.Where(e => e.Contains(order)),
entryCount: 5);
}
Expand Down Expand Up @@ -2251,7 +2251,7 @@ public virtual Task Where_collection_navigation_ToArray_Contains(bool async)
return AssertQuery(
async,
ss => ss.Set<Customer>()
.Select(c => c.Orders.AsEnumerable().ToArray())
.Select(c => c.Orders.AsEnumerable().OrderBy(o => o.OrderID).ToArray())
.Where(e => e.Contains(order)),
entryCount: 5);
}
Expand Down Expand Up @@ -2280,7 +2280,7 @@ public virtual Task Where_collection_navigation_AsEnumerable_Contains(bool async
return AssertQuery(
async,
ss => ss.Set<Customer>()
.Select(c => c.Orders.AsEnumerable())
.Select(c => c.Orders.OrderBy(o => o.OrderID).AsEnumerable())
.Where(e => e.Contains(order)),
entryCount: 5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1996,14 +1996,17 @@ public override async Task Where_collection_navigation_ToList_Contains(bool asyn
AssertSql(
@"@__entity_equality_order_0_OrderID='10248' (Nullable = true)
SELECT [c].[CustomerID], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate]
SELECT [c].[CustomerID], [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate]
FROM [Customers] AS [c]
LEFT JOIN [Orders] AS [o0] ON [c].[CustomerID] = [o0].[CustomerID]
LEFT JOIN (
SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate]
FROM [Orders] AS [o0]
) AS [t] ON [c].[CustomerID] = [t].[CustomerID]
WHERE EXISTS (
SELECT 1
FROM [Orders] AS [o]
WHERE ([c].[CustomerID] = [o].[CustomerID]) AND ([o].[OrderID] = @__entity_equality_order_0_OrderID))
ORDER BY [c].[CustomerID]");
ORDER BY [c].[CustomerID], [t].[OrderID]");
}

public override async Task Where_collection_navigation_ToArray_Count(bool async)
Expand All @@ -2028,14 +2031,17 @@ public override async Task Where_collection_navigation_ToArray_Contains(bool asy
AssertSql(
@"@__entity_equality_order_0_OrderID='10248' (Nullable = true)
SELECT [c].[CustomerID], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate]
SELECT [c].[CustomerID], [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate]
FROM [Customers] AS [c]
LEFT JOIN [Orders] AS [o0] ON [c].[CustomerID] = [o0].[CustomerID]
LEFT JOIN (
SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate]
FROM [Orders] AS [o0]
) AS [t] ON [c].[CustomerID] = [t].[CustomerID]
WHERE EXISTS (
SELECT 1
FROM [Orders] AS [o]
WHERE ([c].[CustomerID] = [o].[CustomerID]) AND ([o].[OrderID] = @__entity_equality_order_0_OrderID))
ORDER BY [c].[CustomerID]");
ORDER BY [c].[CustomerID], [t].[OrderID]");
}

public override async Task Where_collection_navigation_AsEnumerable_Count(bool async)
Expand All @@ -2060,14 +2066,17 @@ public override async Task Where_collection_navigation_AsEnumerable_Contains(boo
AssertSql(
@"@__entity_equality_order_0_OrderID='10248' (Nullable = true)
SELECT [c].[CustomerID], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate]
SELECT [c].[CustomerID], [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate]
FROM [Customers] AS [c]
LEFT JOIN [Orders] AS [o0] ON [c].[CustomerID] = [o0].[CustomerID]
LEFT JOIN (
SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate]
FROM [Orders] AS [o0]
) AS [t] ON [c].[CustomerID] = [t].[CustomerID]
WHERE EXISTS (
SELECT 1
FROM [Orders] AS [o]
WHERE ([c].[CustomerID] = [o].[CustomerID]) AND ([o].[OrderID] = @__entity_equality_order_0_OrderID))
ORDER BY [c].[CustomerID]");
ORDER BY [c].[CustomerID], [t].[OrderID]");
}

public override async Task Where_collection_navigation_ToList_Count_member(bool async)
Expand Down

0 comments on commit 87bc08d

Please sign in to comment.