public static async Task AnalyseTables_GivenTableWithColumnNameContainingWhitespace_ProducesMessages() { var rule = new WhitespaceNameRule(RuleLevel.Error); var testColumn = new DatabaseColumn( " test_column ", Mock.Of <IDbType>(), false, null, null ); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn> { testColumn }, null, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.True); }
public static async Task AnalyseTables_GivenTableWithDisabledUniqueKey_ProducesMessages() { var rule = new DisabledObjectsRule(RuleLevel.Error); var testColumn = new DatabaseColumn( "test_column", Mock.Of <IDbType>(), false, null, null ); var testUniqueKey = new DatabaseKey( Option <Identifier> .Some("test_unique_key"), DatabaseKeyType.Unique, new[] { testColumn }, false ); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn>(), null, new[] { testUniqueKey }, Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.True); }
public static async Task AnalyseTables_GivenTableWithoutColumnsContainingNumericSuffix_ProducesNoMessages() { var rule = new ColumnWithNullDefaultValueRule(RuleLevel.Error); var testColumn = new DatabaseColumn( "test_column", Mock.Of <IDbType>(), true, null, null ); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn> { testColumn }, null, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.False); }
public static async Task AnalyseTables_GivenTableWithDisabledCheck_ProducesMessages() { var rule = new DisabledObjectsRule(RuleLevel.Error); var testCheck = new DatabaseCheckConstraint( Option <Identifier> .Some("test_check"), "test_check_definition", false ); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn>(), null, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), new[] { testCheck }, Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.True); }
public static async Task AnalyseTables_GivenTableWithDisabledTrigger_ProducesMessages() { var rule = new DisabledObjectsRule(RuleLevel.Error); var testTrigger = new DatabaseTrigger( "test_check", "test_check_definition", TriggerQueryTiming.After, TriggerEvent.Insert, false ); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn>(), null, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), new[] { testTrigger } ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.True); }
public static async Task AnalyseTables_GivenTableWithRegularColumnNames_ProducesNoMessages() { var rule = new ReservedKeywordNameRule(CreateFakeDialect(), RuleLevel.Error); var testColumn = new DatabaseColumn( "test_column", Mock.Of <IDbType>(), false, null, null ); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn> { testColumn }, null, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.False); }
public static async Task AnalyseTables_GivenTableWithPrimaryKey_ProducesNoMessages() { var rule = new CandidateKeyMissingRule(RuleLevel.Error); var testColumn = new DatabaseColumn( "test_column", Mock.Of <IDbType>(), false, null, null ); var testPrimaryKey = new DatabaseKey( Option <Identifier> .Some("test_primary_key"), DatabaseKeyType.Primary, new[] { testColumn }, true ); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn>(), testPrimaryKey, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.False); }
public static async Task AnalyseTables_GivenTableWithDisabledForeignKey_ProducesMessages() { var rule = new DisabledObjectsRule(RuleLevel.Error); var testColumn = new DatabaseColumn( "test_column", Mock.Of <IDbType>(), false, null, null ); var testForeignKey = new DatabaseKey( Option <Identifier> .Some("test_foreign_key"), DatabaseKeyType.Foreign, new[] { testColumn }, false ); var testPrimaryKey = new DatabaseKey( Option <Identifier> .Some("test_primary_key"), DatabaseKeyType.Primary, new[] { testColumn }, false ); var testRelationalKey = new DatabaseRelationalKey( "child_table", testForeignKey, "parent_table", testPrimaryKey, ReferentialAction.Cascade, ReferentialAction.Cascade ); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn>(), null, Array.Empty <IDatabaseKey>(), new[] { testRelationalKey }, Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.True); }
public static async Task AnalyseTables_GivenTableWithColumnsExceedingLimit_ProducesMessages() { var rule = new TooManyColumnsRule(RuleLevel.Error, 2); var testColumn1 = new DatabaseColumn( "test_column_1", Mock.Of <IDbType>(), true, null, null ); var testColumn2 = new DatabaseColumn( "test_column_2", Mock.Of <IDbType>(), true, null, null ); var testColumn3 = new DatabaseColumn( "test_column_3", Mock.Of <IDbType>(), true, null, null ); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn> { testColumn1, testColumn2, testColumn3 }, null, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.True); }
public static async Task AnalyseTables_GivenTableWithIndexWithMoreColumnsThanKeyInWrongOrder_ProducesMessages() { var rule = new ForeignKeyIndexRule(RuleLevel.Error); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn> { GetColumn("a"), GetColumn("b"), GetColumn("c") }, null, Array.Empty <IDatabaseKey>(), new[] { new DatabaseRelationalKey( "test", new DatabaseKey(Option <Identifier> .Some("test_fk_1"), DatabaseKeyType.Foreign, new[] { GetColumn("b") }, true), "test_parent", new DatabaseKey(Option <Identifier> .Some("test_pk_1"), DatabaseKeyType.Primary, new[] { GetColumn("b") }, true), ReferentialAction.Cascade, ReferentialAction.Cascade ) }, Array.Empty <IDatabaseRelationalKey>(), new[] { new DatabaseIndex( "test_index_1", false, new[] { GetIndexColumn("c"), GetIndexColumn("b") }, Array.Empty <IDatabaseColumn>(), true ) }, Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.True); }
public static void ToString_WhenInvoked_ReturnsExpectedString(string schema, string localName, string expectedOutput) { var tableName = Identifier.CreateQualifiedIdentifier(schema, localName); var columns = new[] { Mock.Of <IDatabaseColumn>() }; var primaryKey = Option <IDatabaseKey> .None; var uniqueKeys = Array.Empty <IDatabaseKey>(); var parentKeys = Array.Empty <IDatabaseRelationalKey>(); var childKeys = Array.Empty <IDatabaseRelationalKey>(); var indexes = Array.Empty <IDatabaseIndex>(); var checks = Array.Empty <IDatabaseCheckConstraint>(); var triggers = Array.Empty <IDatabaseTrigger>(); var table = new RelationalDatabaseTable(tableName, columns, primaryKey, uniqueKeys, parentKeys, childKeys, indexes, checks, triggers); var result = table.ToString(); Assert.That(result, Is.EqualTo(expectedOutput)); }
public static async Task AnalyseTables_GivenTableWithPrimaryKeyWithSingleNonIntegerColumn_ProducesMessages() { var rule = new PrimaryKeyNotIntegerRule(RuleLevel.Error); var dataTypeMock = new Mock <IDbType>(); dataTypeMock.Setup(t => t.DataType).Returns(DataType.Binary); var testColumn = new DatabaseColumn( "test_column_1", dataTypeMock.Object, false, null, null ); var testPrimaryKey = new DatabaseKey( Option <Identifier> .Some("test_primary_key"), DatabaseKeyType.Primary, new[] { testColumn }, true ); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn> { testColumn }, testPrimaryKey, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.True); }
public static async Task AnalyseTables_GivenTableWithMissingPrimaryKeyAndNoUniqueKeys_ProducesMessages() { var rule = new CandidateKeyMissingRule(RuleLevel.Error); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn>(), null, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.True); }
public static async Task AnalyseTables_GivenTableWithNoDisabledObjects_ProducesNoMessages() { var rule = new DisabledObjectsRule(RuleLevel.Error); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn>(), null, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.False); }
public static async Task AnalyseTables_GivenTableWithOnlyPrimaryKey_ProducesNoMessages() { var rule = new NoIndexesPresentOnTableRule(RuleLevel.Error); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn>(), Option <IDatabaseKey> .Some(Mock.Of <IDatabaseKey>()), Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.False); }
public static async Task AnalyseTables_GivenTableWithChildKeys_ProducesNoMessages() { var rule = new OrphanedTableRule(RuleLevel.Error); var childKey = new DatabaseRelationalKey( "child_table", new DatabaseKey( Option <Identifier> .Some("child_key"), DatabaseKeyType.Foreign, new[] { Mock.Of <IDatabaseColumn>() }, true ), "parent_table", new DatabaseKey( Option <Identifier> .Some("parent_key"), DatabaseKeyType.Primary, new[] { Mock.Of <IDatabaseColumn>() }, true ), ReferentialAction.NoAction, ReferentialAction.NoAction ); var parentTable = new RelationalDatabaseTable( "test", new List <IDatabaseColumn>(), null, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), new[] { childKey }, Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { parentTable }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.False); }
public static async Task AnalyseTables_GivenTableWithRegularName_ProducesNoMessages() { var rule = new WhitespaceNameRule(RuleLevel.Error); var tableName = new Identifier("test"); var table = new RelationalDatabaseTable( tableName, new List <IDatabaseColumn>(), null, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.False); }
public static async Task AnalyseTables_GivenTableWithNameContainingReservedKeyword_ProducesMessages() { var rule = new ReservedKeywordNameRule(CreateFakeDialect(), RuleLevel.Error); var tableName = new Identifier("SELECT"); var table = new RelationalDatabaseTable( tableName, new List <IDatabaseColumn>(), null, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.True); }
public static async Task AnalyseTables_GivenTableWithNoNullableColumnsInUniqueIndex_ProducesNoMessages() { var rule = new UniqueIndexWithNullableColumnsRule(RuleLevel.Error); var testColumn = new DatabaseColumn( "test_column_1", Mock.Of <IDbType>(), false, null, null ); var uniqueIndex = new DatabaseIndex( "test_index_name", true, new[] { new DatabaseIndexColumn("test_column_1", testColumn, IndexColumnOrder.Ascending) }, Array.Empty <IDatabaseColumn>(), true ); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn>(), null, Array.Empty <IDatabaseKey>(), Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseRelationalKey>(), new[] { uniqueIndex }, Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.False); }
public static async Task AnalyseTables_GivenTableWithMultiColumnPrimaryKeyContainingAllForeignKeyColumns_ProducesNoMessages() { var rule = new NoSurrogatePrimaryKeyRule(RuleLevel.Error); var testColumnA = new DatabaseColumn( "test_column_a", Mock.Of <IDbType>(), false, null, null ); var testColumnB = new DatabaseColumn( "test_column_b", Mock.Of <IDbType>(), false, null, null ); var testPrimaryKey = new DatabaseKey( Option <Identifier> .Some("test_primary_key"), DatabaseKeyType.Primary, new[] { testColumnA, testColumnB }, true ); var testForeignKey1 = new DatabaseKey( Option <Identifier> .Some("test_fk1"), DatabaseKeyType.Foreign, new[] { testColumnA }, true ); var testForeignKey2 = new DatabaseKey( Option <Identifier> .Some("test_fk2"), DatabaseKeyType.Foreign, new[] { testColumnB }, true ); var relationalKey1 = new DatabaseRelationalKey( "test", testForeignKey1, "test", testPrimaryKey, ReferentialAction.Cascade, ReferentialAction.Cascade ); var relationalKey2 = new DatabaseRelationalKey( "test", testForeignKey2, "test", testPrimaryKey, ReferentialAction.Cascade, ReferentialAction.Cascade ); var table = new RelationalDatabaseTable( "test", new List <IDatabaseColumn>(), testPrimaryKey, Array.Empty <IDatabaseKey>(), new[] { relationalKey1, relationalKey2 }, Array.Empty <IDatabaseRelationalKey>(), Array.Empty <IDatabaseIndex>(), Array.Empty <IDatabaseCheckConstraint>(), Array.Empty <IDatabaseTrigger>() ); var tables = new[] { table }; var hasMessages = await rule.AnalyseTables(tables).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.False); }