Ejemplo n.º 1
0
        public void Bindings_AddAlreadyInSameManager_ThrowsArgumentException()
        {
            var manager = new PropertyManager();
            BindingsCollection collection = manager.Bindings;
            var binding = new Binding(null, new object(), "member");

            collection.Add(binding);
            Assert.Throws <ArgumentException>("dataBinding", () => collection.Add(binding));
        }
Ejemplo n.º 2
0
        public void Remove_InvokeWithCollectionChanging_CallsHandler()
        {
            var collection = new BindingsCollection();
            var binding    = new Binding(null, new object(), "member");

            int changingCallCount = 0;
            int changedCallCount  = 0;
            CollectionChangeEventHandler changingHandler = (sender, e) =>
            {
                Assert.Same(collection, sender);
                Assert.Equal(CollectionChangeAction.Remove, e.Action);
                Assert.Same(binding, e.Element);
                changingCallCount++;
                Assert.True(changingCallCount > changedCallCount);
            };
            CollectionChangeEventHandler changedHandler = (sender, e) =>
            {
                Assert.Same(collection, sender);
                Assert.Equal(CollectionChangeAction.Remove, e.Action);
                Assert.Same(binding, e.Element);
                changedCallCount++;
                Assert.Equal(changingCallCount, changedCallCount);
            };

            collection.Add(binding);
            collection.CollectionChanging += changingHandler;
            collection.CollectionChanged  += changedHandler;

            collection.Remove(binding);
            Assert.Equal(1, changingCallCount);
            Assert.Equal(1, changedCallCount);
            Assert.Empty(collection);

            // Add again.
            collection.CollectionChanging -= changingHandler;
            collection.CollectionChanged  -= changedHandler;
            collection.Add(binding);
            collection.CollectionChanging += changingHandler;
            collection.CollectionChanged  += changedHandler;

            collection.Remove(binding);
            Assert.Equal(2, changingCallCount);
            Assert.Equal(2, changedCallCount);
            Assert.Empty(collection);

            // Remove handler.
            collection.CollectionChanging -= changingHandler;
            collection.CollectionChanged  -= changedHandler;
            collection.Add(binding);

            collection.Remove(binding);
            Assert.Equal(2, changingCallCount);
            Assert.Equal(2, changedCallCount);
            Assert.Empty(collection);
        }
Ejemplo n.º 3
0
        public void Bindings_AddNull_ThrowsArgumentNullException()
        {
            var manager = new PropertyManager();
            BindingsCollection collection = manager.Bindings;

            Assert.Throws <ArgumentNullException>("dataBinding", () => collection.Add(null));
        }
Ejemplo n.º 4
0
        public void Bindings_Add_Success()
        {
            var manager = new PropertyManager();
            BindingsCollection collection = manager.Bindings;
            var binding = new Binding(null, new object(), "member");

            collection.Add(binding);
            Assert.Same(binding, Assert.Single(collection));
            Assert.Same(manager, binding.BindingManagerBase);
        }
Ejemplo n.º 5
0
        public void Remove_NullDataBinding_Nop()
        {
            var collection = new BindingsCollection();
            var binding    = new Binding(null, new object(), "member");

            collection.Add(binding);

            collection.Remove(null);
            Assert.Same(binding, Assert.Single(collection));
        }
Ejemplo n.º 6
0
        public void RemoveAt_Invoke_Success()
        {
            var collection = new BindingsCollection();
            var binding    = new Binding(null, new object(), "member");

            collection.Add(binding);

            collection.RemoveAt(0);
            Assert.Empty(collection);
        }
Ejemplo n.º 7
0
        public void Bindings_AddAlreadyInDifferentManager_ThrowsArgumentException()
        {
            var manager1 = new PropertyManager();
            var manager2 = new PropertyManager();
            BindingsCollection collection1 = manager1.Bindings;
            BindingsCollection collection2 = manager2.Bindings;
            var binding = new Binding(null, new object(), "member");

            collection1.Add(binding);
            Assert.Throws <ArgumentException>("dataBinding", () => collection2.Add(binding));
        }
Ejemplo n.º 8
0
        public void Bindings_RemoveNullDataBinding_ThrowsArgumentNullException()
        {
            var manager = new PropertyManager();
            BindingsCollection collection = manager.Bindings;
            var binding = new Binding(null, new object(), "member");

            collection.Add(binding);

            Assert.Throws <ArgumentNullException>("dataBinding", () => collection.Remove(null));
            Assert.Same(binding, Assert.Single(collection));
        }
Ejemplo n.º 9
0
        public void Add_Invoke_Success()
        {
            var collection = new BindingsCollection();
            var binding    = new Binding(null, new object(), "member");

            collection.Add(binding);

            Assert.Equal(1, collection.Count);
            Assert.Same(binding, collection[0]);
            Assert.True(collection.ShouldSerializeMyAll());
        }
Ejemplo n.º 10
0
        public void Remove_DataBindingFromOtherCollection_Nop()
        {
            var collection1 = new BindingsCollection();
            var collection2 = new BindingsCollection();
            var binding1    = new Binding(null, new object(), "member");
            var binding2    = new Binding(null, new object(), "member");

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

            collection2.Remove(binding1);
            Assert.Same(binding1, Assert.Single(collection1));
            Assert.Same(binding2, Assert.Single(collection2));
        }
Ejemplo n.º 11
0
        public void Clear_Invoke_Success()
        {
            var collection = new BindingsCollection();
            var binding    = new Binding(null, new object(), "member");

            collection.Add(binding);

            collection.Clear();
            Assert.Empty(collection);

            // Clear again.
            collection.Clear();
            Assert.Empty(collection);
        }
Ejemplo n.º 12
0
        public void Bindings_RemoveDataBindingFromOtherCollection_ThrowsArgumentException()
        {
            var manager1 = new PropertyManager();
            var manager2 = new PropertyManager();
            BindingsCollection collection1 = manager1.Bindings;
            BindingsCollection collection2 = manager2.Bindings;
            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));
        }
Ejemplo n.º 13
0
        public void Add_NullDataBinding_ThrowsArgumentNullException()
        {
            var collection = new BindingsCollection();

            Assert.Throws <ArgumentNullException>("dataBinding", () => collection.Add(null));
        }