|
|
|
|
|
using System;
|
|
|
|
|
|
using EntityFramework.Jet.FunctionalTests.TestUtilities;
|
|
|
|
|
|
using EntityFrameworkCore.Jet;
|
|
|
|
|
|
using Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore.TestModels.ConcurrencyModel;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
|
|
namespace EntityFramework.Jet.FunctionalTests
|
|
|
|
|
|
{
|
|
|
|
|
|
public class F1JetFixture : F1RelationalFixture<JetTestStore>
|
|
|
|
|
|
{
|
|
|
|
|
|
public static readonly string DatabaseName = "OptimisticConcurrencyTest";
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly string _connectionString = JetTestStore.CreateConnectionString(DatabaseName);
|
|
|
|
|
|
|
|
|
|
|
|
public TestSqlLoggerFactory TestSqlLoggerFactory { get; } = new TestSqlLoggerFactory();
|
|
|
|
|
|
|
|
|
|
|
|
public F1JetFixture()
|
|
|
|
|
|
{
|
|
|
|
|
|
_serviceProvider = new ServiceCollection()
|
|
|
|
|
|
.AddEntityFrameworkJet()
|
|
|
|
|
|
.AddSingleton(TestModelSource.GetFactory(OnModelCreating))
|
|
|
|
|
|
.AddSingleton<ILoggerFactory>(TestSqlLoggerFactory)
|
|
|
|
|
|
.BuildServiceProvider();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override JetTestStore CreateTestStore()
|
|
|
|
|
|
{
|
|
|
|
|
|
return JetTestStore.GetOrCreateShared(DatabaseName, () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var optionsBuilder = new DbContextOptionsBuilder()
|
|
|
|
|
|
.UseJet(_connectionString, b => b.ApplyConfiguration())
|
|
|
|
|
|
.UseInternalServiceProvider(_serviceProvider);
|
|
|
|
|
|
|
|
|
|
|
|
using (var context = new F1Context(optionsBuilder.Options))
|
|
|
|
|
|
{
|
|
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
|
|
ConcurrencyModelInitializer.Seed(context);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override F1Context CreateContext(JetTestStore testStore)
|
|
|
|
|
|
{
|
|
|
|
|
|
var optionsBuilder = new DbContextOptionsBuilder()
|
|
|
|
|
|
.UseJet(testStore.Connection, b => b.ApplyConfiguration())
|
|
|
|
|
|
.UseInternalServiceProvider(_serviceProvider);
|
|
|
|
|
|
|
|
|
|
|
|
var context = new F1Context(optionsBuilder.Options);
|
|
|
|
|
|
context.Database.UseTransaction(testStore.Transaction);
|
|
|
|
|
|
return context;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Chassis>().Property<byte[]>("Version").IsRowVersion();
|
|
|
|
|
|
modelBuilder.Entity<Driver>().Property<byte[]>("Version").IsRowVersion();
|
|
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Team>().Property<byte[]>("Version")
|
|
|
|
|
|
.ValueGeneratedOnAddOrUpdate()
|
|
|
|
|
|
.IsConcurrencyToken();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|