Exemplo n.º 1
0
        public void CreateMigration_with_default_migration_directory()
        {
            var tool          = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
            {
                "--MigrationName=MyMigration",
                "--ContextAssembly=EntityFramework.Design.Tests.dll",
                "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext",
                "--MigrationAssembly=EntityFramework.Design.Tests.dll",
                "--MigrationNamespace=MyNamespace"
            });

            var scaffoldedMigration = tool.CreateMigration(configuration);

            Assert.Equal("MyNamespace", scaffoldedMigration.MigrationNamespace);
            Assert.Equal("MyMigration", scaffoldedMigration.MigrationClass);
            Assert.Equal("MyContextModelSnapshot", scaffoldedMigration.SnapshotModelClass);
            Assert.True(scaffoldedMigration.MigrationFile.EndsWith("MyMigration.cs"));
            Assert.True(scaffoldedMigration.MigrationMetadataFile.EndsWith("MyMigration.Designer.cs"));
            Assert.True(scaffoldedMigration.SnapshotModelFile.EndsWith("MyContextModelSnapshot.cs"));
            Assert.True(Path.IsPathRooted(scaffoldedMigration.MigrationFile));
            Assert.True(Path.IsPathRooted(scaffoldedMigration.MigrationMetadataFile));
            Assert.True(Path.IsPathRooted(scaffoldedMigration.SnapshotModelFile));
        }
Exemplo n.º 2
0
        public void CreateMigration()
        {
            var tool          = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
            {
                "--MigrationName=MyMigration",
                "--ContextAssembly=EntityFramework.Design.Tests.dll",
                "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext",
                "--MigrationAssembly=EntityFramework.Design.Tests.dll",
                "--MigrationNamespace=MyNamespace",
                "--MigrationDirectory=C:\\MyDirectory"
            });

            var scaffoldedMigration = tool.CreateMigration(configuration);

            Assert.Equal("MyNamespace", scaffoldedMigration.MigrationNamespace);
            Assert.Equal("MyMigration", scaffoldedMigration.MigrationClass);
            Assert.Equal("MyContextModelSnapshot", scaffoldedMigration.SnapshotModelClass);
            Assert.Equal("C:\\MyDirectory\\MyMigration.cs", scaffoldedMigration.MigrationFile);
            Assert.Equal("C:\\MyDirectory\\MyMigration.Designer.cs", scaffoldedMigration.MigrationMetadataFile);
            Assert.Equal("C:\\MyDirectory\\MyContextModelSnapshot.cs", scaffoldedMigration.SnapshotModelFile);
        }
Exemplo n.º 3
0
        public void LoadContext_throws_if_context_assembly_not_specified()
        {
            var tool          = new MyMigrationTool();
            var configuration = new Configuration();

            Assert.Equal(
                Strings.ContextAssemblyNotSpecified,
                Assert.Throws <InvalidOperationException>(() => tool.LoadContext(configuration)).Message);
        }
Exemplo n.º 4
0
        public void CreateMigration_throws_if_migration_name_not_specified()
        {
            var tool          = new MyMigrationTool();
            var configuration = new Configuration();

            Assert.Equal(
                Strings.MigrationNameNotSpecified,
                Assert.Throws <InvalidOperationException>(() => tool.CreateMigration(configuration)).Message);
        }
Exemplo n.º 5
0
        public void LoadContext_throws_if_context_type_not_specified_and_multiple_DbContext_found_in_assembly()
        {
            var tool          = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
            {
                "--ContextAssembly=EntityFramework.Design.Tests.dll"
            });

            Assert.Equal(
                Strings.FormatAssemblyContainsMultipleDbContext(Assembly.GetExecutingAssembly().FullName),
                Assert.Throws <InvalidOperationException>(() => tool.LoadContext(configuration)).Message);
        }
Exemplo n.º 6
0
        public void LoadContext_throws_if_context_type_is_not_DbContext()
        {
            var tool          = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
            {
                "--ContextAssembly=EntityFramework.Design.Tests.dll",
                "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+NotAContext"
            });

            Assert.Equal(
                Strings.FormatTypeIsNotDbContext("Microsoft.Data.Entity.Design.Tests.MigrationToolTest+NotAContext"),
                Assert.Throws <InvalidOperationException>(() => tool.LoadContext(configuration)).Message);
        }
Exemplo n.º 7
0
        public void GetMigrations_throws_if_invalid_source()
        {
            var tool          = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
            {
                "--ContextAssembly=EntityFramework.Design.Tests.dll",
                "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext",
                "--MigrationSource=Foo"
            });

            Assert.Equal(
                Strings.InvalidMigrationSource,
                Assert.Throws <InvalidOperationException>(() => tool.GetMigrations(configuration)).Message);
        }
Exemplo n.º 8
0
        public void LoadContext_throws_if_context_type_not_found()
        {
            var tool          = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
            {
                "--ContextAssembly=EntityFramework.Design.Tests.dll",
                "--ContextType=Microsoft.Data.Entity.Design.Tests.Vuvuzelas"
            });

            Assert.Equal(
                Strings.FormatAssemblyDoesNotContainType(
                    Assembly.GetExecutingAssembly().FullName,
                    "Microsoft.Data.Entity.Design.Tests.Vuvuzelas"),
                Assert.Throws <InvalidOperationException>(() => tool.LoadContext(configuration)).Message);
        }
