Esempio n. 1
0
        public void Build_creates_sequence_only_named_on_model_with_schema()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder.ForSqlServer().UseSequence("MySequence", "dbOh");

            modelBuilder.Entity("A", b =>
            {
                b.Property <int>("Id").GenerateValuesOnAdd();
                b.Key("Id");
            });
            modelBuilder.Entity("B", b =>
            {
                b.Property <short>("Id").GenerateValuesOnAdd();
                b.Key("Id");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(1, database.Sequences.Count);

            var sequence = database.Sequences[0];

            Assert.Equal("dbOh.MySequence", sequence.Name);
            Assert.Equal("bigint", sequence.DataType);
            Assert.Equal(1, sequence.StartWith);
            Assert.Equal(10, sequence.IncrementBy);
        }
Esempio n. 2
0
        public void Can_use_model_default_and_named_property_specific_sequence_with_schema()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder
            .ForSqlServer(
                b => { b.UseSequence(); })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("S0", "dbOh");
                b.Property <short>("P").ForSqlServer().UseSequence();
                b.Key("Id");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(2, database.Sequences.Count);

            var sequence0 = database.Sequences[0];

            Assert.Equal("dbOh.S0", sequence0.Name);
            Assert.Equal("bigint", sequence0.DataType);
            Assert.Equal(1, sequence0.StartWith);
            Assert.Equal(10, sequence0.IncrementBy);

            var sequence1 = database.Sequences[1];

            Assert.Equal("EntityFrameworkDefaultSequence", sequence1.Name);
            Assert.Equal("bigint", sequence0.DataType);
            Assert.Equal(1, sequence0.StartWith);
            Assert.Equal(10, sequence1.IncrementBy);
        }
Esempio n. 3
0
        public void Build_creates_sequence_defined_on_model_with_defaults()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder.ForSqlServer().UseSequence();

            modelBuilder.Entity("A", b =>
            {
                b.Property <int>("Id").GenerateValuesOnAdd();
                b.Key("Id");
                b.ForSqlServer().Table("T0", "dbo");
            });

            modelBuilder.Entity("B", b =>
            {
                b.Property <short>("Id").GenerateValuesOnAdd();
                b.Key("Id");
                b.ForSqlServer().Table("T1", "dbo");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(1, database.Sequences.Count);

            var sequence = database.Sequences[0];

            Assert.Equal("EntityFrameworkDefaultSequence", sequence.Name);
            Assert.Equal("bigint", sequence.DataType);
            Assert.Equal(1, sequence.StartWith);
            Assert.Equal(10, sequence.IncrementBy);
        }
Esempio n. 4
0
        public void Sequence_specified_on_property_is_shared_if_matches_previous_definition_with_schema()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder
            .ForSqlServer(
                b => { b.Sequence("MySequence", "dbOh").IncrementBy(7); })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("MySequence", "dbOh");
                b.Property <short>("P").ForSqlServer().UseSequence("MySequence", "dbOh");
                b.Key("Id");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(1, database.Sequences.Count);

            var sequence = database.Sequences[0];

            Assert.Equal("dbOh.MySequence", sequence.Name);
            Assert.Equal("bigint", sequence.DataType);
            Assert.Equal(1, sequence.StartWith);
            Assert.Equal(7, sequence.IncrementBy);
        }
Esempio n. 5
0
        public void Build_creates_sequence_specified_on_property_with_schema()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder
            .ForSqlServer(
                b =>
            {
                b.Sequence("S0", "dbOh")
                .IncrementBy(3)
                .Start(1001)
                .Min(1000)
                .Max(2000)
                .Type <int>();

                b.Sequence("S1", "dbOh")
                .IncrementBy(7)
                .Start(7001)
                .Min(7000)
                .Max(9000)
                .Type <short>();
            })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("S0", "dbOh");
                b.Property <short>("P").ForSqlServer().UseSequence("S1", "dbOh");
                b.Key("Id");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(2, database.Sequences.Count);

            var sequence0 = database.Sequences[0];

            Assert.Equal("dbOh.S0", sequence0.Name);
            Assert.Equal("int", sequence0.DataType);
            Assert.Equal(1001, sequence0.StartWith);
            Assert.Equal(3, sequence0.IncrementBy);

            var sequence1 = database.Sequences[1];

            Assert.Equal("dbOh.S1", sequence1.Name);
            Assert.Equal("smallint", sequence1.DataType);
            Assert.Equal(7001, sequence1.StartWith);
            Assert.Equal(7, sequence1.IncrementBy);
        }
