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

            collection.Add(binding);

            Assert.Throws <ArgumentNullException>("dataBinding", () => collection.Remove(null));
            Assert.Same(binding, Assert.Single(collection));
        }
        public void Remove_NoSuchDataBinding_ThrowsArgumentException()
        {
            using var control = new Control();
            var collection = new ControlBindingsCollection(control);
            var binding1   = new Binding(null, new object(), "member");
            var binding2   = new Binding(null, new object(), "member");

            collection.Add(binding1);

            Assert.Throws <ArgumentException>("dataBinding", () => collection.Remove(binding2));
            Assert.Same(binding1, Assert.Single(collection));
        }
        public void Remove_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.Remove(binding);
            Assert.Empty(collection);
            Assert.Null(binding.BindableComponent);
        }
 private static void SetBinding(ControlBindingsCollection bindings, PropertyDescriptor property, DesignBinding designBinding)
 {
     if (designBinding != null)
     {
         Binding binding = bindings[property.Name];
         if (binding != null)
         {
             bindings.Remove(binding);
         }
         if (!designBinding.IsNull)
         {
             bindings.Add(property.Name, designBinding.DataSource, designBinding.DataMember);
         }
     }
 }
        public void Remove_DataBindingFromOtherCollection_ThrowsArgumentException()
        {
            var control1    = new Control();
            var control2    = new Control();
            var collection1 = new ControlBindingsCollection(control1);
            var collection2 = new ControlBindingsCollection(control2);
            var binding1    = new Binding(null, new object(), "member");
            var binding2    = new Binding(null, new object(), "member");

            collection1.Add(binding1);
            collection2.Add(binding2);

            Assert.Throws <ArgumentException>("dataBinding", () => collection2.Remove(binding1));
            Assert.Same(binding1, Assert.Single(collection1));
            Assert.Same(binding2, Assert.Single(collection2));
        }
        private static void SetBinding(ControlBindingsCollection bindings, PropertyDescriptor property, DesignBinding designBinding)
        {
            // this means it couldn't be parsed.
            if (designBinding == null)
            {
                return;
            }
            Binding listBinding = bindings[property.Name];

            if (listBinding != null)
            {
                bindings.Remove(listBinding);
            }
            if (!designBinding.IsNull)
            {
                bindings.Add(property.Name, designBinding.DataSource, designBinding.DataMember);
            }
        }
Exemplo n.º 7
0
        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");
        }