public void Test21() { bool listfinalized = false; MyNode <DataWithBindingList> source = CreateSourceTreeList("root source", 2); BaseNode destination = CreateSourceTree("root dest", 2); MyNode <int> destinationSource = GetFeuille(destination, 2); destinationSource.UserData = 789; MyNode <DataWithBindingList> feuilleSource = GetFeuille <DataWithBindingList>(source, 2); feuilleSource.UserData.MyIntList.OnFinalized += delegate { listfinalized = true; }; feuilleSource.UserData.MyIntList.Add(354); DataBinder.AddCompiledBinding(source, "Left.Right.UserData.MyIntList[0]", destination, "Left.Right.UserData"); Assert.AreEqual(354, destinationSource.UserData); feuilleSource.UserData.MyIntList = new MyBindingList(); feuilleSource.UserData.MyIntList.Add(555); Assert.AreEqual(555, destinationSource.UserData); GC.Collect(); GC.WaitForPendingFinalizers(); //checks that Array is really finalized Assert.IsTrue(listfinalized); }
public void Test9() { BaseNode source = CreateSourceTree("root", 2); BaseNode destination = CreateSourceTree("root dest", 2); DataBinder.AddCompiledBinding(source, "Left.Right.UserData", destination, "Left.Right.UserData"); MyNode <int> feuilleSource = GetFeuille(source, 2); MyNode <int> feuilledest = GetFeuille(destination, 2); feuilleSource.UserData = 1235; Assert.AreEqual(feuilleSource.UserData, feuilledest.UserData); Assert.AreEqual(1235, feuilledest.UserData); source.Left = CreateSourceTree("root1", 1); destination.Left = CreateSourceTree("destroot1", 1); feuilleSource.UserData = 7894; //Destination reprend la valeur par défaut Assert.AreEqual(0, feuilledest.UserData); MyNode <int> feuilledest1 = GetFeuille(destination, 2); Assert.AreEqual(0, feuilledest1.UserData); MyNode <int> feuilleSource1 = GetFeuille(source, 2); feuilleSource1.UserData = 123; Assert.AreEqual(123, feuilledest1.UserData); }
public void Test7() { BaseNode source = CreateSourceTree("root", 2); SourceOfData destination = new SourceOfData(); DataBinder.AddCompiledBinding(source, "A.B.Z", destination, "Prop1"); }
public void Test8() { BaseNode source = CreateSourceTree("root", 2); SourceOfData destination = new SourceOfData(); DataBinder.AddCompiledBinding(source, "Left.Right.UserData", destination, "tagada"); }
private static void TestException() { //HierarchicalData destination = new HierarchicalData(); //SourceOfData source = new SourceOfData(); //DataBinder.AddCompiledBinding(source, "A.Prop1", destination, "A.B.C.Prop1"); //source.Prop1 = 25; HierarchicalData source = new HierarchicalData(); HierarchicalData destination = new HierarchicalData(); DataBinder.AddCompiledBinding(source, "A.B.C.Prop1", destination, "A.B.C.Prop1"); source.A.B.C.Prop1 = 25; AreEqual(source.A.B.C.Prop1, destination.A.B.C.Prop1, "binding doesn't work !"); AreEqual(25, destination.A.B.C.Prop1, "binding doesn't work !"); HierarchicalDataA oldA = source.A; //ici la destination va reprendre la valeur de la source, donc 0 source.A = new HierarchicalDataA("test"); oldA.B.C.Prop1 = 123; AreEqual(0, destination.A.B.C.Prop1, "binding doesn't work !"); source.A.B.C.Prop1 = 456; AreEqual(456, destination.A.B.C.Prop1, "binding doesn't work !"); source.A = new HierarchicalDataA("test1"); source.A.B.C.Prop1 = 789; AreEqual(789, destination.A.B.C.Prop1, "binding doesn't work !"); oldA = destination.A; destination.A = new HierarchicalDataA("test a"); source.A.B.C.Prop1 = 790; AreEqual(790, destination.A.B.C.Prop1, "binding doesn't work !"); AreEqual(789, oldA.B.C.Prop1, "binding doesn't work !"); }
public void Test4() { BaseNode source = CreateSourceTree("root", 2); SourceOfData destination = new SourceOfData(); DataBinder.AddCompiledBinding(source, "Left.Right.UserData", destination, "Prop1"); MyNode <int> feuille = GetFeuille(source, 2); feuille.UserData = 25; Assert.AreEqual(feuille.UserData, destination.Prop1, "binding doesn't work !"); feuille.UserData = 155; Assert.AreEqual(feuille.UserData, destination.Prop1, "binding doesn't work !"); source.Left = CreateSourceTree("childroot", 1); MyNode <int> feuille1 = GetFeuille(source, 2); feuille1.UserData = 157; Assert.AreEqual(feuille1.UserData, destination.Prop1, "binding doesn't work !"); Assert.AreEqual(feuille1.UserData, 157, "binding doesn't work !"); Assert.AreEqual(157, destination.Prop1, "binding doesn't work !"); //changement de l'ancienne valeur feuille.UserData = 456; Assert.AreEqual(157, destination.Prop1, "binding doesn't work !"); }
public void Test22() { SourceDataThrowException source = new SourceDataThrowException(); SourceOfData destination = new SourceOfData(); DataBinder.AddCompiledBinding(source, "PropGetThrowException", destination, "Prop1"); }
public Page() { InitializeComponent(); MySynchronizationContext ctx = new MySynchronizationContext(this.Dispatcher); DataBinder.AddCompiledBinding(tDefault, "Tool.AssemblyPath", t1, "Tool.DefaultPath", ctx); DataBinder.AddCompiledBinding(tDefault, "Tool.AssemblyPath", t2, "Tool.DefaultPath", ctx); }
private static void TestSimplebinding() { Console.WriteLine("Test simple binding"); DestinationOfData d = new DestinationOfData(); SourceOfData s = new SourceOfData(); DataBinder.AddCompiledBinding(s, "Prop1", d, "Prop1Dest"); Console.WriteLine("-> try set 123 on source"); s.Prop1 = 123; }
private static void TestSimplebindingWithconverter() { Console.WriteLine("test TestSimple binding with converter"); DestinationOfData d = new DestinationOfData(); SourceOfData s = new SourceOfData(); DataBinder.AddCompiledBinding(s, "Prop1", d, "Prop1DestDouble", new MyConverter()); DataBinder.AddCompiledBinding(s, "Prop1", d, "PropPoint", new MyConverter()); s.Prop1 = 1234; }
public void Test6() { BaseNode destination = CreateSourceTree("root", 2); SourceOfData source = new SourceOfData(); DataBinder.AddCompiledBinding(source, "Prop1", destination, "Left.Right.UserData"); source.Prop1 = 25; MyNode <int> feuille = GetFeuille(destination, 2); Assert.AreEqual(25, feuille.UserData, "binding doesn't work !"); }
public void Test1() { SourceOfData source = new SourceOfData(); SourceOfData destination = new SourceOfData(); DataBinder.AddCompiledBinding(source, "Prop1", destination, "Prop1"); source.Prop1 = 25; Assert.AreEqual(source.Prop1, destination.Prop1, "simple binding doesn't work !"); source.Prop1 = 155; Assert.AreEqual(source.Prop1, destination.Prop1, "simple binding doesn't work !"); }
public void Test23() { SourceDataNotifyOnPropertyChanged source = new SourceDataNotifyOnPropertyChanged(); source.IntProperty = 123456; SourceOfData destination = new SourceOfData(); DataBinder.AddCompiledBinding(source, "IntProperty", destination, "Prop1"); Assert.AreEqual(123456, destination.Prop1); source.IntProperty = 456789; Assert.AreEqual(456789, destination.Prop1); }
public void Test11() { int actual = DataBinder.Bindings.Count; BaseNode source = CreateSourceTree("root", 2); BaseNode destination = CreateSourceTree("root dest", 2); DataBinder.AddCompiledBinding(source, "Left.Right.UserData", destination, "Left.Right.UserData"); Assert.AreEqual(actual + 1, DataBinder.Bindings.Count, "add/remove doesn't work !"); DataBinder.Bindings[0].UnBind(); Assert.AreEqual(actual, DataBinder.Bindings.Count, "add/remove doesn't work !"); }
private void Button_Click_1(object sender, RoutedEventArgs e) { //test binding on another thread ToolConfig tc = new ToolConfig(); MySynchronizationContext ctx = new MySynchronizationContext(this.Dispatcher); DataBinder.AddCompiledBinding(tc, "DefaultPath", tDefault, "Tool.AssemblyPath", ctx); ThreadPool.QueueUserWorkItem(delegate { tc.DefaultPath = "my test default"; }); }
private static void TestBidirectionnelbinding() { Console.WriteLine("TestBidirectionnelbinding"); DestinationOfData d = new DestinationOfData(); SourceOfData s = new SourceOfData(); DataBinder.AddCompiledBinding(s, "Prop1", d, "Prop1Dest"); DataBinder.AddCompiledBinding(d, "Prop1Dest", s, "Prop1"); Console.WriteLine("-> try set 123 on source"); s.Prop1 = 123; Console.WriteLine("-> try set 456 on dest"); d.Prop1Dest = 456; }
public void Test2() { BaseNode source = CreateSourceTree("root", 2); SourceOfData destination = new SourceOfData(); DataBinder.AddCompiledBinding(source, "Left.Right.UserData", destination, "Prop1"); MyNode <int> feuille = GetFeuille(source, 2); feuille.UserData = 25; Assert.AreEqual(feuille.UserData, destination.Prop1, "binding doesn't work !"); feuille.UserData = 155; Assert.AreEqual(feuille.UserData, destination.Prop1, "binding doesn't work !"); }
private void button2_Click(object sender, EventArgs e) { MyData data = new MyData(); DataBinder.AddCompiledBinding(data, "TextPropertySample", textBox2, "Text", SynchronizationContext.Current); ThreadPool.QueueUserWorkItem((WaitCallback) delegate { for (int i = 0; i < 1000; i++) { data.TextPropertySample = i.ToString(); Thread.Sleep(5); } }); }
public void Test18() { BaseNode source = CreateSourceTree("root", 2); MyNode <DataWithBindingList> destination = CreateSourceTreeList("root dest", 2); MyNode <int> feuilleSource = GetFeuille(source, 2); feuilleSource.UserData = 789; MyNode <DataWithBindingList> feuilledest = GetFeuille <DataWithBindingList>(destination, 2); feuilledest.UserData.IntList.Add(123); DataBinder.AddCompiledBinding(source, "Left.Right.UserData", destination, "Left.Right.UserData.IntList[0]"); Assert.AreEqual(789, feuilledest.UserData.IntList[0]); }
public void Test24() { int currentThId = -1; int getThId = 0, setThId = 0; ManualResetEvent waitevent = new ManualResetEvent(false); DataToTestSynchronizationContext source = new DataToTestSynchronizationContext(); source.IntProperty = 123456; DataToTestSynchronizationContext destination = new DataToTestSynchronizationContext(); new Thread((ThreadStart) delegate { //Create a synchronizationcontext Button b = new Button(); bool propHasSet = false; currentThId = Thread.CurrentThread.ManagedThreadId; ExecutionContext exCtx = Thread.CurrentThread.ExecutionContext; DataBinder.AddCompiledBinding(source, "IntProperty", destination, "IntProperty", SynchronizationContext.Current); Assert.AreEqual(123456, destination.IntProperty); source.OnGet += delegate { getThId = Thread.CurrentThread.ManagedThreadId; }; destination.OnSet += delegate { setThId = Thread.CurrentThread.ManagedThreadId; propHasSet = true; }; Thread th = new Thread((ThreadStart) delegate { source.IntProperty = 456789; }); th.Start(); while (!propHasSet) { Application.DoEvents(); } waitevent.Set(); }).Start(); waitevent.WaitOne(); Assert.AreEqual(456789, destination.IntProperty); Assert.AreEqual(currentThId, getThId); Assert.AreEqual(currentThId, setThId); }
public void Test16() { BaseNode source = CreateSourceTree("root", 2); BaseNode destination = CreateSourceTree("root dest", 2); MyNode <int> feuilleSource = GetFeuille(source, 2); MyNode <int> feuilledest = GetFeuille(destination, 2); destination.Left.Right = null; source.Left.Right = null; DataBinder.AddCompiledBinding(source, "Left.Right.UserData", destination, "Left.Right.UserData"); feuilleSource.UserData = 1235; Assert.AreEqual(0, feuilledest.UserData); }
public void Test20() { MyNode <DataWithBindingList> source = CreateSourceTreeList("root source", 2); BaseNode destination = CreateSourceTree("root dest", 2); MyNode <int> destinationSource = GetFeuille(destination, 2); destinationSource.UserData = 789; MyNode <DataWithBindingList> feuilleSource = GetFeuille <DataWithBindingList>(source, 2); feuilleSource.UserData.IntList.Add(354); DataBinder.AddCompiledBinding(source, "Left.Right.UserData.IntList[0]", destination, "Left.Right.UserData"); Assert.AreEqual(354, destinationSource.UserData); }
private void TestCompiledBindingInForms_Load(object sender, EventArgs e) { DataBinder.AddCompiledBinding(textBox1, "Text", _CurrentData, "TextPropertySample"); DataBinder.AddCompiledBinding(_CurrentData, "TextPropertySample", textBox1, "Text"); DataBinder.AddCompiledBinding(_CurrentData, "TextPropertySample", lblTextboxCopy, "Text"); //DataBinder.AddCompiledBinding(_CurrentData, "TextPropertySample", button1, "Enabled", new StringToBoolean()); DataBinder.AddCompiledBinding(_CurrentData, "TextPropertySample", button1, "Enabled", DataBinder.CreateConverter <bool, string>(delegate(string value) { if (value == "exception") { throw new Exception("value cannot be converted"); } return(!string.IsNullOrEmpty(value)); })); }
private static void TestArrayIndexerBinding() { HierarchicalData source = new HierarchicalData(); HierarchicalData destination = new HierarchicalData(); destination.A.B.C = null; DataBinder.AddCompiledBinding(source, "A.B.C.List[0].Prop2", destination, "A.B.C.Prop1"); SourceOfData1 data1 = new SourceOfData1(); data1.Prop2 = 456; source.A.B.C.List.Add(data1); data1.Prop2 = 789; destination.A.B.C = new SourceOfData(); }
private static void TestPropertyPathBinding() { Console.WriteLine("test binding property 'A.B.C.Prop1' of source in Prop1DestDouble of destination"); HierarchicalData source = new HierarchicalData(); DestinationOfData d = new DestinationOfData(); DataBinder.AddCompiledBinding(source, "A.B.C.Prop1", d, "Prop1Dest"); Console.WriteLine("try to changed A"); source.A.B.C.Prop1 = 777; HierarchicalDataA A = source.A; source.A = new HierarchicalDataA("pgo"); Console.WriteLine("try to changed A.B.C.Prop1"); source.A.B.C.Prop1 = 789; source.A = null; A.B.C.Prop1 = 789; }
public void Test13() { SourceOfData source = new SourceOfData(); SourceOfData destination = new SourceOfData(); DataBinder.AddCompiledBinding(source, "Prop1", destination, "Prop1"); source.Prop1 = 123; Assert.AreEqual(123, destination.Prop1, "binding doesn't work !"); Assert.AreEqual(source.Prop1, destination.Prop1, "binding doesn't work !"); Console.WriteLine("binding count : {0}", DataBinder.Bindings.Count); DataBinder.EnableDisableBinding(source, "Prop1", false); source.Prop1 = 456; Assert.AreEqual(456, source.Prop1, "binding doesn't work !"); Assert.AreEqual(123, destination.Prop1, "binding doesn't work !"); DataBinder.EnableDisableBinding(source, "Prop1", true); source.Prop1 = 789; Assert.AreEqual(789, destination.Prop1, "binding doesn't work !"); Assert.AreEqual(source.Prop1, destination.Prop1, "binding doesn't work !"); }
private static void TestBidirectinnelbindingAndunreferenced() { GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine("TestBidirectinnelbindingAndunreferenced"); DestinationOfData d = new DestinationOfData(); SourceOfData s = new SourceOfData(); DataBinder.AddCompiledBinding(s, "Prop1", d, "Prop1Dest"); DataBinder.AddCompiledBinding(d, "Prop1Dest", s, "Prop1"); Console.WriteLine("-> try set 123 on source"); s.Prop1 = 123; Console.WriteLine("-> try set 456 on dest"); d.Prop1Dest = 456; Console.WriteLine("set destination to null"); d = null; GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine("-> now, try set 123 on source"); s.Prop1 = 123; }
public void Test5() { SourceOfData source = new SourceOfData(); SourceOfData destination = new SourceOfData(); DataBinder.AddCompiledBinding(source, "Prop1", destination, "Prop1"); source.Prop1 = 123; Assert.AreEqual(123, destination.Prop1, "binding doesn't work !"); Assert.AreEqual(source.Prop1, destination.Prop1, "binding doesn't work !"); bool finalized = false; destination.OnFinalized += delegate(object sender, EventArgs e) { finalized = true; }; destination = null; GC.Collect(); GC.WaitForPendingFinalizers(); Assert.IsTrue(finalized); source = new SourceOfData(); destination = new SourceOfData(); DataBinder.AddCompiledBinding(source, "Prop1", destination, "Prop1"); source.Prop1 = 123; Assert.AreEqual(123, destination.Prop1, "binding doesn't work !"); Assert.AreEqual(source.Prop1, destination.Prop1, "binding doesn't work !"); finalized = false; source.OnFinalized += delegate(object sender, EventArgs e) { finalized = true; }; source = null; GC.Collect(); GC.WaitForPendingFinalizers(); Assert.IsTrue(finalized); }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { DataBinder.AddCompiledBinding(this, "Objects[0].Value", this, "Objects[3].Left"); DataBinder.AddCompiledBinding(this, "Objects[1].Value", this, "Objects[3].Right"); DataBinder.AddCompiledBinding(this, "Objects[3].OutValue", this, "Objects[2].Value"); }