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.
71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
using System;
|
|
using EntityFrameworkCore.Jet;
|
|
using Extensions.DependencyInjection;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Xunit;
|
|
|
|
namespace EntityFramework.Jet.FunctionalTests
|
|
{
|
|
public class JetMigrationsTest
|
|
{
|
|
[Fact]
|
|
public void Empty_Migration_Creates_Database()
|
|
{
|
|
using (var testDatabase = JetTestStore.CreateScratch(createDatabase: false))
|
|
{
|
|
|
|
using (var context = CreateContext(testDatabase))
|
|
{
|
|
context.Database.Migrate();
|
|
|
|
Assert.True(context.GetService<IRelationalDatabaseCreator>().Exists());
|
|
}
|
|
}
|
|
}
|
|
|
|
private static BloggingContext CreateContext(JetTestStore testStore)
|
|
{
|
|
var serviceProvider =
|
|
new ServiceCollection()
|
|
.AddEntityFrameworkJet()
|
|
.BuildServiceProvider();
|
|
|
|
var optionsBuilder = new DbContextOptionsBuilder();
|
|
optionsBuilder
|
|
.UseJet(testStore.Connection.ConnectionString)
|
|
.UseInternalServiceProvider(serviceProvider);
|
|
|
|
return new BloggingContext(serviceProvider, optionsBuilder.Options);
|
|
}
|
|
|
|
private class BloggingContext : DbContext
|
|
{
|
|
public BloggingContext(IServiceProvider serviceProvider, DbContextOptions options)
|
|
: base(options)
|
|
{
|
|
}
|
|
|
|
public DbSet<Blog> Blogs { get; set; }
|
|
|
|
public class Blog
|
|
{
|
|
public int Id { get; set; }
|
|
public string Name { get; set; }
|
|
}
|
|
}
|
|
|
|
[DbContext(typeof(BloggingContext))]
|
|
[Migration("00000000000000_Empty")]
|
|
public class EmptyMigration : Migration
|
|
{
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|