예제 #1
0
        public void SyncSetup_Compare_TwoSetup_With_Filters_ShouldBe_Different()
        {
            // Check Setup shoul be differents when tables names count is not same
            SyncSetup setup1 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory" });
            SyncSetup setup2 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });

            Assert.False(setup1.EqualsByProperties(setup2));

            // Check Setup should be differents when tables names are differents
            setup1 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee1" });
            setup2 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee2" });
            Assert.False(setup1.EqualsByProperties(setup2));


            // Check when Setup Filter names are differente (Customer1 and Customer2)
            setup1 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });
            setup2 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });

            setup1.Filters.Add("Customer1", "CompanyName");

            var addressFilter = new SetupFilter("Address");

            addressFilter.AddParameter("CompanyName", "Customer");
            addressFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter.AddWhere("CompanyName", "Customer", "CompanyName");
            setup1.Filters.Add(addressFilter);

            setup2.Filters.Add("Customer2", "CompanyName");

            var addressFilter2 = new SetupFilter("Address");

            addressFilter2.AddParameter("CompanyName", "Customer");
            addressFilter2.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter2.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter2.AddWhere("CompanyName", "Customer", "CompanyName");
            setup2.Filters.Add(addressFilter2);

            Assert.False(setup1.EqualsByProperties(setup2));

            // 2) Check when Setup Filter names are differente (Address1 and Address2)
            setup1 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });
            setup2 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });

            setup1.Filters.Add("Customer", "CompanyName");

            addressFilter = new SetupFilter("Address1");
            addressFilter.AddParameter("CompanyName", "Customer");
            addressFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter.AddWhere("CompanyName", "Customer", "CompanyName");
            setup1.Filters.Add(addressFilter);

            setup2.Filters.Add("Customer", "CompanyName");

            addressFilter2 = new SetupFilter("Address2");
            addressFilter2.AddParameter("CompanyName", "Customer");
            addressFilter2.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter2.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter2.AddWhere("CompanyName", "Customer", "CompanyName");
            setup2.Filters.Add(addressFilter2);

            Assert.False(setup1.EqualsByProperties(setup2));

            // 3) Check when Setup Parameter names are differente (CompanyName1 and CompanyName2)
            setup1 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });
            setup2 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });

            setup1.Filters.Add("Customer", "CompanyName");

            addressFilter = new SetupFilter("Address");
            addressFilter.AddParameter("CompanyName1", "Customer");
            addressFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter.AddWhere("CompanyName", "Customer", "CompanyName1");
            setup1.Filters.Add(addressFilter);

            setup2.Filters.Add("Customer", "CompanyName");

            addressFilter2 = new SetupFilter("Address");
            addressFilter2.AddParameter("CompanyName2", "Customer");
            addressFilter2.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter2.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter2.AddWhere("CompanyName", "Customer", "CompanyName2");
            setup2.Filters.Add(addressFilter2);

            Assert.False(setup1.EqualsByProperties(setup2));

            // 4) Check when Setup Joins names are differente (CustomerAddress1 and CustomerAddress2)
            setup1 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });
            setup2 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });

            setup1.Filters.Add("Customer", "CompanyName");

            addressFilter = new SetupFilter("Address");
            addressFilter.AddParameter("CompanyName", "Customer");
            addressFilter.AddJoin(Join.Left, "CustomerAddress1").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter.AddWhere("CompanyName", "Customer", "CompanyName");
            setup1.Filters.Add(addressFilter);

            setup2.Filters.Add("Customer", "CompanyName");

            addressFilter2 = new SetupFilter("Address");
            addressFilter2.AddParameter("CompanyName", "Customer");
            addressFilter2.AddJoin(Join.Left, "CustomerAddress2").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter2.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter2.AddWhere("CompanyName", "Customer", "CompanyName");
            setup2.Filters.Add(addressFilter2);

            Assert.False(setup1.EqualsByProperties(setup2));

            // 5) Check when Setup Where names are differente (CompanyName1 and CompanyName2)
            setup1 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });
            setup2 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });

            setup1.Filters.Add("Customer", "CompanyName");

            addressFilter = new SetupFilter("Address");
            addressFilter.AddParameter("CompanyName", "Customer");
            addressFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter.AddWhere("CompanyName1", "Customer", "CompanyName");
            setup1.Filters.Add(addressFilter);

            setup2.Filters.Add("Customer", "CompanyName");

            addressFilter2 = new SetupFilter("Address");
            addressFilter2.AddParameter("CompanyName", "Customer");
            addressFilter2.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter2.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter2.AddWhere("CompanyName2", "Customer", "CompanyName");
            setup2.Filters.Add(addressFilter2);

            Assert.False(setup1.EqualsByProperties(setup2));

            // 6) Check CustomWhere differences
            setup1 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });
            setup2 = new SyncSetup(new string[] { "Customer", "Address", "ProductCategory", "Employee" });

            setup1.Filters.Add("Customer", "CompanyName");

            addressFilter = new SetupFilter("Address");
            addressFilter.AddParameter("CompanyName", "Customer");
            addressFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter.AddWhere("CompanyName", "Customer", "CompanyName");
            addressFilter.AddCustomWhere("ID = @ID2");
            setup1.Filters.Add(addressFilter);

            setup2.Filters.Add("Customer", "CompanyName");

            addressFilter2 = new SetupFilter("Address");
            addressFilter2.AddParameter("CompanyName", "Customer");
            addressFilter2.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter2.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter2.AddWhere("CompanyName", "Customer", "CompanyName");
            addressFilter2.AddCustomWhere("ID = @ID1");
            setup2.Filters.Add(addressFilter2);

            Assert.False(setup1.EqualsByProperties(setup2));
        }
        public async Task RemoteOrchestrator_CreateSnapshot_WithParameters_CheckBatchInfo()
        {
            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, true);
            await ctx.Database.EnsureCreatedAsync();

            // snapshot directory
            var snapshotDirctoryName = HelperDatabase.GetRandomName();
            var snapshotDirectory    = Path.Combine(Environment.CurrentDirectory, snapshotDirctoryName);

            var options = new SyncOptions
            {
                SnapshotsDirectory = snapshotDirectory,
                BatchSize          = 200
            };

            var setup    = new SyncSetup(Tables);
            var provider = new SqlSyncProvider(cs);

            setup.Filters.Add("Customer", "CompanyName");

            var addressCustomerFilter = new SetupFilter("CustomerAddress");

            addressCustomerFilter.AddParameter("CompanyName", "Customer");
            addressCustomerFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressCustomerFilter.AddWhere("CompanyName", "Customer", "CompanyName");
            setup.Filters.Add(addressCustomerFilter);

            var addressFilter = new SetupFilter("Address");

            addressFilter.AddParameter("CompanyName", "Customer");
            addressFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter.AddWhere("CompanyName", "Customer", "CompanyName");
            setup.Filters.Add(addressFilter);

            var orderHeaderFilter = new SetupFilter("SalesOrderHeader");

            orderHeaderFilter.AddParameter("CompanyName", "Customer");
            orderHeaderFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "CustomerId", "SalesOrderHeader", "CustomerId");
            orderHeaderFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            orderHeaderFilter.AddWhere("CompanyName", "Customer", "CompanyName");
            setup.Filters.Add(orderHeaderFilter);

            var orderDetailsFilter = new SetupFilter("SalesOrderDetail");

            orderDetailsFilter.AddParameter("CompanyName", "Customer");
            orderDetailsFilter.AddJoin(Join.Left, "SalesOrderHeader").On("SalesOrderDetail", "SalesOrderID", "SalesOrderHeader", "SalesOrderID");
            orderDetailsFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "CustomerId", "SalesOrderHeader", "CustomerId");
            orderDetailsFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            orderDetailsFilter.AddWhere("CompanyName", "Customer", "CompanyName");
            setup.Filters.Add(orderDetailsFilter);


            var orchestrator = new RemoteOrchestrator(provider, options, setup);

            SyncParameters parameters = new SyncParameters();
            var            p1         = new SyncParameter("CompanyName", "A Bike Store");

            parameters.Add(p1);

            var bi = await orchestrator.CreateSnapshotAsync(parameters);

            var finalDirectoryFullName = Path.Combine(snapshotDirectory, SyncOptions.DefaultScopeName);

            Assert.NotNull(bi);
            Assert.Equal(finalDirectoryFullName, bi.DirectoryRoot);
            Assert.Equal("CompanyName_ABikeStore", bi.DirectoryName);
            Assert.Single(bi.BatchPartsInfo);
            Assert.Equal(16, bi.BatchPartsInfo[0].Tables.Length);
            Assert.True(bi.BatchPartsInfo[0].IsLastBatch);

            // Check summary.json exists.
            var summaryFile   = Path.Combine(bi.GetDirectoryFullPath(), "summary.json");
            var summaryString = new StreamReader(summaryFile).ReadToEnd();
            var summaryObject = JObject.Parse(summaryString);

            Assert.NotNull(summaryObject);
            string summaryDirname = (string)summaryObject["dirname"];

            Assert.NotNull(summaryDirname);
            Assert.Equal("CompanyName_ABikeStore", summaryDirname);

            string summaryDir = (string)summaryObject["dir"];

            Assert.NotNull(summaryDir);
            Assert.Equal(finalDirectoryFullName, summaryDir);

            Assert.Single(summaryObject["parts"]);
            Assert.NotNull(summaryObject["parts"][0]["file"]);
            Assert.NotNull(summaryObject["parts"][0]["index"]);
            Assert.Equal(0, (int)summaryObject["parts"][0]["index"]);
            Assert.NotNull(summaryObject["parts"][0]["last"]);
            Assert.True((bool)summaryObject["parts"][0]["last"]);
            Assert.Equal(16, summaryObject["parts"][0]["tables"].Count());

            HelperDatabase.DropDatabase(ProviderType.Sql, dbName);
        }
