Exemplo n.º 1
0
        /// <summary>
        /// Retrieves the reactions with the provided action and type.
        /// </summary>
        /// <param name="action">The action that the reaction performs.</param>
        /// <param name="typeName">The type of entity involved in the reaction</param>
        /// <returns>The reaction matching the provided action and type.</returns>
        public ReactionInfoCollection GetReactions(string action, string typeName)
        {
            ReactionInfoCollection foundReactions = new ReactionInfoCollection();

            using (LogGroup logGroup = LogGroup.StartDebug("Retrieving the reactions to the action '" + action + "' with the type '" + typeName + "'."))
            {
                if (action == null)
                {
                    throw new ArgumentNullException("action");
                }

                if (typeName == null)
                {
                    throw new ArgumentNullException("typeName");
                }


                if (action == String.Empty)
                {
                    throw new ArgumentException("An action must be provided other than String.Empty.", "action");
                }

                if (typeName == String.Empty)
                {
                    throw new ArgumentException("A type name must be provided other than String.Empty.", "typeName");
                }

                ReactionLocator locator = new ReactionLocator(this);

                foundReactions = locator.Locate(action, typeName);

                if (foundReactions == null)
                {
                    throw new ReactionNotFoundException(action, typeName);
                }
            }

            return(foundReactions);
        }
        public void Test_LocateFromHeirarchy()
        {
            string action = "Save";
            string typeName = "MockDerivedEntity";

            ReactionLocator locator = new ReactionLocator(ReactionState.Reactions);

            ReactionInfo[] reactions = locator.LocateFromHeirarchy(action, EntityState.GetType(typeName));

            foreach (ReactionInfo reaction in reactions)
            {
                Type expectedType = EntityState.GetType(typeName);
                Type actualType = EntityState.GetType(reaction.TypeName);

                bool doMatch = expectedType.Equals(actualType)
                    || expectedType.IsAssignableFrom(actualType)
                    || actualType.IsAssignableFrom(expectedType);

                Assert.IsTrue(doMatch, "The type '" + reaction.TypeName + "' on '" + reaction.GetType().FullName + "' reaction does not match expected type '" + typeName + "'.");
            }

            Assert.AreEqual(2, reactions.Length, "Invalid number of reactions found.");
        }
        public void Test_LocateFromInterfaces()
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Testing the LocateFromInterfaces function."))
            {
                string action = "Save";
                string typeName = "MockEntity";

                ReactionLocator locator = new ReactionLocator(ReactionState.Reactions);

                ReactionInfo[] reactions = locator.LocateFromInterfaces(action, EntityState.GetType(typeName));

                foreach (ReactionInfo reaction in reactions)
                {
                    Type expectedType = EntityState.GetType(typeName);
                    Type actualType = EntityState.GetType(reaction.TypeName);

                    bool doMatch = expectedType.Equals(actualType)
                        || expectedType.IsAssignableFrom(actualType)
                        || actualType.IsAssignableFrom(expectedType);

                    Assert.IsTrue(doMatch, "The type '" + reaction.TypeName + "' on '" + reaction.GetType().FullName + "' reaction does not match expected type '" + typeName + "'.");
                }

                Assert.AreEqual(1, reactions.Length, "Invalid number of reactions found.");
            }
        }