Reputation: 179
How to write unit test case for ExecuteUpdateAsync in EF Core 7.0.
For example like GetAll method we can mock as below. Can i mock executeupdateasync method.
repositoryMock.Setup(x => x.GetAll()).Returns(employees)
I have searched for this on stackoverlow for an example but have not got a clue on this.
await context.Blogs.ExecuteUpdateAsync( s => s.SetProperty(b => b.Name, b => b.Name + " Featured!"));
Upvotes: 4
Views: 864
Reputation: 11
The ExecuteUpdateAsync
method doesn't work with the EF Core in-memory provider because it relies on SQL translation to generate and execute SQL UPDATE
statements.
Unit tests often use the EF Core in-memory database provider
The in-memory provider, designed for testing, skips SQL translation and execution, making it incompatible with ExecuteUpdateAsync
.
You need to change approach and instead of mock EF core functionality, use integration tests.
Upvotes: 1