예제 #1
0
        public void ChangeInheritedDataContext()
        {
            using(var form = new Form()) {
                var button1 = new Button();
                var button2 = new Button();
                form.Controls.Add(button1);
                form.Controls.Add(button2);
                form.SetDataContext("test");
                Assert.That(button1.GetDataContext(), Is.EqualTo("test"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                form.SetDataContext("test2");
                Assert.That(button1.GetDataContext(), Is.EqualTo("test2"));
                Assert.That(button1.HasLocalDataContext(), Is.False);

                button2.SetDataContext("button2");

                form.ClearDataContext();
                Assert.That(button1.GetDataContext(), Is.Null);
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);

                form.SetDataContext("test");
                Assert.That(button1.GetDataContext(), Is.EqualTo("test"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);

                form.Controls.Remove(button1);
                Assert.That(button1.GetDataContext(), Is.Null);
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);
                form.Controls.Remove(button2);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);
            }
        }
예제 #2
0
        public void MultiLevelDataContextInheritance1()
        {
            using(var form = new Form()) {
                var panel = new Panel();
                var button1 = new Button();
                button1.SetBinding("Text", new Binding());
                panel.SetBinding("Tag", new Binding());
                panel.Controls.Add(button1);
                form.Controls.Add(panel);
                form.SetDataContext("test");

                Assert.That(button1.Text, Is.EqualTo("test"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                form.SetDataContext("test2");
                Assert.That(button1.Text, Is.EqualTo("test2"));
                Assert.That(button1.HasLocalDataContext(), Is.False);

                form.ClearDataContext();
                Assert.That(button1.Text, Is.EqualTo(string.Empty));

                form.SetDataContext("test2");
                Assert.That(panel.Tag, Is.EqualTo("test2"));
                Assert.That(button1.Text, Is.EqualTo("test2"));

                panel.SetDataContext("panel");
                Assert.That(panel.Tag, Is.EqualTo("panel"));
                Assert.That(button1.Text, Is.EqualTo("panel"));

                form.ClearDataContext();
                Assert.That(panel.Tag, Is.EqualTo("panel"));
                Assert.That(button1.Text, Is.EqualTo("panel"));

                form.SetDataContext("test2");
                Assert.That(panel.Tag, Is.EqualTo("panel"));
                Assert.That(button1.Text, Is.EqualTo("panel"));

                panel.ClearDataContext();
                Assert.That(panel.Tag, Is.EqualTo("test2"));
                Assert.That(button1.Text, Is.EqualTo("test2"));

                form.Controls.Clear();
                Assert.That(panel.Tag, Is.Null);
                Assert.That(button1.Text, Is.EqualTo(string.Empty));
            }
        }
예제 #3
0
        public void MultiLevelDataContextInheritance1()
        {
            using(var form = new Form()) {
                var panel = new Panel();
                var button1 = new Button();
                var button2 = new Button();
                panel.Controls.Add(button1);
                panel.Controls.Add(button2);
                form.Controls.Add(panel);
                form.SetDataContext("test");

                Assert.That(button1.GetDataContext(), Is.EqualTo("test"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                form.SetDataContext("test2");
                Assert.That(button1.GetDataContext(), Is.EqualTo("test2"));
                Assert.That(button1.HasLocalDataContext(), Is.False);

                button2.SetDataContext("button2");

                form.ClearDataContext();
                Assert.That(button1.GetDataContext(), Is.Null);
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);

                form.SetDataContext("test2");
                Assert.That(button1.GetDataContext(), Is.EqualTo("test2"));
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);
                Assert.That(button1.HasLocalDataContext(), Is.False);

                panel.SetDataContext("panel");
                Assert.That(button1.GetDataContext(), Is.EqualTo("panel"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);

                form.ClearDataContext();
                Assert.That(panel.GetDataContext(), Is.EqualTo("panel"));
                Assert.That(panel.HasLocalDataContext(), Is.True);
                Assert.That(button1.GetDataContext(), Is.EqualTo("panel"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);

                form.SetDataContext("test2");
                Assert.That(panel.GetDataContext(), Is.EqualTo("panel"));
                Assert.That(panel.HasLocalDataContext(), Is.True);
                Assert.That(button1.GetDataContext(), Is.EqualTo("panel"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);

                panel.ClearDataContext();
                Assert.That(panel.GetDataContext(), Is.EqualTo("test2"));
                Assert.That(panel.HasLocalDataContext(), Is.False);
                Assert.That(button1.GetDataContext(), Is.EqualTo("test2"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);

                form.Controls.Clear();
                Assert.That(panel.GetDataContext(), Is.Null);
                Assert.That(panel.HasLocalDataContext(), Is.False);
                Assert.That(button1.GetDataContext(), Is.Null);
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);

                panel.SetDataContext("panel");
                Assert.That(button1.GetDataContext(), Is.EqualTo("panel"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);

                panel.Controls.Clear();
                Assert.That(button1.GetDataContext(), Is.Null);
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.GetDataContext(), Is.EqualTo("button2"));
                Assert.That(button2.HasLocalDataContext(), Is.True);
            }
        }
예제 #4
0
        public void InheritedDataContextBinding_BindAfterAddToTree()
        {
            using(var form = new Form()) {
                var button1 = new Button();
                var button2 = new Button();

                form.Controls.Add(button1);
                form.SetDataContext("test");
                form.Controls.Add(button2);

                button1.SetBinding("Text", new Binding());
                Assert.That(button1.Text, Is.EqualTo("test"));
                Assert.That(button1.HasLocalDataContext(), Is.False);

                button2.SetBinding("Text", new Binding());
                Assert.That(button2.Text, Is.EqualTo("test"));
                Assert.That(button2.HasLocalDataContext(), Is.False);

                form.SetDataContext("test2");
                Assert.That(button1.Text, Is.EqualTo("test2"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.Text, Is.EqualTo("test2"));
                Assert.That(button2.HasLocalDataContext(), Is.False);

                button1.SetDataContext("button1");
                Assert.That(button1.Text, Is.EqualTo("button1"));
                Assert.That(button1.HasLocalDataContext(), Is.True);
                button2.SetDataContext(null);
                Assert.That(button2.Text, Is.EqualTo(string.Empty));
                Assert.That(button2.HasLocalDataContext(), Is.True);

                button1.ClearDataContext();
                Assert.That(button1.Text, Is.EqualTo("test2"));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                button2.ClearDataContext();
                Assert.That(button2.Text, Is.EqualTo("test2"));
                Assert.That(button2.HasLocalDataContext(), Is.False);

                form.ClearDataContext();
                Assert.That(button1.Text, Is.EqualTo(string.Empty));
                Assert.That(button1.HasLocalDataContext(), Is.False);
                Assert.That(button2.Text, Is.EqualTo(string.Empty));
                Assert.That(button2.HasLocalDataContext(), Is.False);

                button1.SetDataContext("button1");
                Assert.That(button1.Text, Is.EqualTo("button1"));
                Assert.That(button1.HasLocalDataContext(), Is.True);

                form.SetDataContext("test");
                Assert.That(button1.Text, Is.EqualTo("button1"));
                Assert.That(button1.HasLocalDataContext(), Is.True);
                Assert.That(button2.Text, Is.EqualTo("test"));
                Assert.That(button2.HasLocalDataContext(), Is.False);

                form.Controls.Clear();
                Assert.That(button1.Text, Is.EqualTo("button1"));
                Assert.That(button2.Text, Is.EqualTo(string.Empty));
            }
        }