コード例 #1
0
ファイル: EventTriggerTest.cs プロジェクト: zhamppx97/maui
        public void TestTriggerActionInvoked()
        {
            var bindable      = new MockBindableWithEvent();
            var triggeraction = new MockTriggerAction();
            var eventtrigger  = new EventTrigger()
            {
                Event = "MockEvent", Actions = { triggeraction }
            };
            var collection = bindable.Triggers;

            collection.Add(eventtrigger);

            Assert.False(triggeraction.Invoked);
            bindable.FireEvent();
            Assert.True(triggeraction.Invoked);
        }
コード例 #2
0
ファイル: EventTriggerTest.cs プロジェクト: zhamppx97/maui
        public void TestChangeEventOnEventTrigger()
        {
            var bindable      = new MockBindableWithEvent();
            var triggeraction = new MockTriggerAction();
            var eventtrigger  = new EventTrigger {
                Event = "MockEvent", Actions = { triggeraction }
            };
            var collection = bindable.Triggers;

            collection.Add(eventtrigger);

            triggeraction.Invoked = false;
            Assert.False(triggeraction.Invoked);
            bindable.FireEvent();
            Assert.True(triggeraction.Invoked);

            triggeraction.Invoked = false;
            Assert.False(triggeraction.Invoked);
            bindable.FireEvent2();
            Assert.False(triggeraction.Invoked);

            Assert.Throws <InvalidOperationException>(() => eventtrigger.Event = "MockEvent2");
        }
コード例 #3
0
ファイル: TriggerTests.cs プロジェクト: zhamppx97/maui
        public void EnterAndExitActionsTriggered()
        {
            var conditionbp = BindableProperty.Create("foo", typeof(string), typeof(BindableObject), null);
            var element     = new MockElement();
            var enteraction = new MockTriggerAction();
            var exitaction  = new MockTriggerAction();
            var trigger     = new Trigger(typeof(VisualElement))
            {
                Property     = conditionbp,
                Value        = "foobar",
                EnterActions =
                {
                    enteraction
                },
                ExitActions =
                {
                    exitaction
                }
            };

            Assert.False(enteraction.Invoked);
            Assert.False(exitaction.Invoked);
            element.Triggers.Add(trigger);
            Assert.False(enteraction.Invoked);
            Assert.False(exitaction.Invoked);
            element.SetValue(conditionbp, "foobar");
            Assert.True(enteraction.Invoked);
            Assert.False(exitaction.Invoked);

            enteraction.Invoked = exitaction.Invoked = false;
            Assert.False(enteraction.Invoked);
            Assert.False(exitaction.Invoked);
            element.SetValue(conditionbp, "");
            Assert.False(enteraction.Invoked);
            Assert.True(exitaction.Invoked);
        }