public void Matches_AllTypeIdentifiers()
        {
            ReplacedMethodOverride methodOverride = new ReplacedMethodOverride("Execute", "replacer");

            methodOverride.AddTypeIdentifier(typeof(object).FullName);
            methodOverride.AddTypeIdentifier(typeof(object).FullName);
            Assert.IsTrue(methodOverride.Matches(typeof(Executor).GetMethod("Execute",
                                                                            new Type[] { typeof(object), typeof(object) })));
        }
        public void Matches_MatchingMethodNameWithOverloadAndBadTypeIdentifiers()
        {
            ReplacedMethodOverride methodOverride = new ReplacedMethodOverride("Execute", "replacer");

            methodOverride.AddTypeIdentifier(GetType().FullName);
            Assert.IsFalse(methodOverride.Matches(typeof(Executor).GetMethod("Execute", new Type[] { typeof(object) })));
        }
		public void Matches_AllTypeIdentifiers()
		{
			ReplacedMethodOverride methodOverride = new ReplacedMethodOverride("Execute", "replacer");
			methodOverride.AddTypeIdentifier(typeof (object).FullName);
			methodOverride.AddTypeIdentifier(typeof (object).FullName);
			Assert.IsTrue(methodOverride.Matches(typeof (Executor).GetMethod("Execute",
			                                                                 new Type[] {typeof (object), typeof (object)})));
		}
		public void Matches_MatchingMethodNameWithOverloadAndBadTypeIdentifiers()
		{
			ReplacedMethodOverride methodOverride = new ReplacedMethodOverride("Execute", "replacer");
			methodOverride.AddTypeIdentifier(GetType().FullName);
			Assert.IsFalse(methodOverride.Matches(typeof (Executor).GetMethod("Execute", new Type[] {typeof (object)})));
		}
 /// <summary>
 /// Parse <see cref="ObjectDefinitionConstants.ReplacedMethodElement"/> element and add parsed element to <paramref name="overrides"/>
 /// </summary>
 protected void ParseReplacedMethodElement(
     string name, MethodOverrides overrides, XmlElement element, ParserContext parserContext)
 {
     string methodName = GetAttributeValue(element, ObjectDefinitionConstants.ReplacedMethodNameAttribute);
     string targetReplacerObjectName = GetAttributeValue(element, ObjectDefinitionConstants.ReplacedMethodReplacerNameAttribute);
     if (StringUtils.IsNullOrEmpty(methodName))
     {
         throw new ObjectDefinitionStoreException(
             parserContext.ReaderContext.Resource, name,
             string.Format("The '{0}' attribute is required for the '{1}' element.",
                           ObjectDefinitionConstants.ReplacedMethodNameAttribute, ObjectDefinitionConstants.ReplacedMethodElement));
     }
     if (StringUtils.IsNullOrEmpty(targetReplacerObjectName))
     {
         throw new ObjectDefinitionStoreException(
             parserContext.ReaderContext.Resource, name,
             string.Format("The '{0}' attribute is required for the '{1}' element.",
                           ObjectDefinitionConstants.ReplacedMethodReplacerNameAttribute, ObjectDefinitionConstants.ReplacedMethodElement));
     }
     ReplacedMethodOverride theOverride = new ReplacedMethodOverride(methodName, targetReplacerObjectName);
     foreach (XmlNode node in this.SelectNodes(element, ObjectDefinitionConstants.ReplacedMethodArgumentTypeElement))
     {
         XmlElement argElement = (XmlElement)node;
         string match = GetAttributeValue(argElement, ObjectDefinitionConstants.ReplacedMethodArgumentTypeMatchAttribute);
         if (StringUtils.IsNullOrEmpty(match))
         {
             throw new ObjectDefinitionStoreException(
                 parserContext.ReaderContext.Resource, name,
                 string.Format("The '{0}' attribute is required for the '{1}' element.",
                               ObjectDefinitionConstants.ReplacedMethodArgumentTypeMatchAttribute, ObjectDefinitionConstants.ReplacedMethodArgumentTypeElement));
         }
         theOverride.AddTypeIdentifier(match);
     }
     overrides.Add(theOverride);
 }
		public void SunnyDayReplaceMethod_WithArgumentAcceptingReplacer()
		{
			RootObjectDefinition replacerDef = new RootObjectDefinition(typeof (NewsFeedFactory));

			RootObjectDefinition managerDef = new RootObjectDefinition(typeof (NewsFeedManagerWith_Replace_MethodThatTakesArguments));
			ReplacedMethodOverride theOverride = new ReplacedMethodOverride("CreateNewsFeed", "replacer");
			// we must specify parameter type fragments...
			theOverride.AddTypeIdentifier(typeof(string).FullName);
			managerDef.MethodOverrides.Add(theOverride);

			DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
			factory.RegisterObjectDefinition("manager", managerDef);
			factory.RegisterObjectDefinition("replacer", replacerDef);
			NewsFeedManagerWith_Replace_MethodThatTakesArguments manager = (NewsFeedManagerWith_Replace_MethodThatTakesArguments) factory["manager"];
			NewsFeed feed1 = manager.CreateNewsFeed("So sad... to be all alone in the world");
			Assert.IsNotNull(feed1, "The CreateNewsFeed() method is not being replaced.");
			Assert.AreEqual("So sad... to be all alone in the world", feed1.Name);
			NewsFeed feed2 = manager.CreateNewsFeed("Oh Muzzy!");
			// NewsFeedFactory always yields a new NewsFeed (see class definition below)...
			Assert.IsFalse(ReferenceEquals(feed1, feed2));
		}