public void RemoveValueChanged() { MockPropertyDescriptor pd = new MockPropertyDescriptor( "Name", new Attribute [0]); object compA = new object(); object compB = new object(); EventHandler handlerA = new EventHandler(ValueChanged1); EventHandler handlerB = new EventHandler(ValueChanged1); EventHandler handlerC = new EventHandler(ValueChanged2); pd.AddValueChanged(compA, handlerA); pd.AddValueChanged(compA, handlerC); pd.AddValueChanged(compA, handlerC); pd.AddValueChanged(compA, handlerB); pd.AddValueChanged(compB, handlerC); pd.FireValueChanged(compA, new EventArgs()); Assert.AreEqual(4, _invokedHandlers.Count, "#A1"); pd.RemoveValueChanged(new object(), handlerC); pd.FireValueChanged(compA, new EventArgs()); Assert.AreEqual(8, _invokedHandlers.Count, "#A2"); Reset(); pd.RemoveValueChanged(compA, handlerC); pd.FireValueChanged(compA, new EventArgs()); Assert.AreEqual(3, _invokedHandlers.Count, "#B1"); Assert.AreEqual("ValueChanged1", _invokedHandlers [0], "#B2"); Assert.AreEqual("ValueChanged2", _invokedHandlers [1], "#B3"); Assert.AreEqual("ValueChanged1", _invokedHandlers [2], "#B4"); Reset(); pd.FireValueChanged(compB, new EventArgs()); Assert.AreEqual(1, _invokedHandlers.Count, "#C1"); Assert.AreEqual("ValueChanged2", _invokedHandlers [0], "#C2"); Reset(); pd.RemoveValueChanged(compB, handlerC); pd.FireValueChanged(compB, new EventArgs()); Assert.AreEqual(0, _invokedHandlers.Count, "#D"); }
public void RemoveValueChanged_Handler_Null() { MockPropertyDescriptor pd = new MockPropertyDescriptor( "Name", new Attribute [0]); try { pd.RemoveValueChanged(new object(), (EventHandler)null); Assert.Fail("#1"); } catch (ArgumentNullException ex) { Assert.AreEqual(typeof(ArgumentNullException), ex.GetType(), "#2"); Assert.IsNull(ex.InnerException, "#3"); Assert.IsNotNull(ex.Message, "#4"); Assert.IsNotNull(ex.ParamName, "#5"); Assert.AreEqual("handler", ex.ParamName, "#6"); } }
public void GetValueChangedHandler() { object compA = new object(); object compB = new object(); EventHandler handlerA = new EventHandler(ValueChanged1); EventHandler handlerB = new EventHandler(ValueChanged1); EventHandler handlerC = new EventHandler(ValueChanged2); MockPropertyDescriptor pd = new MockPropertyDescriptor( "Name", new Attribute [0]); Assert.IsNull(pd.GetValueChangedHandler(null), "#A1"); Assert.IsNull(pd.GetValueChangedHandler(compA), "#A2"); Assert.IsNull(pd.GetValueChangedHandler(compB), "#A3"); pd.AddValueChanged(compA, handlerA); Assert.IsNull(pd.GetValueChangedHandler(null), "#B1"); Assert.AreSame(handlerA, pd.GetValueChangedHandler(compA), "#B2"); Assert.IsNull(pd.GetValueChangedHandler(compB), "#B3"); pd.AddValueChanged(compA, handlerB); Assert.IsNull(pd.GetValueChangedHandler(null), "#C1"); EventHandler handler = pd.GetValueChangedHandler(compA); Assert.AreEqual(2, handler.GetInvocationList().Length, "#C2"); Assert.AreEqual(handlerA, handler.GetInvocationList() [0], "#C3"); Assert.AreEqual(handlerB, handler.GetInvocationList() [1], "#C4"); Assert.IsNull(pd.GetValueChangedHandler(compB), "#C5"); pd.AddValueChanged(compB, handlerA); Assert.IsNull(pd.GetValueChangedHandler(null), "#D1"); handler = pd.GetValueChangedHandler(compA); Assert.AreEqual(2, handler.GetInvocationList().Length, "#D2"); Assert.AreSame(handlerA, pd.GetValueChangedHandler(compB), "#D3"); pd.RemoveValueChanged(compB, handlerB); Assert.IsNull(pd.GetValueChangedHandler(null), "#E1"); handler = pd.GetValueChangedHandler(compA); Assert.AreEqual(2, handler.GetInvocationList().Length, "#E2"); Assert.IsNull(pd.GetValueChangedHandler(compB), "#E3"); pd.RemoveValueChanged(compB, handlerB); Assert.IsNull(pd.GetValueChangedHandler(null), "#F1"); handler = pd.GetValueChangedHandler(compA); Assert.AreEqual(2, handler.GetInvocationList().Length, "#F2"); Assert.IsNull(pd.GetValueChangedHandler(compB), "#F3"); pd.RemoveValueChanged(compA, handlerC); Assert.IsNull(pd.GetValueChangedHandler(null), "#G1"); handler = pd.GetValueChangedHandler(compA); Assert.AreEqual(2, handler.GetInvocationList().Length, "#G2"); Assert.IsNull(pd.GetValueChangedHandler(compB), "#G3"); pd.AddValueChanged(compA, handlerC); Assert.IsNull(pd.GetValueChangedHandler(null), "#H1"); handler = pd.GetValueChangedHandler(compA); Assert.AreEqual(3, handler.GetInvocationList().Length, "#H2"); Assert.IsNull(pd.GetValueChangedHandler(compB), "#H3"); pd.RemoveValueChanged(compA, handlerB); Assert.IsNull(pd.GetValueChangedHandler(null), "#I1"); handler = pd.GetValueChangedHandler(compA); Assert.AreEqual(2, handler.GetInvocationList().Length, "#I2"); Assert.AreEqual(handlerA, handler.GetInvocationList() [0], "#I3"); Assert.AreEqual(handlerC, handler.GetInvocationList() [1], "#I4"); Assert.IsNull(pd.GetValueChangedHandler(compB), "#I5"); }
public void RemoveValueChanged () { MockPropertyDescriptor pd = new MockPropertyDescriptor ( "Name", new Attribute [0]); object compA = new object (); object compB = new object (); EventHandler handlerA = new EventHandler (ValueChanged1); EventHandler handlerB = new EventHandler (ValueChanged1); EventHandler handlerC = new EventHandler (ValueChanged2); pd.AddValueChanged (compA, handlerA); pd.AddValueChanged (compA, handlerC); pd.AddValueChanged (compA, handlerC); pd.AddValueChanged (compA, handlerB); pd.AddValueChanged (compB, handlerC); pd.FireValueChanged (compA, new EventArgs ()); Assert.AreEqual (4, _invokedHandlers.Count, "#A1"); pd.RemoveValueChanged (new object (), handlerC); pd.FireValueChanged (compA, new EventArgs ()); Assert.AreEqual (8, _invokedHandlers.Count, "#A2"); Reset (); pd.RemoveValueChanged (compA, handlerC); pd.FireValueChanged (compA, new EventArgs ()); Assert.AreEqual (3, _invokedHandlers.Count, "#B1"); Assert.AreEqual ("ValueChanged1", _invokedHandlers [0], "#B2"); Assert.AreEqual ("ValueChanged2", _invokedHandlers [1], "#B3"); Assert.AreEqual ("ValueChanged1", _invokedHandlers [2], "#B4"); Reset (); pd.FireValueChanged (compB, new EventArgs ()); Assert.AreEqual (1, _invokedHandlers.Count, "#C1"); Assert.AreEqual ("ValueChanged2", _invokedHandlers [0], "#C2"); Reset (); pd.RemoveValueChanged (compB, handlerC); pd.FireValueChanged (compB, new EventArgs ()); Assert.AreEqual (0, _invokedHandlers.Count, "#D"); }
public void GetValueChangedHandler () { object compA = new object (); object compB = new object (); EventHandler handlerA = new EventHandler (ValueChanged1); EventHandler handlerB = new EventHandler (ValueChanged1); EventHandler handlerC = new EventHandler (ValueChanged2); MockPropertyDescriptor pd = new MockPropertyDescriptor ( "Name", new Attribute [0]); Assert.IsNull (pd.GetValueChangedHandler (null), "#A1"); Assert.IsNull (pd.GetValueChangedHandler (compA), "#A2"); Assert.IsNull (pd.GetValueChangedHandler (compB), "#A3"); pd.AddValueChanged (compA, handlerA); Assert.IsNull (pd.GetValueChangedHandler (null), "#B1"); Assert.AreSame (handlerA, pd.GetValueChangedHandler (compA), "#B2"); Assert.IsNull (pd.GetValueChangedHandler (compB), "#B3"); pd.AddValueChanged (compA, handlerB); Assert.IsNull (pd.GetValueChangedHandler (null), "#C1"); EventHandler handler = pd.GetValueChangedHandler (compA); Assert.AreEqual (2, handler.GetInvocationList ().Length, "#C2"); Assert.AreEqual (handlerA, handler.GetInvocationList () [0], "#C3"); Assert.AreEqual (handlerB, handler.GetInvocationList () [1], "#C4"); Assert.IsNull (pd.GetValueChangedHandler (compB), "#C5"); pd.AddValueChanged (compB, handlerA); Assert.IsNull (pd.GetValueChangedHandler (null), "#D1"); handler = pd.GetValueChangedHandler (compA); Assert.AreEqual (2, handler.GetInvocationList ().Length, "#D2"); Assert.AreSame (handlerA, pd.GetValueChangedHandler (compB), "#D3"); pd.RemoveValueChanged (compB, handlerB); Assert.IsNull (pd.GetValueChangedHandler (null), "#E1"); handler = pd.GetValueChangedHandler (compA); Assert.AreEqual (2, handler.GetInvocationList ().Length, "#E2"); Assert.IsNull (pd.GetValueChangedHandler (compB), "#E3"); pd.RemoveValueChanged (compB, handlerB); Assert.IsNull (pd.GetValueChangedHandler (null), "#F1"); handler = pd.GetValueChangedHandler (compA); Assert.AreEqual (2, handler.GetInvocationList ().Length, "#F2"); Assert.IsNull (pd.GetValueChangedHandler (compB), "#F3"); pd.RemoveValueChanged (compA, handlerC); Assert.IsNull (pd.GetValueChangedHandler (null), "#G1"); handler = pd.GetValueChangedHandler (compA); Assert.AreEqual (2, handler.GetInvocationList ().Length, "#G2"); Assert.IsNull (pd.GetValueChangedHandler (compB), "#G3"); pd.AddValueChanged (compA, handlerC); Assert.IsNull (pd.GetValueChangedHandler (null), "#H1"); handler = pd.GetValueChangedHandler (compA); Assert.AreEqual (3, handler.GetInvocationList ().Length, "#H2"); Assert.IsNull (pd.GetValueChangedHandler (compB), "#H3"); pd.RemoveValueChanged (compA, handlerB); Assert.IsNull (pd.GetValueChangedHandler (null), "#I1"); handler = pd.GetValueChangedHandler (compA); Assert.AreEqual (2, handler.GetInvocationList ().Length, "#I2"); Assert.AreEqual (handlerA, handler.GetInvocationList () [0], "#I3"); Assert.AreEqual (handlerC, handler.GetInvocationList () [1], "#I4"); Assert.IsNull (pd.GetValueChangedHandler (compB), "#I5"); }
public void RemoveValueChanged_Handler_Null () { MockPropertyDescriptor pd = new MockPropertyDescriptor ( "Name", new Attribute [0]); try { pd.RemoveValueChanged (new object (), (EventHandler) null); Assert.Fail ("#1"); } catch (ArgumentNullException ex) { Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); Assert.IsNotNull (ex.ParamName, "#5"); Assert.AreEqual ("handler", ex.ParamName, "#6"); } }