public void Ctor_Default() { var collection = new SubBindingsCollection(); Assert.Equal(0, collection.Count); Assert.Empty(collection.List); Assert.False(collection.ShouldSerializeMyAll()); }
public void RemoveCore_NullDataBinding_Nop() { var collection = new SubBindingsCollection(); var binding = new Binding(null, new object(), "member"); collection.Add(binding); collection.RemoveCore(null); Assert.Same(binding, Assert.Single(collection)); }
public void RemoveCore_Invoke_Success() { var collection = new SubBindingsCollection(); var binding = new Binding(null, new object(), "member"); collection.Add(binding); collection.RemoveCore(binding); Assert.Empty(collection); }
public void RemoveCore_InvokeWithCollectionChanging_DoesNotCallHandler() { var collection = new SubBindingsCollection(); 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.RemoveCore(binding); Assert.Equal(0, changingCallCount); Assert.Equal(0, changedCallCount); Assert.Empty(collection); // Add again. collection.CollectionChanging -= changingHandler; collection.CollectionChanged -= changedHandler; collection.Add(binding); collection.CollectionChanging += changingHandler; collection.CollectionChanged += changedHandler; collection.RemoveCore(binding); Assert.Equal(0, changingCallCount); Assert.Equal(0, changedCallCount); Assert.Empty(collection); // Remove handler. collection.CollectionChanging -= changingHandler; collection.CollectionChanged -= changedHandler; collection.Add(binding); collection.RemoveCore(binding); Assert.Equal(0, changingCallCount); Assert.Equal(0, changedCallCount); Assert.Empty(collection); }
public void AddCore_Invoke_Success() { var collection = new SubBindingsCollection(); var binding = new Binding(null, new object(), "member"); collection.AddCore(binding); Assert.Equal(1, collection.Count); Assert.Same(binding, collection[0]); Assert.True(collection.ShouldSerializeMyAll()); }
public void RemoveCore_DataBindingFromOtherCollection_Nop() { var collection1 = new SubBindingsCollection(); var collection2 = new SubBindingsCollection(); var binding1 = new Binding(null, new object(), "member"); var binding2 = new Binding(null, new object(), "member"); collection1.Add(binding1); collection2.Add(binding2); collection2.RemoveCore(binding1); Assert.Same(binding1, Assert.Single(collection1)); Assert.Same(binding2, Assert.Single(collection2)); }
public void OnCollectionChanged_Invoke_CallsHandler() { var collection = new SubBindingsCollection(); var eventArgs = new CollectionChangeEventArgs(CollectionChangeAction.Refresh, null); int callCount = 0; CollectionChangeEventHandler handler = (sender, e) => { Assert.Same(collection, sender); Assert.Same(eventArgs, e); callCount++; }; // Call with handler. collection.CollectionChanged += handler; collection.OnCollectionChanged(eventArgs); Assert.Equal(1, callCount); // Remove handler. collection.CollectionChanged -= handler; collection.OnCollectionChanged(eventArgs); Assert.Equal(1, callCount); }
public void AddCore_NullDataBinding_ThrowsArgumentNullException() { var collection = new SubBindingsCollection(); Assert.Throws <ArgumentNullException>("dataBinding", () => collection.AddCore(null)); }