Exemplo n.º 9
0
        public void LoadContext_throws_if_context_type_not_specified_and_multiple_DbContext_found_in_assembly()
        {
            var tool = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
                    {
                        "--ContextAssembly=EntityFramework.Design.Tests.dll"
                    });

            Assert.Equal(
                Strings.FormatAssemblyContainsMultipleDbContext(Assembly.GetExecutingAssembly().FullName),
                Assert.Throws<InvalidOperationException>(() => tool.LoadContext(configuration)).Message);
        }
Exemplo n.º 10
0
        public void LoadContext_throws_if_context_type_not_found()
        {
            var tool = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
                    {
                        "--ContextAssembly=EntityFramework.Design.Tests.dll", 
                        "--ContextType=Microsoft.Data.Entity.Design.Tests.Vuvuzelas"
                    });

            Assert.Equal(
                Strings.FormatAssemblyDoesNotContainType(
                    Assembly.GetExecutingAssembly().FullName,
                    "Microsoft.Data.Entity.Design.Tests.Vuvuzelas"),
                Assert.Throws<InvalidOperationException>(() => tool.LoadContext(configuration)).Message);
        }
Exemplo n.º 11
0
        public void LoadContext_throws_if_context_type_is_not_DbContext()
        {
            var tool = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
                    {
                        "--ContextAssembly=EntityFramework.Design.Tests.dll", 
                        "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+NotAContext"
                    });

            Assert.Equal(
                Strings.FormatTypeIsNotDbContext("Microsoft.Data.Entity.Design.Tests.MigrationToolTest+NotAContext"),
                Assert.Throws<InvalidOperationException>(() => tool.LoadContext(configuration)).Message);
        }
Exemplo n.º 12
0
        public void LoadContext_throws_if_context_assembly_not_specified()
        {
            var tool = new MyMigrationTool();
            var configuration = new Configuration();

            Assert.Equal(
                Strings.ContextAssemblyNotSpecified,
                Assert.Throws<InvalidOperationException>(() => tool.LoadContext(configuration)).Message);
        }
Exemplo n.º 13
0
        public void GetMigrations_throws_if_invalid_source()
        {
            var tool = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
                    {
                        "--ContextAssembly=EntityFramework.Design.Tests.dll", 
                        "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext", 
                        "--MigrationSource=Foo"
                    });

            Assert.Equal(
                Strings.InvalidMigrationSource,
                Assert.Throws<InvalidOperationException>(() => tool.GetMigrations(configuration)).Message);
        }
Exemplo n.º 14
0
        public void CreateMigration_throws_if_migration_name_not_specified()
        {
            var tool = new MyMigrationTool();
            var configuration = new Configuration();

            Assert.Equal(
                Strings.MigrationNameNotSpecified,
                Assert.Throws<InvalidOperationException>(() => tool.CreateMigration(configuration)).Message);
        }
Exemplo n.º 15
0
        public void CreateMigration_with_default_migration_directory()
        {
            var tool = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
                    {
                        "--MigrationName=MyMigration", 
                        "--ContextAssembly=EntityFramework.Design.Tests.dll", 
                        "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext", 
                        "--MigrationAssembly=EntityFramework.Design.Tests.dll", 
                        "--MigrationNamespace=MyNamespace"
                    });

            var scaffoldedMigration = tool.CreateMigration(configuration);

            Assert.Equal("MyNamespace", scaffoldedMigration.MigrationNamespace);
            Assert.Equal("MyMigration", scaffoldedMigration.MigrationClass);
            Assert.Equal("MyContextModelSnapshot", scaffoldedMigration.SnapshotModelClass);
            Assert.True(scaffoldedMigration.MigrationFile.EndsWith("MyMigration.cs"));
            Assert.True(scaffoldedMigration.MigrationMetadataFile.EndsWith("MyMigration.Designer.cs"));
            Assert.True(scaffoldedMigration.SnapshotModelFile.EndsWith("MyContextModelSnapshot.cs"));
            Assert.True(Path.IsPathRooted(scaffoldedMigration.MigrationFile));
            Assert.True(Path.IsPathRooted(scaffoldedMigration.MigrationMetadataFile));
            Assert.True(Path.IsPathRooted(scaffoldedMigration.SnapshotModelFile));
        }
Exemplo n.º 16
0
        public void CreateMigration()
        {
            var tool = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
                    {
                        "--MigrationName=MyMigration", 
                        "--ContextAssembly=EntityFramework.Design.Tests.dll", 
                        "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext", 
                        "--MigrationAssembly=EntityFramework.Design.Tests.dll", 
                        "--MigrationNamespace=MyNamespace", 
                        "--MigrationDirectory=C:\\MyDirectory"
                    });

            var scaffoldedMigration = tool.CreateMigration(configuration);

            Assert.Equal("MyNamespace", scaffoldedMigration.MigrationNamespace);
            Assert.Equal("MyMigration", scaffoldedMigration.MigrationClass);
            Assert.Equal("MyContextModelSnapshot", scaffoldedMigration.SnapshotModelClass);
            Assert.Equal("C:\\MyDirectory\\MyMigration.cs", scaffoldedMigration.MigrationFile);
            Assert.Equal("C:\\MyDirectory\\MyMigration.Designer.cs", scaffoldedMigration.MigrationMetadataFile);
            Assert.Equal("C:\\MyDirectory\\MyContextModelSnapshot.cs", scaffoldedMigration.SnapshotModelFile);
        }