I'm trying to create unit tests for the database repository class using the InMemory Sqlite database. I have one of the entities with the Concurrency Tokens column named xmin
.
This column configured in DbContext this way:
And then I'm trying to setup in memory context for unit tests:
In TestDataBuilder I've filled this column with some value. Here's an error I'm getting:
After a year I've got the same issue again and was able to find a solution.
For setting up in-memory DB I've created a new DB Context derived from original one and override settings for xmin field:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<PgIdentity>().Property(i => i.xmin).HasDefaultValue((uint)DateTime.UtcNow.Ticks);
}
This way I can override some DB settings that we don't need (or not support) in InMemory database.
Hope it will be helpful for someone.