public async Task TrackingTable_Drop_One_Cancel()
        {
            var dbName = HelperDatabase.GetRandomName("tcp_lo_");
            await HelperDatabase.CreateDatabaseAsync(ProviderType.Sql, dbName, true);

            var cs          = HelperDatabase.GetConnectionString(ProviderType.Sql, dbName);
            var sqlProvider = new SqlSyncProvider(cs);

            var ctx = new AdventureWorksContext((dbName, ProviderType.Sql, sqlProvider), true, false);
            await ctx.Database.EnsureCreatedAsync();

            var options = new SyncOptions();
            var setup   = new SyncSetup(new string[] { "SalesLT.Product" });

            setup.TrackingTablesPrefix = "t_";
            setup.TrackingTablesSuffix = "_t";

            var remoteOrchestrator = new RemoteOrchestrator(sqlProvider, options);

            var scopeInfo = await remoteOrchestrator.GetServerScopeInfoAsync(setup);

            var onDropping = false;
            var onDropped  = false;

            remoteOrchestrator.OnTrackingTableDropping(ttca =>
            {
                ttca.Cancel = true;
                onDropping  = true;
            });

            remoteOrchestrator.OnTrackingTableDropped(ttca =>
            {
                onDropped = true;
            });

            await remoteOrchestrator.CreateTrackingTableAsync(scopeInfo, "Product", "SalesLT");

            await remoteOrchestrator.DropTrackingTableAsync(scopeInfo, "Product", "SalesLT");

            Assert.True(onDropping);
            Assert.False(onDropped);

            // Check we have a new column in tracking table
            using (var c = new SqlConnection(cs))
            {
                await c.OpenAsync().ConfigureAwait(false);

                var table = await SqlManagementUtils.GetTableAsync(c, null, "t_Product_t", "SalesLT").ConfigureAwait(false);

                Assert.NotEmpty(table.Rows);

                c.Close();
            }

            HelperDatabase.DropDatabase(ProviderType.Sql, dbName);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Drop one tracking table and one stored procedure
        /// </summary>
        private static async Task DropOneTrackingTableAndOneStoredProcedure()
        {
            var provider     = new SqlSyncProvider(serverConnectionString);
            var options      = new SyncOptions();
            var setup        = new SyncSetup("ProductCategory", "ProductModel", "Product");
            var orchestrator = new RemoteOrchestrator(provider, options);

            var serverScope = await orchestrator.GetServerScopeInfoAsync(setup);

            var trExists = await orchestrator.ExistTrackingTableAsync(serverScope, "Product");

            if (trExists)
            {
                await orchestrator.DropTrackingTableAsync(serverScope, "Product");
            }

            var spExists = await orchestrator.ExistStoredProcedureAsync(serverScope, "Product", null, DbStoredProcedureType.SelectChanges);

            if (spExists)
            {
                await orchestrator.DropStoredProcedureAsync(serverScope, "Product", null, DbStoredProcedureType.SelectChanges);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Drop one tracking table and one stored procedure
        /// </summary>
        private static async Task DropOneTrackingTableAndOneStoredProcedure()
        {
            var provider     = new SqlSyncProvider(serverConnectionString);
            var options      = new SyncOptions();
            var setup        = new SyncSetup(new string[] { "ProductCategory", "ProductModel", "Product" });
            var orchestrator = new RemoteOrchestrator(provider, options, setup);

            // working on the product Table
            var productSetupTable = setup.Tables["Product"];

            var trExists = await orchestrator.ExistTrackingTableAsync(productSetupTable);

            if (trExists)
            {
                await orchestrator.DropTrackingTableAsync(productSetupTable);
            }

            var spExists = await orchestrator.ExistStoredProcedureAsync(productSetupTable, DbStoredProcedureType.SelectChanges);

            if (spExists)
            {
                await orchestrator.DropStoredProcedureAsync(productSetupTable, DbStoredProcedureType.SelectChanges);
            }
        }