コード例 #1
0
        public void TestSqlServerTableWithIdentity()
        {
            //arrange
            var schema = new DatabaseSchema(null, SqlType.SqlServer);
            var table = schema.AddTable("Test")
                  .AddColumn<int>("Id").AddIdentity()
                  .AddColumn<string>("Name").AddLength(200)
                  .Table;
            var tableGen = new TableGenerator(table);

            //act
            var ddl = tableGen.Write();

            //assert
            Assert.IsTrue(ddl.Contains("[Id] INT IDENTITY(1,1)  NOT NULL"));
        }
コード例 #2
0
        public void TestSqlServerTableWithSequenceAutoNumber()
        {
            //arrange
            var schema = new DatabaseSchema(null, SqlType.SqlServer);
            var table = schema.AddTable("Test");
            var id = table.AddColumn<int>("Id").AddPrimaryKey();
            id.DefaultValue = "NEXT VALUE FOR [MySequence]";
            id.IsAutoNumber = true; //but id.IdentityDefinition == null
            table.AddColumn<string>("Name").AddLength(200);
            var tableGen = new TableGenerator(table);

            //act
            var ddl = tableGen.Write();

            //assert
            Assert.IsTrue(ddl.Contains("[Id] INT NOT NULL DEFAULT NEXT VALUE FOR [MySequence]"));
        }
コード例 #3
0
        public void TestSqlServerTableWithComputedColumn()
        {
            //arrange
            var schema = new DatabaseSchema(null, SqlType.SqlServer);
            var table = schema.AddTable("AllTypes")
                  .AddColumn<int>("Id").AddIdentity()
                  .AddColumn<string>("Name").AddLength(200)
                  .AddColumn<int>("Age")
                  .AddColumn<int>("Period")
                  .Table;
            table.AddColumn<int>("ComputedAge").ComputedDefinition = "(Age - Period)";
            var tableGen = new TableGenerator(table);

            //act
            var ddl = tableGen.Write();

            //assert
            Assert.IsTrue(ddl.Contains("[ComputedAge] AS (Age - Period)"));
        }
コード例 #4
0
        public void TestAccessDateCheckConstraint()
        {
            //arrange
            var table = new DatabaseTable {Name = "Orders"};

            var check = new DatabaseConstraint
                            {
                                ConstraintType = ConstraintType.Check,
                                Expression = ">Date()",
                                Name = "[Orders].[OrderDate].ValidationRule"
                            };

            table.AddConstraint(check);

            var writer = new TableGenerator(table);

            //act
            var txt = writer.Write();

            //assert
            Assert.IsTrue(txt.Contains("ALTER TABLE [Orders] ADD CONSTRAINT [Orders_OrderDate_ValidationRule] CHECK ([Orders].[OrderDate] >getdate());"));
        }
コード例 #5
0
        public void TestSqlServerTableWithDescription()
        {
            //arrange
            var schema = new DatabaseSchema(null, SqlType.SqlServer);
            var table = schema.AddTable("Test");
            var id = table.AddColumn<int>("Id").AddPrimaryKey();
            id.Description = "This is the primary key";
            table.AddColumn<string>("Name").AddLength(200);
            var tableGen = new TableGenerator(table);

            //act
            var ddl = tableGen.Write();

            //assert
            Assert.IsTrue(ddl.Contains("EXEC sys.sp_addextendedproperty"));
            Assert.IsTrue(ddl.Contains("'This is the primary key'"));
        }