public void SetupFilter_Compare_TwoSetupFilters_With_CustomWhere_ShouldBe_Equals() { var filter1 = new SetupFilter(); var filter2 = new SetupFilter(); filter1.AddCustomWhere("where 1"); filter2.AddCustomWhere("where 1"); Assert.Equal(filter1, filter2); Assert.True(filter1.EqualsByProperties(filter2)); filter1 = new SetupFilter(); filter2 = new SetupFilter(); filter1.AddCustomWhere(""); filter2.AddCustomWhere(""); Assert.Equal(filter1, filter2); Assert.True(filter1.EqualsByProperties(filter2)); filter1.AddCustomWhere(null); filter2.AddCustomWhere(null); Assert.Equal(filter1, filter2); Assert.True(filter1.EqualsByProperties(filter2)); filter1.AddCustomWhere(""); filter2.AddCustomWhere(null); Assert.Equal(filter1, filter2); Assert.True(filter1.EqualsByProperties(filter2)); }
public void SetupFilter_Compare_TwoSetupFilters_With_CustomWhere_ShouldBe_Different() { var filter1 = new SetupFilter(); var filter2 = new SetupFilter(); filter1.AddCustomWhere("where 1"); filter2.AddCustomWhere("where 2"); Assert.NotEqual(filter1, filter2); Assert.False(filter1.EqualsByProperties(filter2)); filter1 = new SetupFilter(); filter2 = new SetupFilter(); filter1.AddCustomWhere(""); filter2.AddCustomWhere("a"); Assert.NotEqual(filter1, filter2); Assert.False(filter1.EqualsByProperties(filter2)); filter1.AddCustomWhere("b"); filter2.AddCustomWhere(null); Assert.NotEqual(filter1, filter2); Assert.False(filter1.EqualsByProperties(filter2)); }
public SyncSetup GetFilterSetup() { var setup = new SyncSetup(new string[] { "SalesLT.ProductModel", "SalesLT.ProductCategory", "SalesLT.Product", "Customer", "Address", "CustomerAddress", "Employee", "SalesLT.SalesOrderHeader", "SalesLT.SalesOrderDetail" }); // Vertical Filter on columns setup.Tables["Customer"].Columns.AddRange(new string[] { "CustomerID", "EmployeeID", "NameStyle", "FirstName", "LastName" }); setup.Tables["Address"].Columns.AddRange(new string[] { "AddressID", "AddressLine1", "City", "PostalCode" }); // Horizontal Filters on where clause // 1) EASY Way: setup.Filters.Add("CustomerAddress", "CustomerID"); setup.Filters.Add("SalesOrderHeader", "CustomerID", "SalesLT"); // 2) Same, but decomposed in 3 Steps var customerFilter = new SetupFilter("Customer"); customerFilter.AddParameter("CustomerID", "Customer", true); customerFilter.AddWhere("CustomerID", "Customer", "CustomerID"); setup.Filters.Add(customerFilter); // 3) Create your own filter // Create a filter on table Address var addressFilter = new SetupFilter("Address"); addressFilter.AddParameter("CustomerID", "Customer"); addressFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "AddressId", "Address", "AddressId"); addressFilter.AddWhere("CustomerID", "CustomerAddress", "CustomerID"); setup.Filters.Add(addressFilter); // ---------------------------------------------------- // Create a filter on table SalesLT.SalesOrderDetail var salesOrderDetailFilter = new SetupFilter("SalesOrderDetail", "SalesLT"); salesOrderDetailFilter.AddParameter("CustomerID", "Customer"); salesOrderDetailFilter.AddJoin(Join.Left, "SalesLT.SalesOrderHeader").On("SalesLT.SalesOrderHeader", "SalesOrderId", "SalesLT.SalesOrderDetail", "SalesOrderId"); salesOrderDetailFilter.AddJoin(Join.Left, "CustomerAddress").On("CustomerAddress", "CustomerID", "SalesLT.SalesOrderHeader", "CustomerID"); salesOrderDetailFilter.AddWhere("CustomerID", "CustomerAddress", "CustomerID"); setup.Filters.Add(salesOrderDetailFilter); // ---------------------------------------------------- // 4) Custom Wheres on Product. var productFilter = new SetupFilter("Product", "SalesLT"); productFilter.AddCustomWhere("ProductCategoryID IS NOT NULL OR side.sync_row_is_tombstone = 1"); setup.Filters.Add(productFilter); return(setup); }
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)); }