public void RequiredAttribute_sql_generation()
        {
            using (var testDb = new TestDb(SqlVersion.Sql13))
            {
                var command     = testDb.GetCreateTableCommand(testDb.TestTable._, false);
                var expectedSql =
                    @"CREATE TABLE [TestTable] (
    [Id] INT NOT NULL
);
";
                Assert.AreEqual(expectedSql, command.CommandText);
            }
        }
Example #2
0
        public void AutoGuidAttribute_sql_generation()
        {
            using (var testDb = new TestDb(SqlVersion.Sql13))
            {
                var command     = testDb.GetCreateTableCommand(testDb.TestTable._, false);
                var expectedSql =
                    @"CREATE TABLE [TestTable] (
    [Guid] UNIQUEIDENTIFIER NULL DEFAULT(NEWID())
);
";
                Assert.AreEqual(expectedSql, command.CommandText);
            }
        }
Example #3
0
        public void AutoDateTimeAttribute_sql_generation()
        {
            using (var testDb = new TestDb(SqlVersion.Sql13))
            {
                var command     = testDb.GetCreateTableCommand(testDb.TestTable._, false);
                var expectedSql =
                    @"CREATE TABLE [TestTable] (
    [DateTime] DATETIME NULL DEFAULT(GETDATE())
);
";
                Assert.AreEqual(expectedSql, command.CommandText);
            }
        }
Example #4
0
        public void DbColumnNameAttribute()
        {
            using (var testDb = new TestDb(SqlVersion.Sql13))
            {
                var command     = testDb.GetCreateTableCommand(testDb.TestTable._, false);
                var expectedSql =
                    @"CREATE TABLE [TestTable] (
    [DB_ID] INT NULL
);
";
                Assert.AreEqual(expectedSql, command.CommandText);
            }
        }
        public void ComputationAttribute_sql_generation()
        {
            using (var testDb = new TestDb(SqlVersion.Sql13))
            {
                var command     = testDb.GetCreateTableCommand(testDb.Headers._, false);
                var expectedSql =
                    @"CREATE TABLE [Headers] (
    [Id] INT NULL,
    [IdPlusOne] AS (([Id] + 1)),
    [TotalValue] INT NULL
);
";
                Assert.AreEqual(expectedSql, command.CommandText);
            }
        }
Example #6
0
        public void UniqueAttribute_sql_generation()
        {
            using (var testDb = new TestDb(SqlVersion.Sql13))
            {
                var command     = testDb.GetCreateTableCommand(testDb.TestTable._, false);
                var expectedSql =
                    @"CREATE TABLE [TestTable] (
    [Id] INT NULL

    CONSTRAINT [AK_Id] UNIQUE NONCLUSTERED ([Id])
);
";
                Assert.AreEqual(expectedSql, command.CommandText);
            }
        }
Example #7
0
        public void DefaultValueAttribute_sql_generation()
        {
            using (var testDb = new TestDb(SqlVersion.Sql13))
            {
                var command     = testDb.GetCreateTableCommand(DbTable <TestModel> .Create(new TestModel(), testDb, nameof(TestDb.TestTable))._, false);
                var expectedSql =
                    @"CREATE TABLE [TestTable] (
    [Int] INT NULL DEFAULT(5),
    [WeekDay] TINYINT NULL DEFAULT(1),
    [Status] CHAR(1) NULL DEFAULT('I')
);
";
                Assert.AreEqual(expectedSql, command.CommandText);
            }
        }
Example #8
0
        public void CheckAttribute_sql_generation()
        {
            using (var testDb = new TestDb(SqlVersion.Sql13))
            {
                var command     = testDb.GetCreateTableCommand(testDb.TestTable.Model, false);
                var expectedSql =
                    @"CREATE TABLE [TestTable] (
    [Id] INT NULL

    CONSTRAINT [CK_TestModel_Id] CHECK ([Id] > 0)
);
";
                Assert.AreEqual(expectedSql, command.CommandText);
            }
        }
        public void DbIndexAttribute_sql_generation()
        {
            using (var testDb = new TestDb(SqlVersion.Sql13))
            {
                var command     = testDb.GetCreateTableCommand(testDb.TestTable._, false);
                var expectedSql =
                    @"CREATE TABLE [TestTable] (
    [Id] INT NULL,
    [Value] INT NULL

    INDEX [IDX_ID] UNIQUE NONCLUSTERED ([Id] ASC),
    INDEX [IDX_ID_VALUE] NONCLUSTERED ([Id], [Value] DESC)
);
";
                Assert.AreEqual(expectedSql, command.CommandText);
            }
        }