Пример #1
0
        public void WhenCreateTableWithNamedPrimaryKey_GetCorrespondingTableScript()
        {
            var table = new List<IDbChange>().AddNewTable<TestTable>();
            table.AddColumn(m => m.Key1).PrimaryKey("PrimaryKeyForTestTables");
            table.AddColumn(m => m.Key2).PrimaryKey("PrimaryKeyForTestTables");

            var createScript = table.GetUpScript().Single();

            Assert.Equal("CREATE TABLE TestTables\r\n(\r\nKey1 int NOT NULL,\r\nKey2 int NOT NULL,\r\nCONSTRAINT PrimaryKeyForTestTables PRIMARY KEY (Key1,Key2)\r\n)", createScript);
        }
Пример #2
0
        public void WhenCreateTableWithNotNullAndTwoColumnsAsPrimaryKey_GetCorrespondingTableScript()
        {
            var table = new List<IDbChange>().AddNewTable<TestTable>();
            table.AddColumn(m => m.MyIdColumn1).PrimaryKey();
            table.AddColumn(m => m.MyIdColumn2).PrimaryKey();
            table.AddColumn(m => m.MyValue, 100);

            var createScript = table.GetUpScript().Single();

            Assert.Equal("CREATE TABLE TestTables\r\n(\r\nMyIdColumn1 int NOT NULL,\r\nMyIdColumn2 int NOT NULL,\r\nMyValue nvarchar(100) NOT NULL,\r\nCONSTRAINT PK_TestTables PRIMARY KEY (MyIdColumn2,MyIdColumn1)\r\n)", createScript);
        }
Пример #3
0
        public void WhenCreateTableWithNamedUniquesAndOneUniqueColumn_GetCorrespondingTableScript()
        {
            var table = new List<IDbChange>().AddNewTable<TestTable>();
            table.AddColumn(m => m.Col1).Unique("PrimaryKeyForTestTables");
            table.AddColumn(m => m.Col2).Unique("PrimaryKeyForTestTables");
            table.AddColumn(m => m.Col3).Unique();

            var createScript = table.GetUpScript().Single();

            Assert.Equal("CREATE TABLE TestTables\r\n(\r\nCol1 int NOT NULL,\r\nCol2 int NOT NULL,\r\nCol3 int NOT NULL UNIQUE,\r\nCONSTRAINT PrimaryKeyForTestTables UNIQUE (Col1,Col2)\r\n)", createScript);
        }
Пример #4
0
        public void WhenCreateTableWithAutoIncrementAndPrimaryKey_GetCorrespondingTableScript()
        {
            var table = new List<IDbChange>().AddNewTable<TestTable>();

            table.AddColumn(m => m.MyIdColumn).AutoIncrement().PrimaryKey();
            table.AddColumn(m => m.MyValue ,100);

            var createScript = table.GetUpScript().Single();

            Assert.Equal("CREATE TABLE TestTables\r\n(\r\nMyIdColumn int IDENTITY(1,1) PRIMARY KEY,\r\nMyValue nvarchar(100) NOT NULL\r\n)", createScript);
        }
Пример #5
0
        public void WhenColumnWithNotNull_GetCorrespondingTableScript()
        {
            var table = new List<IDbChange>().AddNewTable<TestTable>();

            table.AddColumn(m => m.MyColumn).NotNull();

            var createScript = table.GetUpScript().Single();

            Assert.Equal("CREATE TABLE TestTables\r\n(\r\nMyColumn int NOT NULL\r\n)", createScript);
        }
Пример #6
0
        public void WhenNullableInt_GetCorrespondingTableScript()
        {
            var table = new List<IDbChange>().AddNewTable<NullableIntTestTable>();

            table.AddColumn(m => m.MyNullableInt);

            var createScript = table.GetUpScript().Single();

            Assert.Equal("CREATE TABLE NullableIntTestTables\r\n(\r\nMyNullableInt int\r\n)", createScript);
        }
Пример #7
0
        public void WhenGuid_GetCorrespondingTableScript()
        {
            var table = new List<IDbChange>().AddNewTable<GuidTestTable>();

            table.AddColumn(m => m.MyUniqueIdentifier);

            var createScript = table.GetUpScript().Single();

            Assert.Equal("CREATE TABLE GuidTestTables\r\n(\r\nMyUniqueIdentifier uniqueidentifier NOT NULL\r\n)", createScript);
        }