Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 29 additions & 32 deletions Test/UnitTests/EventTriggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void Constructor_DefaultConstructor_SetsEventNameToLoaded()
public void Constructor_EventNameConstructor_SetsEventNameToSpecifiedValue()
{
EventTrigger eventTrigger = new EventTrigger("Click");
Assert.AreEqual(eventTrigger.EventName, "Click", "eventTrigger.EventName == Click");
Assert.AreEqual("Click", eventTrigger.EventName, "eventTrigger.EventName == Click");
}

[TestMethod]
Expand All @@ -135,7 +135,7 @@ public void EventFired_SimpleEvent_Fires()
StubAction eventAction = AttachTriggerToObject(eventTrigger, eventStub);

eventStub.FireStubEvent();
Assert.AreEqual(eventAction.InvokeCount, 1, "Action was invoked in response to event.");
Assert.AreEqual(1, eventAction.InvokeCount, "Action was invoked in response to event.");
}

[TestMethod]
Expand Down Expand Up @@ -167,7 +167,7 @@ public void EventFired_EventFiredOnSourceNameObject_Fires()
System.Windows.RoutedEventArgs args = CreateClickEvent();

button.RaiseEvent(args);
Assert.AreEqual(action.InvokeCount, 1, "Click on button while Source=button should not invoke the action.");
Assert.AreEqual(1, action.InvokeCount, "Click on button while Source=button should not invoke the action.");
}
}

Expand All @@ -190,7 +190,7 @@ public void EventFired_EventFiredOnAssociatedObjectWhenSourceNameObjectIsDiffere
System.Windows.RoutedEventArgs args = CreateClickEvent();

rect.RaiseEvent(args);
Assert.AreEqual(action.InvokeCount, 0, "Click on rect while Source=button should not invoke the action.");
Assert.AreEqual(0, action.InvokeCount, "Click on rect while Source=button should not invoke the action.");
}
}

Expand All @@ -205,7 +205,7 @@ public void SourceObjectEventFired_EventNameMatchesFiredEvent_Fires()
eventTrigger.SourceObject = eventSource;
eventSource.FireStubEvent();

Assert.AreEqual(action.InvokeCount, 1, "Trigger should be invoked when source object fires the event it is listening to.");
Assert.AreEqual(1, action.InvokeCount, "Trigger should be invoked when source object fires the event it is listening to.");
}

[TestMethod]
Expand All @@ -220,7 +220,7 @@ public void EventFired_OldEventFiredAfterEventNameChanged_DoesNotFires()
eventTrigger.EventName = "StubEvent2";
eventSource.FireStubEvent();

Assert.AreEqual(action.InvokeCount, 0, "Trigger should not be invoked when source object fires its event it is not listening to.");
Assert.AreEqual(0, action.InvokeCount, "Trigger should not be invoked when source object fires its event it is not listening to.");
}

[TestMethod]
Expand All @@ -235,7 +235,7 @@ public void EventFired_NewEventFiredAfterEventNameChanged_Fires()
eventTrigger.EventName = "StubEvent2";
eventSource.FireStubEvent2();

Assert.AreEqual(action.InvokeCount, 1, "Trigger should be invoked when source object fires the event it is listening to.");
Assert.AreEqual(1, action.InvokeCount, "Trigger should be invoked when source object fires the event it is listening to.");
}

[TestMethod]
Expand All @@ -251,7 +251,7 @@ public void EventFired_OldSourceObjectFiresEvent_DoesNotFire()
eventTrigger.SourceObject = newEventSource;
oldEventSource.FireStubEvent();

Assert.AreEqual(action.InvokeCount, 0, "Trigger should not be invoked when an old source object fires the event it is listening to.");
Assert.AreEqual(0, action.InvokeCount, "Trigger should not be invoked when an old source object fires the event it is listening to.");
}

[TestMethod]
Expand Down Expand Up @@ -295,7 +295,7 @@ public void EventNameSet_IncompatibleEventSignatureWithNoSourceObject_DoesNothin
EventObjectStub eventStub = CreateEventObjectStub();
AttachTriggerToObject(eventTrigger, eventStub);
eventTrigger.EventName = "IntEvent";
// With no source object set, non-existant event did not throw.
// With no source object set, non-existent event did not throw.
}

