Example #1
0
        public void Clone_replicates_tables()
        {
            var databaseModel = new DatabaseModel();
            var sequence0     = new Sequence("dbo.S0");
            var sequence1     = new Sequence("dbo.S1");
            var table0        = new Table("dbo.T0");
            var table1        = new Table("dbo.T1");

            databaseModel.AddSequence(sequence0);
            databaseModel.AddSequence(sequence1);
            databaseModel.AddTable(table0);
            databaseModel.AddTable(table1);

            var clone = databaseModel.Clone();

            Assert.NotSame(databaseModel, clone);
            Assert.Equal(2, clone.Sequences.Count);
            Assert.NotSame(sequence0, clone.Sequences[0]);
            Assert.NotSame(sequence1, clone.Sequences[1]);
            Assert.Equal("dbo.S0", clone.Sequences[0].Name);
            Assert.Equal("dbo.S1", clone.Sequences[1].Name);
            Assert.Equal(2, clone.Tables.Count);
            Assert.NotSame(table0, clone.Tables[0]);
            Assert.NotSame(table1, clone.Tables[1]);
            Assert.Equal("dbo.T0", clone.Tables[0].Name);
            Assert.Equal("dbo.T1", clone.Tables[1].Name);
        }
Example #2
0
        public void GetSequence_finds_sequence_by_name()
        {
            var database  = new DatabaseModel();
            var sequence0 = new Sequence("dbo.MySequence0");
            var sequence1 = new Sequence("dbo.MySequence1");

            database.AddSequence(sequence0);
            database.AddSequence(sequence1);

            Assert.Same(sequence0, database.GetSequence("dbo.MySequence0"));
            Assert.Same(sequence1, database.GetSequence("dbo.MySequence1"));
        }
Example #3
0
        public void Sequences_gets_read_only_list_of_sequences()
        {
            var database  = new DatabaseModel();
            var sequence0 = new Sequence("dbo.MySequence0");
            var sequence1 = new Sequence("dbo.MySequence1");

            database.AddSequence(sequence0);
            database.AddSequence(sequence1);

            Assert.IsAssignableFrom <IReadOnlyList <Sequence> >(database.Sequences);
            Assert.Equal(2, database.Sequences.Count);
            Assert.Same(sequence0, database.Sequences[0]);
            Assert.Same(sequence1, database.Sequences[1]);
        }
Example #4
0
        public void RemoveSequence_removes_specified_sequence()
        {
            var database  = new DatabaseModel();
            var sequence0 = new Sequence("dbo.MySequence0");
            var sequence1 = new Sequence("dbo.MySequence1");

            database.AddSequence(sequence0);
            database.AddSequence(sequence1);

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

            database.RemoveSequence("dbo.MySequence1");

            Assert.Equal(1, database.Sequences.Count);
            Assert.Same(sequence0, database.Sequences[0]);
        }
Example #5
0
        private void BuildSequence([NotNull] IProperty property, [NotNull] DatabaseModel database)
        {
            Check.NotNull(property, "property");
            Check.NotNull(database, "database");

            var sequence = BuildSequence(property);

            if (sequence == null)
            {
                return;
            }

            var existingSequence = database.TryGetSequence(sequence.Name);

            if (existingSequence == null)
            {
                database.AddSequence(sequence);
                return;
            }

            if (!string.Equals(sequence.DataType, existingSequence.DataType, StringComparison.OrdinalIgnoreCase) ||
                sequence.StartWith != existingSequence.StartWith ||
                sequence.IncrementBy != existingSequence.IncrementBy)
            {
                throw new InvalidOperationException(Strings.FormatSequenceDefinitionMismatch(sequence.Name));
            }
        }
        public void Visit_with_rename_sequence_operation()
        {
            var model     = new DatabaseModel();
            var operation = new RenameSequenceOperation("dbo.MySequence", "RenamedSequence");

            model.AddSequence(new Sequence("dbo.MySequence", "bigint", 0, 1));
            operation.Accept(new DatabaseModelModifier(), model);

            Assert.Equal(1, model.Sequences.Count);
            Assert.Equal("dbo.RenamedSequence", model.Sequences[0].Name);
        }
Example #7
0
        public void AddSequence_adds_specified_sequence()
        {
            var database = new DatabaseModel();

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

            var sequence = new Sequence("dbo.MySequence");

            database.AddSequence(sequence);

            Assert.Equal(1, database.Sequences.Count);
            Assert.Same(sequence, database.Sequences[0]);
        }
Example #8
0
        public void Visit_with_drop_sequence_operation()
        {
            var model     = new DatabaseModel();
            var operation = new DropSequenceOperation("dbo.MySequence");

            model.AddSequence(new Sequence("dbo.MySequence"));

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

            operation.Accept(new DatabaseModelModifier(), model);

            Assert.Equal(0, model.Sequences.Count);
        }
        public void Visit_with_alter_sequence_operation()
        {
            var model     = new DatabaseModel();
            var operation = new AlterSequenceOperation("dbo.MySequence", 7);

            model.AddSequence(new Sequence("dbo.MySequence", "bigint", 0, 6));
            operation.Accept(new DatabaseModelModifier(), model);

            Assert.Equal(1, model.Sequences.Count);
            Assert.Equal("dbo.MySequence", model.Sequences[0].Name);
            Assert.Equal("bigint", model.Sequences[0].DataType);
            Assert.Equal(0, model.Sequences[0].StartWith);
            Assert.Equal(7, model.Sequences[0].IncrementBy);
        }