public void ReparentActionTest() { SysWindows.Shapes.Rectangle hostRectangle = new SysWindows.Shapes.Rectangle(); // try parenting an action more than once; should throw StubAction action = new StubAction(); StubTrigger trigger1 = new StubTrigger(); StubTrigger trigger2 = new StubTrigger(); trigger1.Attach(hostRectangle); trigger2.Attach(hostRectangle); trigger1.Actions.Add(action); try { trigger2.Actions.Add(action); Debug.Fail("Expected InvalidOperationException to be thrown after adding an action to a second trigger."); } catch (InvalidOperationException) { } // now try the same, properly unhooking before reparenting action = new StubAction(); trigger1 = new StubTrigger(); trigger2 = new StubTrigger(); trigger1.Actions.Add(action); trigger1.Actions.Remove(action); trigger2.Actions.Add(action); Assert.AreEqual(((IAttachedObject)action).AssociatedObject, trigger2.HostObject, "action.AssociatedObject == trigger2.Host"); Assert.AreEqual(trigger2.Actions.Count, 1, "trigger2.Actions.Count == 1"); }
private StubTrigger SetupRemoveAction(DependencyObject target) { StubTrigger trigger = new StubTrigger(); RemoveElementAction action = new RemoveElementAction(); trigger.Actions.Add(action); trigger.Attach(target); return(trigger); }