public async Task SyncThroughHttp() { using (var server = new KestrellTestServer()) { var serverHandler = new RequestDelegate(async context => { SqlSyncProvider serverProvider = new SqlSyncProvider(this.fixture.ServerConnectionString); SyncConfiguration configuration = new SyncConfiguration(this.fixture.Tables); configuration.DownloadBatchSizeInKB = 500; serverProvider.SetConfiguration(configuration); WebProxyServerProvider proxyServerProvider = new WebProxyServerProvider(serverProvider, SerializationFormat.Json); await proxyServerProvider.HandleRequestAsync(context); }); var clientHandler = new ResponseDelegate(async(serviceUri) => { var proxyProvider = new WebProxyClientProvider(new Uri(serviceUri), SerializationFormat.Json); var clientProvider = new SqlSyncProvider(this.fixture.Client1ConnectionString); SyncAgent agent = new SyncAgent(clientProvider, proxyProvider); var session = await agent.SynchronizeAsync(); Assert.Equal(5, session.TotalChangesDownloaded); Assert.Equal(0, session.TotalChangesUploaded); }); await server.Run(serverHandler, clientHandler); } }
public async Task Initialize() { var serverHandler = new RequestDelegate(async context => { //configuration.AddTable(fixture.Tables); serverProvider.SetConfiguration(configuration); proxyServerProvider.SerializationFormat = SerializationFormat.Json; await proxyServerProvider.HandleRequestAsync(context); }); using (var server = new KestrellTestServer()) { var clientHandler = new ResponseDelegate(async(serviceUri) => { proxyClientProvider.ServiceUri = new Uri(serviceUri); proxyClientProvider.SerializationFormat = SerializationFormat.Json; var syncAgent = new SyncAgent(clientProvider, proxyClientProvider); var session = await syncAgent.SynchronizeAsync(); Assert.Equal(7, session.TotalChangesDownloaded); Assert.Equal(0, session.TotalChangesUploaded); }); await server.Run(serverHandler, clientHandler); } // check relation has been created on client : int foreignKeysCount; using (var sqlConnection = new SqlConnection(fixture.Client1ConnectionString)) { var script = $@"Select count(*) from sys.foreign_keys where name = 'FK_ServiceTickets_Customers'"; using (var sqlCmd = new SqlCommand(script, sqlConnection)) { sqlConnection.Open(); foreignKeysCount = (int)sqlCmd.ExecuteScalar(); sqlConnection.Close(); } } Assert.Equal(1, foreignKeysCount); }
public async Task Initialize() { using (var server = new KestrellTestServer()) { var serverHandler = new RequestDelegate(async context => { //configuration.AddTable(fixture.Tables); serverProvider.SetConfiguration(configuration); proxyServerProvider.SerializationFormat = SerializationFormat.Json; await proxyServerProvider.HandleRequestAsync(context); }); var clientHandler = new ResponseDelegate(async(serviceUri) => { proxyClientProvider.ServiceUri = new Uri(serviceUri); proxyClientProvider.SerializationFormat = SerializationFormat.Json; var session = await agent.SynchronizeAsync(); Assert.Equal(50, session.TotalChangesDownloaded); Assert.Equal(0, session.TotalChangesUploaded); }); await server.Run(serverHandler, clientHandler); } }
/// <summary> /// Test syncking through Kestrell server /// </summary> private static async Task TestSyncThroughKestrellAsync() { var id = Guid.NewGuid(); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddJsonFile("config.json", true); IConfiguration Configuration = configurationBuilder.Build(); var serverConfig = Configuration["AppConfiguration:ServerConnectionString"]; var clientConfig = Configuration["AppConfiguration:ClientConnectionString"]; // Server side var serverHandler = new RequestDelegate(async context => { // Create the internal provider SqlSyncProvider serverProvider = new SqlSyncProvider(serverConfig); // Create the configuration stuff ServiceConfiguration configuration = new ServiceConfiguration(new string[] { "ServiceTickets" }); configuration.DownloadBatchSizeInKB = 500; serverProvider.SetConfiguration(configuration); // Create the proxy provider WebProxyServerProvider proxyServerProvider = new WebProxyServerProvider(serverProvider, SerializationFormat.Json); serverProvider.SyncProgress += ServerProvider_SyncProgress; try { CancellationTokenSource cts = new CancellationTokenSource(); // cts.CancelAfter(60000); CancellationToken token = cts.Token; await proxyServerProvider.HandleRequestAsync(context, token); } catch (WebSyncException webSyncException) { Console.WriteLine("Proxy Server WebSyncException : " + webSyncException.Message); } catch (Exception e) { Console.WriteLine("Proxy Server Exception : " + e.Message); throw e; } }); var clientHandler = new ResponseDelegate(async(serviceUri) => { var proxyProvider = new WebProxyClientProvider(new Uri(serviceUri), SerializationFormat.Json); var clientProvider = new SqlSyncProvider(clientConfig); SyncAgent agent = new SyncAgent(clientProvider, proxyProvider); agent.SyncProgress += Agent_SyncProgress; do { try { CancellationTokenSource cts = new CancellationTokenSource(); //cts.CancelAfter(1000); CancellationToken token = cts.Token; var s = await agent.SynchronizeAsync(token); } catch (WebSyncException webSyncException) { Console.WriteLine("Proxy Client WebSyncException : " + webSyncException.Message); } catch (Exception e) { Console.WriteLine("Proxy Client Exception : " + e.Message); } Console.WriteLine("Sync Ended. Press a key to start again, or Escapte to end"); } while (Console.ReadKey().Key != ConsoleKey.Escape); }); await TestKestrelHttpServer.LaunchKestrellAsync(serverHandler, clientHandler); }