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);
        }
        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);
        }
        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);
        }