dotnet / dotnet/efcore

Cosmos: OwnedQueryCosmosTest seed null collection instead of an empty list

Open
#34,011 0 comments 0 reactions 0 assignees View on GitHub
area-cosmos area-migrations-seeding area-test
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

OwnedQueryTestBase has some test data that includes empty collections of owned entity types:

```c#
var order2 = new Order
{
Id = -11,
Client = ownedPerson1,
["OrderDate"] = Convert.ToDateTime("2015-03-03 04:37:59"),
Details = []
};
```

Interestingly, the Cosmos implementation (OwnedQueryCosmosTest) doesn't use the test data, but rather uses HasData() to seed the test data:

```c#
ob.OwnsMany(
e => e.Details, odb =>
{
odb.HasData(
new
{
Id = -100,
OrderId = -10,
OrderClientId = 1,
Detail = "Discounted Order"
},
```

This means that the test data is duplicated and can diverge, which isn't great. But regardless, for orders which have no Details, the JSON document in the database ends up with a null collection, rather than an empty one. As a result, tests such as Where_owned_collection_navigation_ToList_Count fail, since they check for a list length of zero.

Note that this is probably not just a test problem - it may be impossible to use HasData() to seed empty collections of entity types at the moment.

/cc @AndriySvyryd (not critical)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.