Exemple #1
0
        public async Task BaseOrchestrator_GetSchema_ShouldReturnSchema()
        {
            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 scopeName = "scope";

            var options = new SyncOptions();
            var setup   = new SyncSetup(this.Tables);

            var onSchemaRead    = false;
            var onSchemaReading = false;

            var localOrchestrator = new LocalOrchestrator(sqlProvider, options, setup, scopeName);

            localOrchestrator.OnSchemaLoading(args =>
            {
                onSchemaReading = true;
            });

            localOrchestrator.OnSchemaLoaded(args =>
            {
                Assert.IsType <SchemaLoadedArgs>(args);
                Assert.Equal(SyncStage.SchemaReading, args.Context.SyncStage);
                Assert.Equal(scopeName, args.Context.ScopeName);
                Assert.NotNull(args.Connection);
                Assert.Null(args.Transaction);
                Assert.Equal(ConnectionState.Open, args.Connection.State);
                Assert.Equal(17, args.Schema.Tables.Count);
                onSchemaRead = true;
            });

            AssertConnectionAndTransaction(localOrchestrator, SyncStage.SchemaReading);

            var schema = await localOrchestrator.GetSchemaAsync();

            Assert.NotNull(schema);
            Assert.Equal(SyncStage.SchemaReading, localOrchestrator.GetContext().SyncStage);
            Assert.Equal(17, schema.Tables.Count);
            Assert.True(onSchemaRead);
            Assert.True(onSchemaReading);

            HelperDatabase.DropDatabase(ProviderType.Sql, dbName);
        }