예제 #3
0
        public void SyncSetup_Compare_TwoSetup_With_Filters_ShouldBe_Equals()
        {
            SyncSetup setup1 = new SyncSetup(new string[] { "Customer", "Product", "ProductCategory", "Employee" });
            SyncSetup setup2 = new SyncSetup(new string[] { "Customer", "Product", "ProductCategory", "Employee" });

            setup1.Filters.Add("Customer", "CompanyName");

            var addressCustomerFilter = new SetupFilter("CustomerAddress");

            addressCustomerFilter.AddParameter("CompanyName", "Customer");
            addressCustomerFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressCustomerFilter.AddWhere("CompanyName", "Customer", "CompanyName");
            setup1.Filters.Add(addressCustomerFilter);

            var addressFilter = new SetupFilter("Address");

            addressFilter.AddParameter("CompanyName", "Customer");
            addressFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter.AddWhere("CompanyName", "Customer", "CompanyName");
            setup1.Filters.Add(addressFilter);

            var orderHeaderFilter = new SetupFilter("SalesOrderHeader");

            orderHeaderFilter.AddParameter("CompanyName", "Customer");
            orderHeaderFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "CustomerId", "SalesOrderHeader", "CustomerId");
            orderHeaderFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            orderHeaderFilter.AddWhere("CompanyName", "Customer", "CompanyName");
            setup1.Filters.Add(orderHeaderFilter);

            var orderDetailsFilter = new SetupFilter("SalesOrderDetail");

            orderDetailsFilter.AddParameter("CompanyName", "Customer");
            orderDetailsFilter.AddJoin(Join.Left, "SalesOrderHeader").On("SalesOrderDetail", "SalesOrderID", "SalesOrderHeader", "SalesOrderID");
            orderDetailsFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "CustomerId", "SalesOrderHeader", "CustomerId");
            orderDetailsFilter.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            orderDetailsFilter.AddWhere("CompanyName", "Customer", "CompanyName");
            setup1.Filters.Add(orderDetailsFilter);

            setup2.Filters.Add("Customer", "CompanyName");

            var addressCustomerFilter2 = new SetupFilter("CustomerAddress");

            addressCustomerFilter2.AddParameter("CompanyName", "Customer");
            addressCustomerFilter2.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressCustomerFilter2.AddWhere("CompanyName", "Customer", "CompanyName");
            setup2.Filters.Add(addressCustomerFilter2);

            var addressFilter2 = new SetupFilter("Address");

            addressFilter2.AddParameter("CompanyName", "Customer");
            addressFilter2.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId");
            addressFilter2.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            addressFilter2.AddWhere("CompanyName", "Customer", "CompanyName");
            setup2.Filters.Add(addressFilter2);

            var orderHeaderFilter2 = new SetupFilter("SalesOrderHeader");

            orderHeaderFilter2.AddParameter("CompanyName", "Customer");
            orderHeaderFilter2.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "CustomerId", "SalesOrderHeader", "CustomerId");
            orderHeaderFilter2.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            orderHeaderFilter2.AddWhere("CompanyName", "Customer", "CompanyName");
            setup2.Filters.Add(orderHeaderFilter2);

            var orderDetailsFilter2 = new SetupFilter("SalesOrderDetail");

            orderDetailsFilter2.AddParameter("CompanyName", "Customer");
            orderDetailsFilter2.AddJoin(Join.Left, "SalesOrderHeader").On("SalesOrderDetail", "SalesOrderID", "SalesOrderHeader", "SalesOrderID");
            orderDetailsFilter2.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "CustomerId", "SalesOrderHeader", "CustomerId");
            orderDetailsFilter2.AddJoin(Join.Left, "Customer").On("CustomerAddress", "CustomerId", "Customer", "CustomerId");
            orderDetailsFilter2.AddWhere("CompanyName", "Customer", "CompanyName");
            setup2.Filters.Add(orderDetailsFilter2);


            Assert.True(setup1.EqualsByProperties(setup2));
        }