public void VectorChanged_ActionChangedToNonAction_ExceptionThrown()
        {
            ActionCollection actionCollection = new ActionCollection();
            actionCollection.Add(new StubAction());

            TestUtilities.AssertThrowsException(() => actionCollection[0] = new Button());
        }
        protected ActionCollection GetActionCollection(DependencyProperty collectionProperty)
        {
            ActionCollection actionCollection = (ActionCollection)this.GetValue(collectionProperty);
            if (actionCollection == null)
            {
                actionCollection = new ActionCollection();
                this.SetValue(collectionProperty, actionCollection);
            }

            return actionCollection;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Executes all actions in the <see cref="ActionCollection"/> and returns their results.
        /// </summary>
        /// <param name="sender">The <see cref="System.Object"/> which will be passed on to the action.</param>
        /// <param name="actions">The set of actions to execute.</param>
        /// <param name="parameter">The value of this parameter is determined by the calling behavior.</param>
        /// <returns>Returns the results of the actions.</returns>
        public static IEnumerable <object> ExecuteActions(object sender, ActionCollection actions, object parameter)
        {
            List <object> results = new List <object>();

            if (actions == null || Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                return(results);
            }

            foreach (DependencyObject dependencyObject in actions)
            {
                IAction action = (IAction)dependencyObject;
                results.Add(action.Execute(sender, parameter));
            }

            return(results);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Executes all actions in the <see cref="ActionCollection"/> and returns their results.
        /// </summary>
        /// <param name="sender">The <see cref="System.Object"/> which will be passed on to the action.</param>
        /// <param name="actions">The set of actions to execute.</param>
        /// <param name="parameter">The value of this parameter is determined by the calling behavior.</param>
        /// <returns>Returns the results of the actions.</returns>
        public static IEnumerable<object> ExecuteActions(object sender, ActionCollection actions, object parameter)
        {
            List<object> results = new List<object>();

            if (actions == null || Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                return results;
            }

            foreach (DependencyObject dependencyObject in actions)
            {
                IAction action = (IAction)dependencyObject;
                results.Add(action.Execute(sender, parameter));
            }

            return results;
        }
Exemplo n.º 5
0
        private void ActionCollection_VectorChanged(IObservableVector <DependencyObject> sender, IVectorChangedEventArgs eventArgs)
        {
            CollectionChange collectionChange = eventArgs.CollectionChange;

            if (collectionChange == CollectionChange.Reset)
            {
                foreach (DependencyObject item in this)
                {
                    ActionCollection.VerifyType(item);
                }
            }
            else if (collectionChange == CollectionChange.ItemInserted || collectionChange == CollectionChange.ItemChanged)
            {
                DependencyObject changedItem = this[(int)eventArgs.Index];
                ActionCollection.VerifyType(changedItem);
            }
        }
Exemplo n.º 6
0
        public void ExecuteActions_ActionsWithResults_ResultsInActionOrder()
        {
            string[] expectedReturnValues = { "A", "B", "C" };

            ActionCollection actions = new ActionCollection();

            foreach (string returnValue in expectedReturnValues)
            {
                actions.Add(new StubAction(returnValue));
            }

            List<object> results = Interaction.ExecuteActions(null, actions, null).ToList();

            Assert.AreEqual(expectedReturnValues.Length, results.Count, "Should have the same number of results as IActions.");

            for (int resultIndex = 0; resultIndex < results.Count; resultIndex++)
            {
                Assert.AreEqual(expectedReturnValues[resultIndex], results[resultIndex], "Results should be returned in the order of the actions in the ActionCollection.");
            }
        }
Exemplo n.º 7
0
        public void ExecuteActions_MultipleActions_AllActionsExecuted()
        {
            ActionCollection actions = new ActionCollection();
            actions.Add(new StubAction());
            actions.Add(new StubAction());
            actions.Add(new StubAction());

            Button sender = new Button();
            string parameterString = "TestString";

            Interaction.ExecuteActions(sender, actions, parameterString);

            foreach (StubAction action in actions)
            {
                Assert.AreEqual(1, action.ExecuteCount, "Each IAction should be executed once.");
                Assert.AreEqual(sender, action.Sender, "Sender is passed to the actions.");
                Assert.AreEqual(parameterString, action.Parameter, "Parameter is passed to the actions.");
            }
        }