示例#1
0
        public void Test_FilterBehavior_Detached()
        {
            // Arrange.
            var items      = new ObservableCollection <string>();
            var viewSource = new CollectionViewSource
            {
                Source = items
            };

            var filter = CreateFilter();

            var action = new CollectionViewSourceFilter();

            action.Attach(viewSource);
            action.Filter = filter;

            var trigger = new EventTrigger {
                EventName = "Filter"
            };

            trigger.Attach(viewSource);
            trigger.Actions.Add(action);

            // Act.
            action.Detach();
            trigger.Detach();
            items.Add("item");                  // Trigger a view refresh.

            // Assert.
            Assert.False(filterInvocations[0]);
        }
示例#2
0
        public void EventTriggerTest()
        {
            Assert.IsInstanceOfType(new EventTrigger(), typeof(EventTrigger));

            var textBox      = new TextBox();
            var eventTrigger = new EventTrigger(nameof(textBox.TextChanged));
            var action       = new TestTriggerAction
            {
                IsEnabled = true
            };

            Assert.IsTrue(action.IsEnabled);

            eventTrigger.Actions.Add(action);
            eventTrigger.Attach(textBox);
            textBox.RaiseEvent(new TextChangedEventArgs(TextBoxBase.TextChangedEvent, UndoAction.None));
            Assert.IsTrue(action.Invoked);
            Assert.ThrowsException <ArgumentException>(() => eventTrigger.EventName = "test");

            // for code coverage
            action.Attach(textBox);
            eventTrigger.Actions.Remove(action);
            eventTrigger.Actions.Add(action);
            eventTrigger.Detach();
        }
示例#3
0
        public void TestLoadedEvent()
        {
            Rectangle    rectangle       = new Rectangle();
            EventTrigger eventTrigger1   = new EventTrigger("Loaded");
            EventTrigger eventTrigger2   = new EventTrigger("MouseLeftButtonDown");
            StubAction   loadedAction    = new StubAction();
            StubAction   mouseDownAction = new StubAction();

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

            using (StubWindow window = new StubWindow(rectangle))
            {
                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();
            }
            eventTrigger1.Detach();
            Assert.IsNull(((IAttachedObject)eventTrigger1).AssociatedObject, "Trigger was detached");
        }