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.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 MyProject
                        {
                            internal class Context1 : DbContext
                            {
                            }

                            internal class Context2 : 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 build = source.Build();
                using (var executor = new ExecutorWrapper(targetDir, build.TargetName + ".dll", targetDir, "MyProject"))
                {
                    var migrations = executor.GetMigrations("Context1");

                    Assert.Equal(1, migrations.Count());
                }
            }
        }
示例#2
0
        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());
                }
            }
        }