public void Clear_Invoke_Success()
        {
            var control    = new Control();
            var collection = new ControlBindingsCollection(control);
            var binding    = new Binding(null, new object(), "member");

            collection.Add(binding);
            Assert.Same(binding, Assert.Single(collection));
            Assert.Same(control, binding.BindableComponent);

            collection.Clear();
            Assert.Empty(collection);
            Assert.Null(binding.BindableComponent);

            // Clear again.
            collection.Clear();
            Assert.Empty(collection);
        }
Esempio n. 2
0
        private static void ClearBindings(ControlBindingsCollection b)
        {
            var bindings = new Binding[b.Count];

            b.CopyTo(bindings, 0);
            b.Clear();

            foreach (var binding in bindings)
            {
                TypeDescriptor.Refresh(binding.DataSource);
            }
        }
        public void CollectionChangingTest()
        {
            Control c = new Control();

            c.BindingContext = new BindingContext();
            c.CreateControl();

            ControlBindingsCollection binding_coll = c.DataBindings;

            Binding binding  = new Binding("Text", new MockItem("A", 0), "Text");
            Binding binding2 = new Binding("Name", new MockItem("B", 0), "Text");

            binding_coll.Add(binding);

            binding_coll.CollectionChanging += CollectionChangingHandler;

            collection_expected_count   = 1;
            collection_action_expected  = CollectionChangeAction.Add;
            collection_element_expected = binding2;
            collection_expected_assert  = "#A0";
            binding_coll.Add(binding2);
            Assert.IsTrue(collection_changing_called, "#A1");

            collection_changing_called  = false;
            collection_expected_count   = 2;
            collection_action_expected  = CollectionChangeAction.Remove;
            collection_element_expected = binding;
            collection_expected_assert  = "#B0";
            binding_coll.Remove(binding);
            Assert.IsTrue(collection_changing_called, "#B1");

            collection_changing_called  = false;
            collection_expected_count   = 1;
            collection_element_expected = null;
            collection_action_expected  = CollectionChangeAction.Refresh;
            collection_expected_assert  = "#C0";
            binding_coll.Clear();
            Assert.IsTrue(collection_changing_called, "#C1");
        }