public SimpleProject() { var source = new BuildSource { TargetDir = TargetDir, References = { BuildReference.ByName("System.Diagnostics.DiagnosticSource", copyLocal: true), BuildReference.ByName("System.Interactive.Async", copyLocal: true), BuildReference.ByName("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"), BuildReference.ByName("Microsoft.AspNetCore.Hosting.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Tools", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Design.Core", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational.Design", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.SqlServer", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Memory", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Configuration.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.FileProviders.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Options", copyLocal: true), BuildReference.ByName("Remotion.Linq", copyLocal: true) }, Sources = { @" using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace SimpleProject { internal class SimpleContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(""Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=SimpleProject.SimpleContext;Integrated Security=True""); } } namespace Migrations { [DbContext(typeof(SimpleContext))] [Migration(""20141010222726_InitialCreate"")] public class InitialCreate : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } }" } }; var build = source.Build(); Executor = new AppDomainOperationExecutor(TargetDir, build.TargetName, TargetDir, TargetDir, "SimpleProject"); }
public SimpleProject() { var source = new BuildSource { TargetDir = TargetDir, References = { BuildReference.ByName("System.Collections.Immutable", copyLocal: true), BuildReference.ByName("System.Interactive.Async", copyLocal: true), BuildReference.ByName("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"), BuildReference.ByName("EntityFramework.Core", copyLocal: true), BuildReference.ByName("EntityFramework.Commands", copyLocal: true), BuildReference.ByName("EntityFramework.Relational", copyLocal: true), BuildReference.ByName("EntityFramework.Relational.Design", copyLocal: true), BuildReference.ByName("EntityFramework.SqlServer", copyLocal: true), BuildReference.ByName("Microsoft.CodeAnalysis", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Caching.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Caching.Memory", copyLocal: true), BuildReference.ByName("Microsoft.Framework.DependencyInjection", copyLocal: true), BuildReference.ByName("Microsoft.Framework.DependencyInjection.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Logging", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Logging.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Framework.OptionsModel", copyLocal: true), BuildReference.ByName("Remotion.Linq", copyLocal: true) }, Sources = { @" using Microsoft.Data.Entity; using Microsoft.Data.Entity.Infrastructure; using Microsoft.Data.Entity.Migrations; namespace SimpleProject { internal class SimpleContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(""Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=SimpleProject.SimpleContext;Integrated Security=True""); } } namespace Migrations { [DbContext(typeof(SimpleContext))] public class InitialCreate : Migration { public override string Id => ""201410102227260_InitialCreate""; protected override void Up(MigrationBuilder migrationBuilder) { } } } }" } }; var build = source.Build(); Executor = new ExecutorWrapper(TargetDir, build.TargetName + ".dll", TargetDir, "SimpleProject"); }
public void Throws_for_no_parameterless_constructor() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var source = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Diagnostics.DiagnosticSource", copyLocal: true), BuildReference.ByName("System.Interactive.Async", copyLocal: true), BuildReference.ByName("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"), BuildReference.ByName("Microsoft.AspNetCore.Hosting.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Tools", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Tools.Core", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational.Design", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.SqlServer", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Memory", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Configuration.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.FileProviders.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Options", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.PlatformAbstractions", copyLocal: true), BuildReference.ByName("Remotion.Linq", copyLocal: true) }, Sources = { @" using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace MyProject { internal class MyContext : DbContext { public MyContext(DbContextOptions<MyContext> options) :base(options) {} } }" } }; var build = source.Build(); using (var executor = new AppDomainOperationExecutor(targetDir, build.TargetName, targetDir, targetDir, "MyProject")) { var ex = Assert.Throws <OperationException>( () => executor.GetMigrations("MyContext")); Assert.Equal( ToolsCoreStrings.NoParameterlessConstructor("MyContext"), ex.Message); } } }
public void Forwards_to_instances_of_a_different_type() { using (var directory = new TempDirectory()) { var source = new BuildSource { TargetDir = directory.Path, Sources = { @" using System; namespace Microsoft.EntityFrameworkCore.Design.Internal { // NOTE: This interface will have a different identity than the one above internal interface IMagic { int Number { get; } } internal class Magic : MarshalByRefObject, IMagic { public int Number { get { return 7; } } } }" } }; var build = source.Build(); var domain = AppDomain.CreateDomain( "ForwardingProxyTest", null, new AppDomainSetup { ApplicationBase = build.TargetDir }); try { var target = domain.CreateInstanceAndUnwrap( build.TargetName, "Microsoft.EntityFrameworkCore.Design.Internal.Magic"); var forwardingProxy = new ForwardingProxy <IMagic>(target); var transparentProxy = forwardingProxy.GetTransparentProxy(); Assert.Equal(7, transparentProxy.Number); } finally { AppDomain.Unload(domain); } } }
public void Throws_for_no_parameterless_constructor() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var source = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Threading.Tasks.Extensions", true), BuildReference.ByName("Microsoft.EntityFrameworkCore", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Abstractions", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Design", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational", true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection", true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.Logging", true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", true) }, Sources = { @" using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace MyProject { internal class MyContext : DbContext { public MyContext(DbContextOptions<MyContext> options) :base(options) {} } }" } }; var build = source.Build(); using (var executor = CreateExecutorFromBuildResult(build, "MyProject", "C#")) { var ex = Assert.Throws <WrappedException>( () => executor.GetMigrations("MyContext")); Assert.Equal( DesignStrings.NoParameterlessConstructor("MyContext"), ex.Message); } } }
public void AddMigration_begins_new_namespace_when_foreign_migrations() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var source = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Diagnostics.DiagnosticSource", copyLocal: true), BuildReference.ByName("System.Interactive.Async", copyLocal: true), BuildReference.ByName("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"), BuildReference.ByName("Microsoft.AspNetCore.Hosting.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Tools", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Tools.Core", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational.Design", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.SqlServer", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Memory", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Configuration.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.FileProviders.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Options", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.PlatformAbstractions", copyLocal: true), BuildReference.ByName("Remotion.Linq", copyLocal: true) }, Sources = { @" using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace MyProject { internal class MyFirstContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(""Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=MyProject.MyFirstContext""); } } internal class MySecondContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(""Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=MyProject.MySecondContext""); } } namespace Migrations { [DbContext(typeof(MyFirstContext))] [Migration(""20151006140723_InitialCreate"")] public class InitialCreate : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } }" } }; var build = source.Build(); using (var executor = new AppDomainOperationExecutor(targetDir, build.TargetName, targetDir, targetDir, "MyProject")) { var artifacts = executor.AddMigration("MyMigration", /*outputDir:*/ null, "MySecondContext"); Assert.Equal(3, artifacts.Keys.Count); Assert.True(Directory.Exists(Path.Combine(targetDir, @"Migrations\MySecond"))); } } }
public void GetContextType_works_with_multiple_assemblies() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var contextsSource = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("Microsoft.EntityFrameworkCore", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Tools", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Tools.Core", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", copyLocal: true) }, Sources = { @" using Microsoft.EntityFrameworkCore; namespace MyProject { public class Context1 : DbContext { } public class Context2 : DbContext { } }" } }; var contextsBuild = contextsSource.Build(); var migrationsSource = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Reflection.Metadata", copyLocal: true), BuildReference.ByName("Microsoft.AspNetCore.Hosting.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore"), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational.Design", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Configuration.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.FileProviders.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Options", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.PlatformAbstractions", copyLocal: true), BuildReference.ByPath(contextsBuild.TargetPath) }, Sources = { @" using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace MyProject { internal class Context3 : DbContext { } namespace Migrations { namespace Context1Migrations { [DbContext(typeof(Context1))] [Migration(""000000000000000_Context1Migration"")] public class Context1Migration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } namespace Context2Migrations { [DbContext(typeof(Context2))] [Migration(""000000000000000_Context2Migration"")] public class Context2Migration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } } }" } }; var migrationsBuild = migrationsSource.Build(); using (var executor = new AppDomainOperationExecutor(targetDir, migrationsBuild.TargetName, targetDir, targetDir, "MyProject")) { var contextTypes = executor.GetContextTypes(); Assert.Equal(3, contextTypes.Count()); } } }
public void GetMigrations_filters_by_context_name() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var source = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Diagnostics.DiagnosticSource", copyLocal: true), BuildReference.ByName("System.Interactive.Async", copyLocal: true), BuildReference.ByName("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"), BuildReference.ByName("Microsoft.AspNetCore.Hosting.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Tools", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Tools.Core", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational.Design", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.SqlServer", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Memory", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Configuration.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.FileProviders.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Options", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.PlatformAbstractions", copyLocal: true), BuildReference.ByName("Remotion.Linq", copyLocal: true) }, Sources = { @" using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace MyProject { internal class Context1 : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(""Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=SimpleProject.SimpleContext;Integrated Security=True""); } } internal class Context2 : DbContext { } namespace Migrations { namespace Context1Migrations { [DbContext(typeof(Context1))] [Migration(""000000000000000_Context1Migration"")] public class Context1Migration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } namespace Context2Migrations { [DbContext(typeof(Context2))] [Migration(""000000000000000_Context2Migration"")] public class Context2Migration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } } }" } }; var build = source.Build(); using (var executor = new AppDomainOperationExecutor(targetDir, build.TargetName, targetDir, targetDir, "MyProject")) { var migrations = executor.GetMigrations("Context1"); Assert.Equal(1, migrations.Count()); } } }
public void GetContextType_works_with_multiple_assemblies() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var contextsSource = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("Microsoft.EntityFrameworkCore", true) }, Sources = { @" using Microsoft.EntityFrameworkCore; namespace MyProject { public class Context1 : DbContext { } public class Context2 : DbContext { } }" } }; var contextsBuild = contextsSource.Build(); var migrationsSource = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("Microsoft.EntityFrameworkCore"), BuildReference.ByName("Microsoft.EntityFrameworkCore.Design", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational", true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection", true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection.Abstractions",true), BuildReference.ByName("Microsoft.Extensions.Logging", true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", true), BuildReference.ByPath(contextsBuild.TargetPath) }, Sources = { @" using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace MyProject { internal class Context3 : DbContext { } namespace Migrations { namespace Context1Migrations { [DbContext(typeof(Context1))] [Migration(""000000000000000_Context1Migration"")] public class Context1Migration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } namespace Context2Migrations { [DbContext(typeof(Context2))] [Migration(""000000000000000_Context2Migration"")] public class Context2Migration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } } }" } }; var build = migrationsSource.Build(); using (var executor = CreateExecutorFromBuildResult(build, "MyProject")) { var contextTypes = executor.GetContextTypes(); Assert.Equal(3, contextTypes.Count()); } } }
public SimpleProject() { var source = new BuildSource { TargetDir = TargetDir, References = { BuildReference.ByName("System.Collections.Immutable", true), BuildReference.ByName("System.Diagnostics.DiagnosticSource", true), BuildReference.ByName("System.Interactive.Async", true), BuildReference.ByName("System.Data.SqlClient", true), BuildReference.ByName("Microsoft.EntityFrameworkCore", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Abstractions", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Design", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.SqlServer", true), BuildReference.ByName("Microsoft.Extensions.Caching.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.Caching.Memory", true), BuildReference.ByName("Microsoft.Extensions.Configuration.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection", true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.Logging", true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.Options", true), BuildReference.ByName("Microsoft.Extensions.Primitives", true), BuildReference.ByName("Remotion.Linq", true) }, Sources = { @" using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace SimpleProject { internal class SimpleContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(""Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=SimpleProject.SimpleContext;Integrated Security=True""); } } namespace Migrations { [DbContext(typeof(SimpleContext))] [Migration(""20141010222726_InitialCreate"")] public class InitialCreate : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } }" } }; var build = source.Build(); File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, build.TargetPath + ".config"); Executor = new AppDomainOperationExecutor( build.TargetPath, build.TargetPath, build.TargetDir, build.TargetDir, "SimpleProject", "C#"); }
public SimpleProject() { var source = new BuildSource { TargetDir = TargetDir, References = { BuildReference.ByName("System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), BuildReference.ByName("EntityFramework.Core", copyLocal: true), BuildReference.ByName("EntityFramework.Commands", copyLocal: true), BuildReference.ByName("EntityFramework.Migrations", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Logging", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Logging.Interfaces", copyLocal: true) }, Source = @" using System; using Microsoft.Data.Entity; using Microsoft.Data.Entity.Metadata; using Microsoft.Data.Entity.Migrations; using Microsoft.Data.Entity.Migrations.Builders; using Microsoft.Data.Entity.Migrations.Infrastructure; using Microsoft.Data.Entity.Migrations.Model; namespace SimpleProject { internal class SimpleContext : DbContext { } namespace Migrations { [ContextType(typeof(SimpleContext))] public class InitialCreate : Migration, IMigrationMetadata { public string MigrationId { get { return ""201410102227260_InitialCreate""; } } public string ProductVersion { get { throw new NotImplementedException(); } } public IModel TargetModel { get { throw new NotImplementedException(); } } public override void Up(MigrationBuilder migrationBuilder) { } public override void Down(MigrationBuilder migrationBuilder) { } } } } " }; var build = source.Build(); _executor = new ExecutorWrapper(TargetDir, build.TargetName + ".dll", TargetDir, "SimpleProject"); }
public void GetMigrations_filters_by_context_name() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var source = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Diagnostics.DiagnosticSource", true), BuildReference.ByName("System.Interactive.Async", true), BuildReference.ByName("Microsoft.EntityFrameworkCore", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Abstractions", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Design", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.SqlServer", true), BuildReference.ByName("Microsoft.Extensions.Caching.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.Caching.Memory", true), BuildReference.ByName("Microsoft.Extensions.Configuration.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection", true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.Logging", true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.Options", true), BuildReference.ByName("Microsoft.Extensions.Primitives", true), BuildReference.ByName("Remotion.Linq", true) }, Sources = { @" using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace MyProject { internal class Context1 : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(""Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=SimpleProject.SimpleContext;Integrated Security=True""); } } internal class Context2 : DbContext { } namespace Migrations { namespace Context1Migrations { [DbContext(typeof(Context1))] [Migration(""000000000000000_Context1Migration"")] public class Context1Migration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } namespace Context2Migrations { [DbContext(typeof(Context2))] [Migration(""000000000000000_Context2Migration"")] public class Context2Migration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } } }" } }; var build = source.Build(); using (var executor = CreateExecutorFromBuildResult(build, "MyProject", "C#")) { var migrations = executor.GetMigrations("Context1"); Assert.Single(migrations); } } }
public void GetContextType_works_with_multiple_assemblies() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var contextsSource = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("EntityFramework.Core", copyLocal: true), BuildReference.ByName("EntityFramework.Commands", copyLocal: true) }, Sources = { @" using Microsoft.Data.Entity; namespace MyProject { public class Context1 : DbContext { } public class Context2 : DbContext { } }" } }; var contextsBuild = contextsSource.Build(); var migrationsSource = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Collections.Immutable", copyLocal: true), BuildReference.ByName("System.Reflection.Metadata", copyLocal: true), BuildReference.ByName("EntityFramework.Core"), BuildReference.ByName("EntityFramework.Relational", copyLocal: true), BuildReference.ByName("EntityFramework.Relational.Design", copyLocal: true), BuildReference.ByName("Microsoft.CodeAnalysis", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Logging", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Logging.Abstractions", copyLocal: true), BuildReference.ByPath(contextsBuild.TargetPath) }, Sources = { @" using System; using Microsoft.Data.Entity; using Microsoft.Data.Entity.Metadata; using Microsoft.Data.Entity.Migrations; using Microsoft.Data.Entity.Migrations.Builders; using Microsoft.Data.Entity.Migrations.Infrastructure; namespace MyProject { internal class Context3 : DbContext { } namespace Migrations { namespace Context1Migrations { [ContextType(typeof(Context1))] public class Context1Migration : Migration { public override string Id => ""000000000000000_Context1Migration""; public override void Up(MigrationBuilder migrationBuilder) { } public override void Down(MigrationBuilder migrationBuilder) { } } } namespace Context2Migrations { [ContextType(typeof(Context2))] public class Context2Migration : Migration { public override string Id => ""000000000000000_Context2Migration""; public override void Up(MigrationBuilder migrationBuilder) { } public override void Down(MigrationBuilder migrationBuilder) { } } } } }" } }; var migrationsBuild = migrationsSource.Build(); using (var executor = new ExecutorWrapper(targetDir, migrationsBuild.TargetName + ".dll", targetDir, "MyProject")) { var contextTypes = executor.GetContextTypes(); Assert.Equal(3, contextTypes.Count()); } } }
public void GetMigrations_filters_by_context_name() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var source = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Collections.Immutable", copyLocal: true), BuildReference.ByName("System.Interactive.Async", copyLocal: true), BuildReference.ByName("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"), BuildReference.ByName("EntityFramework.Core", copyLocal: true), BuildReference.ByName("EntityFramework.Commands", copyLocal: true), BuildReference.ByName("EntityFramework.Relational", copyLocal: true), BuildReference.ByName("EntityFramework.Relational.Design", copyLocal: true), BuildReference.ByName("EntityFramework.SqlServer", copyLocal: true), BuildReference.ByName("Microsoft.CodeAnalysis", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Caching.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Caching.Memory", copyLocal: true), BuildReference.ByName("Microsoft.Framework.DependencyInjection", copyLocal: true), BuildReference.ByName("Microsoft.Framework.DependencyInjection.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Logging", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Logging.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Framework.OptionsModel", copyLocal: true), BuildReference.ByName("Remotion.Linq", copyLocal: true) }, Sources = { @" using System; using Microsoft.Data.Entity; using Microsoft.Data.Entity.Metadata; using Microsoft.Data.Entity.Migrations; using Microsoft.Data.Entity.Migrations.Builders; using Microsoft.Data.Entity.Migrations.Infrastructure; namespace MyProject { internal class Context1 : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(""Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=SimpleProject.SimpleContext;Integrated Security=True""); } } internal class Context2 : DbContext { } namespace Migrations { namespace Context1Migrations { [ContextType(typeof(Context1))] public class Context1Migration : Migration { public override string Id => ""000000000000000_Context1Migration""; public override void Up(MigrationBuilder migrationBuilder) { } public override void Down(MigrationBuilder migrationBuilder) { } } } namespace Context2Migrations { [ContextType(typeof(Context2))] public class Context2Migration : Migration { public override string Id => ""000000000000000_Context2Migration""; public override void Up(MigrationBuilder migrationBuilder) { } public override void Down(MigrationBuilder migrationBuilder) { } } } } }" } }; var build = source.Build(); using (var executor = new ExecutorWrapper(targetDir, build.TargetName + ".dll", targetDir, "MyProject")) { var migrations = executor.GetMigrations("Context1"); Assert.Equal(1, migrations.Count()); } } }
public void AddMigration_begins_new_namespace_when_foreign_migrations() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var source = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Interactive.Async", true), BuildReference.ByName("Microsoft.EntityFrameworkCore", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Abstractions", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Design", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational", true), BuildReference.ByName("Microsoft.EntityFrameworkCore.SqlServer", true), BuildReference.ByName("Microsoft.Extensions.Caching.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.Caching.Memory", true), BuildReference.ByName("Microsoft.Extensions.Configuration.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection", true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.Logging", true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", true), BuildReference.ByName("Microsoft.Extensions.Options", true), BuildReference.ByName("Microsoft.Extensions.Primitives", true), BuildReference.ByName("Remotion.Linq", true) }, Sources = { @" using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace MyProject { internal class MyFirstContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(""Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=MyProject.MyFirstContext""); } } internal class MySecondContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(""Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=MyProject.MySecondContext""); } } namespace Migrations { [DbContext(typeof(MyFirstContext))] [Migration(""20151006140723_InitialCreate"")] public class InitialCreate : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } }" } }; var build = source.Build(); using (var executor = CreateExecutorFromBuildResult(build, "MyProject", "C#")) { try { var artifacts = executor.AddMigration("MyMigration", /*outputDir:*/ null, "MySecondContext"); Assert.Equal(3, artifacts.Keys.Count); } catch (WrappedException ex) { throw new WrappedXunitException(ex); } Assert.True(Directory.Exists(Path.Combine(targetDir, @"Migrations\MySecond"))); } } }
public void GetContextType_works_with_multiple_assemblies() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var contextsSource = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), BuildReference.ByName("EntityFramework.Core", copyLocal: true), BuildReference.ByName("EntityFramework.Commands", copyLocal: true) }, Source = @" using Microsoft.Data.Entity; namespace MyProject { public class Context1 : DbContext { } public class Context2 : DbContext { } } " }; var contextsBuild = contextsSource.Build(); var migrationsSource = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), BuildReference.ByName("EntityFramework.Core"), BuildReference.ByName("EntityFramework.Migrations", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Logging", copyLocal: true), BuildReference.ByName("Microsoft.Framework.Logging.Interfaces", copyLocal: true), BuildReference.ByPath(contextsBuild.TargetPath) }, Source = @" using System; using Microsoft.Data.Entity; using Microsoft.Data.Entity.Metadata; using Microsoft.Data.Entity.Migrations; using Microsoft.Data.Entity.Migrations.Builders; using Microsoft.Data.Entity.Migrations.Infrastructure; using Microsoft.Data.Entity.Migrations.Model; namespace MyProject { internal class Context3 : DbContext { } namespace Migrations { namespace Context1Migrations { [ContextType(typeof(Context1))] public class Context1Migration : Migration, IMigrationMetadata { public string MigrationId { get { return ""000000000000000_Context1Migration""; } } public string ProductVersion { get { throw new NotImplementedException(); } } public IModel TargetModel { get { throw new NotImplementedException(); } } public override void Up(MigrationBuilder migrationBuilder) { } public override void Down(MigrationBuilder migrationBuilder) { } } } namespace Context2Migrations { [ContextType(typeof(Context2))] public class Context2Migration : Migration, IMigrationMetadata { public string MigrationId { get { return ""000000000000000_Context2Migration""; } } public string ProductVersion { get { throw new NotImplementedException(); } } public IModel TargetModel { get { throw new NotImplementedException(); } } public override void Up(MigrationBuilder migrationBuilder) { } public override void Down(MigrationBuilder migrationBuilder) { } } } } } " }; var migrationsBuild = migrationsSource.Build(); using (var executor = new ExecutorWrapper(targetDir, migrationsBuild.TargetName + ".dll", targetDir, "MyProject")) { var contextTypes = executor.GetContextTypes(); Assert.Equal(3, contextTypes.Count()); } } }
public void GetMigrations_throws_when_target_and_migrations_assemblies_mismatch() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var source = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Diagnostics.DiagnosticSource", copyLocal: true), BuildReference.ByName("System.Interactive.Async", copyLocal: true), BuildReference.ByName("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"), BuildReference.ByName("Microsoft.AspNetCore.Hosting.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Tools", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Tools.Core", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational.Design", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.SqlServer", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Memory", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Configuration.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.FileProviders.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Options", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.PlatformAbstractions", copyLocal: true), BuildReference.ByName("Remotion.Linq", copyLocal: true) }, Sources = { @" using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace MyProject { internal class MyContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder .UseSqlServer( ""Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=MyProject.MyContext;Integrated Security=True"", b => b.MigrationsAssembly(""UnknownAssembly"")); } } namespace Migrations { [DbContext(typeof(MyContext))] [Migration(""20151215152142_MyMigration"")] public class MyMigration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } } }" } }; var build = source.Build(); using (var executor = new AppDomainOperationExecutor(targetDir, build.TargetName, targetDir, targetDir, "MyProject")) { var ex = Assert.Throws <OperationException>( () => executor.GetMigrations("MyContext")); Assert.Equal( ToolsCoreStrings.MigrationsAssemblyMismatch(build.TargetName, "UnknownAssembly"), ex.Message); } } }
public void ScaffoldRuntimeDirectives() { using (var directory = new TempDirectory()) { var targetDir = directory.Path; var source = new BuildSource { TargetDir = targetDir, References = { BuildReference.ByName("System.Diagnostics.DiagnosticSource", copyLocal: true), BuildReference.ByName("System.Interactive.Async", copyLocal: true), BuildReference.ByName("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"), BuildReference.ByName("Microsoft.EntityFrameworkCore", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Commands", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational.Design", copyLocal: true), BuildReference.ByName("Microsoft.EntityFrameworkCore.SqlServer", copyLocal: true), BuildReference.ByName("Microsoft.CodeAnalysis", copyLocal: true), BuildReference.ByName("Microsoft.CodeAnalysis.CSharp", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Caching.Memory", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.DependencyInjection.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Logging.Abstractions", copyLocal: true), BuildReference.ByName("Microsoft.Extensions.Options", copyLocal: true), BuildReference.ByName("Remotion.Linq", copyLocal: true) }, Sources = { @"using System; using Microsoft.EntityFrameworkCore; namespace MyProject { public class MyContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(""Data Source=(localdb)\\mssqllocaldb""); } public DbSet<Post> Posts { get; set; } } public class MySecondContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(""Data Source=(localdb)\\mssqllocaldb""); } public DbSet<Blog> Blogs { get; set; } } public class Blog { public int Id { get; set; } public DateTime Created { get; set; } public string Title { get; set; } } public class Post { public int Id { get; set; } public string Title { get; set; } } }" } }; var build = source.Build(); using (var executor = new OperationExecutorWrapper(targetDir, build.TargetName, targetDir, "MyProject")) { executor.ScaffoldRuntimeDirectives(); var expectedFile = Path.Combine(targetDir, @"Properties\Microsoft.EntityFrameworkCore.g.rd.xml"); Assert.True(File.Exists(expectedFile)); var contents = File.ReadAllText(expectedFile); _output?.WriteLine(contents); // original values snapshot Assert.Contains("<TypeInstantiation Name=\"Microsoft.EntityFrameworkCore.ChangeTracking.Internal.Snapshot\" " + "Arguments=\"System.Int32, System.DateTime, System.String\" " + "Dynamic=\"Required All\" />", contents); } } }