[TestMethod]
Expand All @@ -310,7 +310,7 @@ public void NonDependencyObjectEventSource_EventFired_InvokesActions()
StubAction action = AttachTriggerToObject(eventTrigger, host);

clrEventClass.Fire();
Assert.AreEqual(action.InvokeCount, 1, "Event firing on a source CLR object should fire the EventTrigger.");
Assert.AreEqual(1, action.InvokeCount, "Event firing on a source CLR object should fire the EventTrigger.");
}

[TestMethod]
Expand All @@ -335,9 +335,9 @@ public void EventFired_SourceObjectAndSourceNameSet_ListensOnlyToSourceObject()
System.Windows.RoutedEventArgs args = CreateClickEvent();

sourceNameButton.RaiseEvent(args);
Assert.AreEqual(action.InvokeCount, 0, "Click on source name button when SourceObject is set to another object should not invoke the action.");
Assert.AreEqual(0, action.InvokeCount, "Click on source name button when SourceObject is set to another object should not invoke the action.");
sourceButton.RaiseEvent(args);
Assert.AreEqual(action.InvokeCount, 1, "Click on source object button should invoke the action.");
Assert.AreEqual(1, action.InvokeCount, "Click on source object button should invoke the action.");
}
}

Expand All @@ -364,38 +364,35 @@ public void EventFired_SourceObjectChangesToNull_ListensToSourceName()
System.Windows.RoutedEventArgs args = CreateClickEvent();

sourceButton.RaiseEvent(args);
Assert.AreEqual(action.InvokeCount, 0, "Click on source object button should not invoke the action, as the SourceObject has been cleared.");
Assert.AreEqual(0, action.InvokeCount, "Click on source object button should not invoke the action, as the SourceObject has been cleared.");
sourceNameButton.RaiseEvent(args);
Assert.AreEqual(action.InvokeCount, 1, "Click on source name button when SourceObject has been cleared should invoke the action.");
Assert.AreEqual(1, action.InvokeCount, "Click on source name button when SourceObject has been cleared should invoke the action.");
}
}

[TestMethod]
public void TestLoadedEvent()
{
Rectangle rectangle = new Rectangle();
EventTrigger eventTrigger1 = new EventTrigger("Loaded");
EventTrigger eventTrigger2 = new EventTrigger("MouseLeftButtonDown");
Button button = CreateButton();
EventTrigger eventTrigger = new EventTrigger("Loaded");
StubAction loadedAction = new StubAction();
StubAction mouseDownAction = new StubAction();
System.Windows.RoutedEventArgs clickArgs = CreateClickEvent();

eventTrigger1.Actions.Add(loadedAction);
eventTrigger1.Attach(rectangle);
eventTrigger.Actions.Add(loadedAction);
eventTrigger.Attach(button);

using (StubWindow window = new StubWindow(rectangle))
using (StubWindow window = new StubWindow(button))
{
Assert.AreEqual(loadedAction.InvokeCount, 1, "Loaded action was invoked");
eventTrigger1.EventName = "GotMouseCapture";
rectangle.CaptureMouse();
Assert.AreEqual(loadedAction.InvokeCount, 2, "GotMouseCapture action was invoked");
rectangle.ReleaseMouseCapture();
eventTrigger1.EventName = "Loaded";
rectangle.CaptureMouse();
Assert.AreEqual(loadedAction.InvokeCount, 2, "GotMouseCapture action was not invoked");
rectangle.ReleaseMouseCapture();
Assert.AreEqual(1, loadedAction.InvokeCount, "Loaded action was invoked");
eventTrigger.EventName = "Click";
button.RaiseEvent(clickArgs);
Assert.AreEqual(2, loadedAction.InvokeCount, "Click action was invoked");
eventTrigger.EventName = "Loaded";
button.RaiseEvent(clickArgs);
Assert.AreEqual(2, loadedAction.InvokeCount, "Click action was not invoked");
}
eventTrigger1.Detach();
Assert.IsNull(((IAttachedObject)eventTrigger1).AssociatedObject, "Trigger was detached");
eventTrigger.Detach();
Assert.IsNull(((IAttachedObject)eventTrigger).AssociatedObject, "Trigger was detached");
}

#endregion
Expand Down