GrabNewsFeed() 공개 메소드

public GrabNewsFeed ( ) : NewsFeed
리턴 NewsFeed
예제 #1
0
        public void SunnyDayReplaceMethod_WithProtectedVirtual()
        {
            RootObjectDefinition replacerDef = new RootObjectDefinition(typeof(NewsFeedFactory));

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

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

            DefaultListableObjectFactory factory = new DefaultListableObjectFactory();

            factory.RegisterObjectDefinition("manager", managerDef);
            factory.RegisterObjectDefinition("replacer", replacerDef);
            ProtectedReturnsNullNewsFeedManagerWithVirtualMethod manager = (ProtectedReturnsNullNewsFeedManagerWithVirtualMethod)factory["manager"];
            NewsFeed feed1 = manager.GrabNewsFeed();

            Assert.IsNotNull(feed1, "The protected CreateNewsFeed() method is not being replaced.");
            Assert.AreEqual(NewsFeedFactory.DefaultName, feed1.Name);
            NewsFeed feed2 = manager.GrabNewsFeed();

            // NewsFeedFactory always yields a new NewsFeed (see class definition below)...
            Assert.IsFalse(ReferenceEquals(feed1, feed2));
        }
예제 #2
0
        public void LookupMethodWithVirtualProtectedMethod()
        {
            RootObjectDefinition feedDef = new RootObjectDefinition(typeof(NewsFeed));

            feedDef.IsSingleton = false;
            feedDef.PropertyValues.Add("name", "Bingo");

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

            managerDef.MethodOverrides.Add(new LookupMethodOverride("CreateNewsFeed", "feed"));

            DefaultListableObjectFactory factory = new DefaultListableObjectFactory();

            factory.RegisterObjectDefinition("manager", managerDef);
            factory.RegisterObjectDefinition("feed", feedDef);
            ProtectedReturnsNullNewsFeedManagerWithVirtualMethod manager = (ProtectedReturnsNullNewsFeedManagerWithVirtualMethod)factory["manager"];
            NewsFeed feed1 = manager.GrabNewsFeed();

            Assert.IsNotNull(feed1, "The CreateNewsFeed() method is not being replaced.");
            NewsFeed feed2 = manager.GrabNewsFeed();

            // assert that the object (prototype) is definitely being looked up each time...
            Assert.IsFalse(ReferenceEquals(feed1, feed2));
        }