Esempio n. 6
0
        public void Sequences_are_matched_if_specified_on_matching_properties_of_fuzzy_matched_entity_types()
        {
            var sourceModelBuilder = new BasicModelBuilder();

            sourceModelBuilder
            .ForSqlServer(
                b => { b.Sequence("S1").IncrementBy(6); })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id");
                b.Property <int>("P1").ForSqlServer().UseSequence("S1");
                b.Key("Id").ForSqlServer().Name("PK");
            });

            var targetModelBuilder = new BasicModelBuilder();

            targetModelBuilder
            .ForSqlServer(
                b => { b.Sequence("S2").IncrementBy(7); })
            .Entity("B",
                    b =>
            {
                b.Property <int>("Id");
                b.Property <int>("P1").ForSqlServer().UseSequence("S2");
                b.Property <string>("P2");
                b.Key("Id").ForSqlServer().Name("PK");
            });

            var operations = new SqlServerModelDiffer(new SqlServerDatabaseBuilder(new SqlServerTypeMapper())).Diff(
                sourceModelBuilder.Model, targetModelBuilder.Model);

            Assert.Equal(4, operations.Count);

            Assert.IsType <RenameSequenceOperation>(operations[0]);
            Assert.IsType <AlterSequenceOperation>(operations[1]);
            Assert.IsType <RenameTableOperation>(operations[2]);
            Assert.IsType <AddColumnOperation>(operations[3]);

            var renameSequenceOperation = (RenameSequenceOperation)operations[0];
            var alterSequenceOperation  = (AlterSequenceOperation)operations[1];

            Assert.Equal("S1", renameSequenceOperation.SequenceName);
            Assert.Equal("S2", renameSequenceOperation.NewSequenceName);
            Assert.Equal("S2", alterSequenceOperation.SequenceName);
            Assert.Equal(7, alterSequenceOperation.NewIncrementBy);
        }
Esempio n. 7
0
        public void Sequences_are_matched_if_specified_on_properties_with_same_name_and_different_column_names()
        {
            var sourceModelBuilder = new BasicModelBuilder();

            sourceModelBuilder
            .ForSqlServer(
                b => { b.Sequence("S1").IncrementBy(6); })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id");
                b.Property <int>("P").ForSqlServer().Column("C1").UseSequence("S1");
                b.Key("Id");
            });

            var targetModelBuilder = new BasicModelBuilder();

            targetModelBuilder
            .ForSqlServer(
                b => { b.Sequence("S2").IncrementBy(7); })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id");
                b.Property <int>("P").ForSqlServer().Column("C2").UseSequence("S2");
                b.Key("Id");
            });

            var operations = new SqlServerModelDiffer(new SqlServerDatabaseBuilder(new SqlServerTypeMapper())).Diff(
                sourceModelBuilder.Model, targetModelBuilder.Model);

            Assert.Equal(3, operations.Count);

            Assert.IsType <RenameSequenceOperation>(operations[0]);
            Assert.IsType <AlterSequenceOperation>(operations[1]);
            Assert.IsType <RenameColumnOperation>(operations[2]);

            var renameSequenceOperation = (RenameSequenceOperation)operations[0];
            var alterSequenceOperation  = (AlterSequenceOperation)operations[1];

            Assert.Equal("S1", renameSequenceOperation.SequenceName);
            Assert.Equal("S2", renameSequenceOperation.NewSequenceName);
            Assert.Equal("S2", alterSequenceOperation.SequenceName);
            Assert.Equal(7, alterSequenceOperation.NewIncrementBy);
        }
Esempio n. 8
0
        public void Can_use_configured_default_and_configured_property_specific_sequence()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder
            .ForSqlServer(
                b =>
            {
                b.Sequence("S0").IncrementBy(3);
                b.Sequence("S1").IncrementBy(7);
                b.UseSequence("S1");
            })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("S0");
                b.Property <short>("P").ForSqlServer().UseSequence();
                b.Key("Id");
            });

            var databaseBuilder = new SqlServerDatabaseBuilder(new SqlServerTypeMapper());
            var database        = databaseBuilder.GetDatabase(modelBuilder.Model);

            Assert.Equal(2, database.Sequences.Count);

            var sequence0 = database.Sequences[0];

            Assert.Equal("S0", sequence0.Name);
            Assert.Equal("bigint", sequence0.DataType);
            Assert.Equal(1, sequence0.StartWith);
            Assert.Equal(3, sequence0.IncrementBy);

            var sequence1 = database.Sequences[1];

            Assert.Equal("S1", sequence1.Name);
            Assert.Equal("bigint", sequence0.DataType);
            Assert.Equal(1, sequence0.StartWith);
            Assert.Equal(7, sequence1.IncrementBy);
        }
Esempio n. 9
0
        public void Diff_finds_altered_sequence()
        {
            var sourceModelBuilder = new BasicModelBuilder();

            sourceModelBuilder
            .ForSqlServer(
                b => { b.Sequence("S", "dbo").IncrementBy(6); })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("S", "dbo");
                b.Key("Id");
            });

            var targetModelBuilder = new BasicModelBuilder();

            targetModelBuilder
            .ForSqlServer(
                b => { b.Sequence("S", "dbo").IncrementBy(7); })
            .Entity("A",
                    b =>
            {
                b.Property <int>("Id").ForSqlServer().UseSequence("S", "dbo");
                b.Key("Id");
            });

            var operations = new SqlServerModelDiffer(new SqlServerDatabaseBuilder(new SqlServerTypeMapper())).Diff(
                sourceModelBuilder.Model, targetModelBuilder.Model);

            Assert.Equal(1, operations.Count);
            Assert.IsType <AlterSequenceOperation>(operations[0]);

            var alterSequenceOperation = (AlterSequenceOperation)operations[0];

            Assert.Equal("dbo.S", alterSequenceOperation.SequenceName);
            Assert.Equal(7, alterSequenceOperation.NewIncrementBy);
        }