CLSavill
CLSavill

Reputation: 101

Entity Framework DB updating but DB context not showing updates

I have the following setup:

With the following steps leading to my issue:

  1. Before the test I populate the DB with a resource and some claims.
  2. The unit test makes a HTTP DELETE request which results in a claim being deleted. This is visible in the DB as context.SaveChanges() is called.
  3. The unit test then asserts that the claim has been deleted by using the DB context. This fails due to the context not appearing to update.

The issue is that the EF DB context in the unit test appears to not see the deletion of the claim that the API's DB context made.

Things I have tried:

Observations:

Questions:

Many thanks in advance.

Upvotes: 6

Views: 3617

Answers (1)

CLSavill
CLSavill

Reputation: 101

Thanks to both Eric J and DevilSuichiro for helping me resolve my issue. The problem was that I should not have been trying to use the same DB context. By retrieving a new DB context instead of trying to reuse the same DB context I was able to verify my test results.

Many thanks again.

Upvotes: 4

Related Questions