CreateNewsFeed() public method

public CreateNewsFeed ( string headline ) : NewsFeed
headline string
return NewsFeed
Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        public void SunnyDayReplaceMethod_WithArgumentAcceptingReplacerWithNoTypeFragmentsSpecified()
        {
            RootObjectDefinition replacerDef = new RootObjectDefinition(typeof(NewsFeedFactory));

            RootObjectDefinition managerDef = new RootObjectDefinition(typeof(NewsFeedManagerWith_Replace_MethodThatTakesArguments));

            managerDef.MethodOverrides.Add(new ReplacedMethodOverride("CreateNewsFeed", "replacer"));

            DefaultListableObjectFactory factory = new DefaultListableObjectFactory();

            factory.RegisterObjectDefinition("manager", managerDef);
            factory.RegisterObjectDefinition("replacer", replacerDef);
            NewsFeedManagerWith_Replace_MethodThatTakesArguments manager = (NewsFeedManagerWith_Replace_MethodThatTakesArguments)factory["manager"];

            Assert.Throws <NotImplementedException>(() => manager.CreateNewsFeed("So sad... to be all alone in the world"));
        }