Beispiel #1
0
        public async Task AnalyseTables_GivenTablesWithTableWithoutIndexOnForeignKey_ProducesMessages()
        {
            var rule     = new ForeignKeyIndexRule(RuleLevel.Error);
            var database = GetSqliteDatabase();

            var tables = new[]
            {
                await database.GetTable("no_index_parent_table_1").UnwrapSomeAsync().ConfigureAwait(false),
                await database.GetTable("not_indexed_child_table_1").UnwrapSomeAsync().ConfigureAwait(false)
            };

            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 AnalyseTables_GivenNullTables_ThrowsArgumentNullException()
        {
            var rule = new ForeignKeyIndexRule(RuleLevel.Error);

            Assert.That(() => rule.AnalyseTables(null), Throws.ArgumentNullException);
        }