Is asserting the DbSet via Nunit query the database if there is no query called on the DbSet in the Assert explicitly

Viewed 20

I am looking to speed up our unit tests.

In many cases during DELETE DB access unit tests, we Assert in the following manner:

Assert.That(myDbSet, Has.Exactly(0).Items);
Assert.That(!(await myDbSet.AnyAsync(x => x.Foo == myEntityInstance.Foo).ConfigureAwait(false)));

I was wondering if it is really needed to call the 2. Assert, as the first one should check if there are any records left in the database, thus according to my logic if the 1. Assert doesn't fail, then the 2. one should not be needed. (If there are no records in the table, there should of course be no records with given property Foo).

However this would only be true, if not calling a query explicitly (like .AnyAsync) actually queries the DB for values, not only a local tracking.

So in summary, do I have to call a method querying the DbSet to actually query the DB?

Thanks!

0 Answers
Related