public async Task TrackingTable_Drop_All() { 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.ProductCategory", "SalesLT.ProductModel", "SalesLT.Product", "dbo.Sql", "Posts" }); setup.TrackingTablesPrefix = "t_"; setup.TrackingTablesSuffix = "_t"; var localOrchestrator = new LocalOrchestrator(sqlProvider, options, setup); var onDropping = 0; var onDropped = 0; localOrchestrator.OnTrackingTableDropping(ttca => onDropping++); localOrchestrator.OnTrackingTableDropped(ttca => onDropped++); await localOrchestrator.CreateTrackingTablesAsync(); await localOrchestrator.DropTrackingTablesAsync(); Assert.Equal(5, onDropping); Assert.Equal(5, onDropped); HelperDatabase.DropDatabase(ProviderType.Sql, dbName); }
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 localOrchestrator = new LocalOrchestrator(sqlProvider, options, setup); var onDropping = false; var onDropped = false; localOrchestrator.OnTrackingTableDropping(ttca => { ttca.Cancel = true; onDropping = true; }); localOrchestrator.OnTrackingTableDropped(ttca => { onDropped = true; }); await localOrchestrator.CreateTrackingTableAsync(setup.Tables[0]); await localOrchestrator.DropTrackingTableAsync(setup.Tables[0]); 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); }