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 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()); } } }