Exemple #1
0
        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 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());
                }
            }
        }
Exemple #3
0
        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 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());
                }
            }
        }