public void WhenSourceObjectIsSet_ShouldSubscribeToRaisedEvent()
        {
            InteractionRequest <INotification> request = new InteractionRequest <INotification>();
            TestableInteractionRequestTrigger  trigger = new TestableInteractionRequestTrigger();
            DependencyObject associatedObject          = new DependencyObject();

            trigger.Attach(associatedObject);
            trigger.SourceObject = request;

            Assert.IsTrue(trigger.ExecutionCount == 0);

            request.Raise(new Notification());
            Assert.IsTrue(trigger.ExecutionCount == 1);
        }
        public void WhenEventIsRaised_ShouldExecuteTriggerActions()
        {
            InteractionRequest <INotification> request = new InteractionRequest <INotification>();
            TestableInteractionRequestTrigger  trigger = new TestableInteractionRequestTrigger();
            DependencyObject      associatedObject     = new DependencyObject();
            TestableTriggerAction action = new TestableTriggerAction();

            trigger.Actions.Add(action);
            trigger.Attach(associatedObject);
            trigger.SourceObject = request;

            Assert.IsTrue(action.ExecutionCount == 0);

            request.Raise(new Notification());
            Assert.IsTrue(action.ExecutionCount == 1);
        }
示例#3
0
        public async Task WhenEventIsRaisedAsync_NotificationIsPassedBackAsync()
        {
            var request          = new InteractionRequest <INotification>();
            var trigger          = new TestableInteractionRequestTrigger();
            var associatedObject = new DependencyObject();
            var action           = new TestableTriggerAction();
            var notification     = new Notification();

            trigger.Actions.Add(action);
            trigger.Attach(associatedObject);
            trigger.SourceObject = request;

            Assert.IsTrue(action.ExecutionCount == 0);

            var result = await request.RaiseAsync(notification);

            Assert.IsTrue(action.ExecutionCount == 1);
            Assert.ReferenceEquals(notification, result);
        }
示例#4
0
        public void WhenAssociatedObjectIsUnloadedAndDiscarded_ShouldBeGarbageCollected()
        {
            InteractionRequest <INotification> request = new InteractionRequest <INotification>();
            TestableInteractionRequestTrigger  trigger = new TestableInteractionRequestTrigger();
            MockFrameworkElement associatedObject      = new MockFrameworkElement();

            trigger.Attach(associatedObject);
            trigger.SourceObject = request;

            WeakReference weakTrigger = new WeakReference(trigger);

            trigger = null;

            GC.Collect();
            Assert.IsTrue(weakTrigger.IsAlive);

            associatedObject.RaiseUnloaded();
            associatedObject = null;
            GC.Collect();
            Assert.IsFalse(weakTrigger.IsAlive);
        }
示例#5
0
        public void WhenAssociatedObjectIsReloaded_ShouldReactToEventBeingRaisedAgain()
        {
            InteractionRequest <INotification> request = new InteractionRequest <INotification>();
            TestableInteractionRequestTrigger  trigger = new TestableInteractionRequestTrigger();
            MockFrameworkElement associatedObject      = new MockFrameworkElement();

            trigger.Attach(associatedObject);
            trigger.SourceObject = request;

            Assert.IsTrue(trigger.ExecutionCount == 0);

            request.Raise(new Notification());
            Assert.IsTrue(trigger.ExecutionCount == 1);

            associatedObject.RaiseUnloaded();
            request.Raise(new Notification());
            Assert.IsTrue(trigger.ExecutionCount == 1);

            associatedObject.RaiseLoaded();
            request.Raise(new Notification());
            Assert.IsTrue(trigger.ExecutionCount == 2);
        }