private async Task ExportInsertionOrderAsync(bool hasCycles, CancellationToken cancellationToken)
        {
            var orderer             = new TableRelationshipOrderer();
            var insertionOrder      = orderer.GetInsertionOrder(Tables);
            var insertionOutputPath = Path.Combine(ExportDirectory.FullName, "insertion-order.sql");
            var insertionOrderDoc   = BuildOrderDocument(insertionOrder);

            using var writer = File.CreateText(insertionOutputPath);
            await writer.WriteLineAsync("-- This is the insertion order for the database.".AsMemory(), cancellationToken).ConfigureAwait(false);

            await writer.WriteLineAsync("-- This may not be correct for your database or data relationships.".AsMemory(), cancellationToken).ConfigureAwait(false);

            await writer.WriteLineAsync("-- Please check before relying upon this information.".AsMemory(), cancellationToken).ConfigureAwait(false);

            await writer.WriteLineAsync().ConfigureAwait(false);

            if (hasCycles)
            {
                await writer.WriteLineAsync("-- NOTE: There are relationship cycles present in the database. This ordering is not guaranteed.".AsMemory(), cancellationToken).ConfigureAwait(false);

                await writer.WriteLineAsync().ConfigureAwait(false);
            }

            await writer.WriteAsync(insertionOrderDoc.AsMemory(), cancellationToken).ConfigureAwait(false);

            await writer.FlushAsync().ConfigureAwait(false);
        }
Esempio n. 2
0
        public static void GetInsertionOrder_GivenNullTables_ThrowsArgumentNullException()
        {
            var tableOrder = new TableRelationshipOrderer();

            Assert.That(() => tableOrder.GetInsertionOrder(null), Throws.ArgumentNullException);
        }