EfCore.TestSupport
EfCore.TestSupport copied to clipboard
Suggestion: Extend EfCoreLogDecoder to decode CommandError as well as CommandExecuted
A small suggestion for this handy little feature.
if (log.EventId.Name != RelationalEventId.CommandError.Name && log.EventId.Name != RelationalEventId.CommandExecuted.Name)
My use case was encountering a foreign key constraint error from sqlite when constructing a test database to run a unit test against - of course sqlite being unable to tell me which constraint I was violating. With a copy of the class with that small change I was able to pull the sql being executed and find what I was doing wrong. Maybe helpful in other situations too?
Hi @MeltedFreddo,
I don't use the EfCoreLogDecoder since the EF Core 5 brought out the ToQueryString method because the EfCoreLogDecoder code isn't perfect. But I see why you are using the logging.
I'll leave this issue open and when I have another change I will update it.
PS. My solution if this problem is to comment out the SQLiite and replace with a SQL Server database to get a better database exception and then undo it afterwards, e.g.
[Fact]
public void TestAddRolesToDatabaseIfEmpty()
{
//SETUP
var options = SqliteInMemory.CreateOptions<AuthPermissionsDbContext>();
//var options = this.CreateUniqueClassOptions<AuthPermissionsDbContext>();
using var context = new AuthPermissionsDbContext(options);
context.Database.EnsureCreated();
//context.Database.EnsureClean();
//... rest of test left out
Hi @MeltedFreddo,
I have added your code to the 5.3.0 release, which supports .NET 7. I didn't check it so let me know if it works.
That's great to hear, thank you very much!