You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does Audit.EntityFramework not work with in-memory database? I need it for testing. I am using EF Core with xUnit.
I have a context factory like so:
public class DatabaseContextFactory
{
public DatabaseContext Create()
{
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();
var builder = new DbContextOptionsBuilder<DatabaseContext>();
builder.UseInMemoryDatabase()
.UseInternalServiceProvider(serviceProvider);
return new DatabaseContext(builder.Options);
}
}
Where my DatabaseContext inherits from AuditDbContext:
public sealed class DatabaseContext : AuditDbContext
{
public DatabaseContext(DbContextOptions options)
: base(options)
{
}
}
I get this error when running tests:
System.IndexOutOfRangeException : Index was outside the bounds of the array.
Stack Trace:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Audit.EntityFramework.DbContextHelper.EnsureEntitiesIncludeIgnoreAttrCache(Type type)
at Audit.EntityFramework.DbContextHelper.IncludeEntity(IAuditDbContext context, EntityEntry entry, AuditOptionMode mode)
at Audit.EntityFramework.DbContextHelper.<>c__DisplayClass19_0.<GetModifiedEntries>b__0(EntityEntry x)
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Audit.EntityFramework.DbContextHelper.GetModifiedEntries(IAuditDbContext context)
at Audit.EntityFramework.DbContextHelper.CreateAuditEvent(IAuditDbContext context)
at Audit.EntityFramework.DbContextHelper.SaveChanges(IAuditDbContext context, Func`1 baseSaveChanges)
at Audit.EntityFramework.AuditDbContext.SaveChanges()
The text was updated successfully, but these errors were encountered:
I was unable to reproduce. I've tested using an in-memory database and performing insert/update operations with no problems.
Anyway, from the error I can imply that the static cache for the audit attributes is having problems with multiple threads trying to add the same value at the same time.
Will look into converting the cache to a thread-safe structure.
Does
Audit.EntityFramework
not work with in-memory database? I need it for testing. I am using EF Core with xUnit.I have a context factory like so:
Where my
DatabaseContext
inherits fromAuditDbContext
:I get this error when running tests:
The text was updated successfully, but these errors were encountered: