public void AddTable_adds_specified_table()
        {
            var database = new DatabaseModel();

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

            var table = new Table("dbo.MyTable");
            database.AddTable(table);

            Assert.Equal(1, database.Tables.Count);
            Assert.Same(table, database.Tables[0]);
        }
        public void Tables_gets_read_only_list_of_tables()
        {
            var database = new DatabaseModel();
            var table0 = new Table("dbo.MyTable0");
            var table1 = new Table("dbo.MyTable1");

            database.AddTable(table0);
            database.AddTable(table1);

            Assert.IsAssignableFrom<IReadOnlyList<Table>>(database.Tables);
            Assert.Equal(2, database.Tables.Count);
            Assert.Same(table0, database.Tables[0]);
            Assert.Same(table1, database.Tables[1]);
        }
        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);
        }
        public void GetTable_finds_table_by_name()
        {
            var database = new DatabaseModel();
            var table0 = new Table("dbo.MyTable0");
            var table1 = new Table("dbo.MyTable1");

            database.AddTable(table0);
            database.AddTable(table1);

            Assert.Same(table0, database.GetTable("dbo.MyTable0"));
            Assert.Same(table1, database.GetTable("dbo.MyTable1"));
        }
        public void RemoveTable_removes_specified_table()
        {
            var database = new DatabaseModel();
            var table0 = new Table("dbo.MyTable0");
            var table1 = new Table("dbo.MyTable1");

            database.AddTable(table0);
            database.AddTable(table1);

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

            database.RemoveTable("dbo.MyTable1");

            Assert.Equal(1, database.Tables.Count);
            Assert.Same(table0, database.Tables[0]);
        }
        private static Table BuildTable(DatabaseModel database, IEntityType entityType)
        {
            var table = new Table(GetSchemaQualifiedName(entityType));

            database.AddTable(table);

            return table;
        }