You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
EntityFrameworkCore.Jet/test/EFCore.Jet.Tests/TestBase.cs

43 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities;
using EntityFrameworkCore.Jet.Infrastructure;
using Microsoft.EntityFrameworkCore;
namespace EntityFrameworkCore.Jet
{
public class TestBase<TContext> : IDisposable
where TContext : ContextBase, new()
{
public TestBase()
{
TestStore = JetTestStore.CreateInitialized(StoreName);
}
public virtual void Dispose() => TestStore.Dispose();
public virtual string StoreName => GetType().Name;
public virtual JetTestStore TestStore { get; }
public virtual List<string> SqlCommands { get; } = new List<string>();
public virtual string Sql => string.Join("\n\n", SqlCommands);
public virtual TContext CreateContext(
Action<JetDbContextOptionsBuilder> jetOptions = null,
Action<IServiceProvider, DbContextOptionsBuilder> options = null,
Action<ModelBuilder> model = null)
{
var context = new TContext();
context.Initialize(
TestStore.Name,
command => SqlCommands.Add(command.CommandText),
model: model,
options: options,
jetOptions: jetOptions);
TestStore.Clean(context);
return context;
}
}
}