public void PrototypeModeWithSingletonTarget()
		{
			TestObject dude = new TestObject("Rick Evans", 30);			
            IObjectFactory objectFactory = mocks.StrictMock<IObjectFactory>();
			const string lookupObjectName = "rick";
            Expect.Call(objectFactory.GetObject(lookupObjectName)).Return(dude).Repeat.Twice();
			ObjectFactoryCreatingFactoryObject factory = new ObjectFactoryCreatingFactoryObject();
		    factory.ObjectFactory = objectFactory;
			factory.TargetObjectName = lookupObjectName;
			factory.IsSingleton = false;
			factory.AfterPropertiesSet();

            mocks.ReplayAll();
			IGenericObjectFactory gofOne = (IGenericObjectFactory) factory.GetObject();
			IGenericObjectFactory gofTwo = (IGenericObjectFactory) factory.GetObject();
			Assert.IsFalse(Object.ReferenceEquals(gofOne, gofTwo),
				"Not returning distinct instances (Prototype = true).");
			TestObject one = (TestObject) gofOne.GetObject();
			Assert.IsNotNull(one, "Must never return null (IFactoryObject contract).");
			TestObject two = (TestObject) gofTwo.GetObject();
			Assert.IsNotNull(two, "Must never return null (IFactoryObject contract).");
			Assert.IsTrue(Object.ReferenceEquals(one, two),
				"Not returning the same instance to singleton object.");
			mocks.VerifyAll();
		}
        public void PrototypeModeWithSingletonTarget()
        {
            TestObject     dude             = new TestObject("Rick Evans", 30);
            IObjectFactory objectFactory    = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory));
            const string   lookupObjectName = "rick";

            Expect.Call(objectFactory.GetObject(lookupObjectName)).Return(dude).Repeat.Twice();
            ObjectFactoryCreatingFactoryObject factory = new ObjectFactoryCreatingFactoryObject();

            factory.ObjectFactory    = (IObjectFactory)objectFactory;
            factory.TargetObjectName = lookupObjectName;
            factory.IsSingleton      = false;
            factory.AfterPropertiesSet();

            mocks.ReplayAll();
            IGenericObjectFactory gofOne = (IGenericObjectFactory)factory.GetObject();
            IGenericObjectFactory gofTwo = (IGenericObjectFactory)factory.GetObject();

            Assert.IsFalse(Object.ReferenceEquals(gofOne, gofTwo),
                           "Not returning distinct instances (Prototype = true).");
            TestObject one = (TestObject)gofOne.GetObject();

            Assert.IsNotNull(one, "Must never return null (IFactoryObject contract).");
            TestObject two = (TestObject)gofTwo.GetObject();

            Assert.IsNotNull(two, "Must never return null (IFactoryObject contract).");
            Assert.IsTrue(Object.ReferenceEquals(one, two),
                          "Not returning the same instance to singleton object.");
            mocks.VerifyAll();
        }
		public void SunnyDay()
		{
			TestObject dude = new TestObject("Rick Evans", 30);
		    IObjectFactory objectFactory = mocks.StrictMock<IObjectFactory>();
			const string lookupObjectName = "rick";
		    Expect.Call(objectFactory.GetObject(lookupObjectName)).Return(dude).Repeat.Twice();
			ObjectFactoryCreatingFactoryObject factory = new ObjectFactoryCreatingFactoryObject();
		    factory.ObjectFactory = objectFactory;
			factory.TargetObjectName = lookupObjectName;
			factory.AfterPropertiesSet();

            mocks.ReplayAll();

			IGenericObjectFactory gof = (IGenericObjectFactory) factory.GetObject();
			IGenericObjectFactory gofOther = (IGenericObjectFactory) factory.GetObject();
			Assert.IsTrue(Object.ReferenceEquals(gof, gofOther),
				"Not returning a shared instance (Singleton = true).");
			TestObject one = (TestObject) gof.GetObject();
			Assert.IsNotNull(one, "Must never return null (IFactoryObject contract).");
			TestObject two = (TestObject) gof.GetObject();
			Assert.IsNotNull(two, "Must never return null (IFactoryObject contract).");
			Assert.IsTrue(Object.ReferenceEquals(one, two),
			              "Not returning the same instance.");
			mocks.VerifyAll();
		}
        public void SunnyDay()
        {
            TestObject     dude             = new TestObject("Rick Evans", 30);
            IObjectFactory objectFactory    = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory));
            const string   lookupObjectName = "rick";

            Expect.Call(objectFactory.GetObject(lookupObjectName)).Return(dude).Repeat.Twice();
            ObjectFactoryCreatingFactoryObject factory = new ObjectFactoryCreatingFactoryObject();

            factory.ObjectFactory    = (IObjectFactory)objectFactory;
            factory.TargetObjectName = lookupObjectName;
            factory.AfterPropertiesSet();

            mocks.ReplayAll();

            IGenericObjectFactory gof      = (IGenericObjectFactory)factory.GetObject();
            IGenericObjectFactory gofOther = (IGenericObjectFactory)factory.GetObject();

            Assert.IsTrue(Object.ReferenceEquals(gof, gofOther),
                          "Not returning a shared instance (Singleton = true).");
            TestObject one = (TestObject)gof.GetObject();

            Assert.IsNotNull(one, "Must never return null (IFactoryObject contract).");
            TestObject two = (TestObject)gof.GetObject();

            Assert.IsNotNull(two, "Must never return null (IFactoryObject contract).");
            Assert.IsTrue(Object.ReferenceEquals(one, two),
                          "Not returning the same instance.");
            mocks.VerifyAll();
        }
        public void WithMissingObjectName()
        {
            ObjectFactoryCreatingFactoryObject factory
                = new ObjectFactoryCreatingFactoryObject();

            factory.AfterPropertiesSet();
        }
示例#6
0
        public void WithMissingObjectName()
        {
            ObjectFactoryCreatingFactoryObject factory
                = new ObjectFactoryCreatingFactoryObject();

            Assert.Throws <ArgumentException>(() => factory.AfterPropertiesSet(), "The 'TargetObjectName' property must have a value.");
        }
		public void WithMissingObjectName()
		{
			ObjectFactoryCreatingFactoryObject factory
				= new ObjectFactoryCreatingFactoryObject();
            Assert.Throws<ArgumentException>(() => factory.AfterPropertiesSet(), "The 'TargetObjectName' property must have a value.");
		}
		public void WithMissingObjectName()
		{
			ObjectFactoryCreatingFactoryObject factory
				= new ObjectFactoryCreatingFactoryObject();
			factory.AfterPropertiesSet();
		}
			/// <summary>
			/// Creates a new instance of the GenericObjectFactory class.
			/// </summary>
			/// <param name="enclosing">
			/// The enclosing
			/// <see cref="Spring.Objects.Factory.Config.ObjectFactoryCreatingFactoryObject"/>.
			/// </param>
			public GenericObjectFactory(
				ObjectFactoryCreatingFactoryObject enclosing)
			{
				_enclosing = enclosing;
			}
示例#10
0
 /// <summary>
 /// Creates a new instance of the GenericObjectFactory class.
 /// </summary>
 /// <param name="enclosing">
 /// The enclosing
 /// <see cref="Spring.Objects.Factory.Config.ObjectFactoryCreatingFactoryObject"/>.
 /// </param>
 public GenericObjectFactory(
     ObjectFactoryCreatingFactoryObject enclosing)
 {
     _enclosing = enclosing;
 }