public void FactoryDoesNotContainTargetObject()
        {
            A.CallTo(() => factory.ContainsObject("bojangles")).Returns(false);

            ObjectReferenceFactoryObject fac = new ObjectReferenceFactoryObject();

            fac.TargetObjectName = "bojangles";

            // simulate IFactoryObjectAware interface...
            Assert.Throws <NoSuchObjectDefinitionException>(() => fac.ObjectFactory = factory,
                                                            "Must have bailed with a " +
                                                            "NoSuchObjectDefinitionException 'cos the object doesn't " +
                                                            "exist in the associated factory.");
        }
Beispiel #2
0
        /// <summary>
        /// Create a target source for object instances. Uses any
        /// TargetSourceCreators if set. Returns null if no Custom TargetSource
        /// should be used.
        /// This implementation uses the customTargetSourceCreators property.
        /// Subclasses can override this method to use a different mechanism.
        /// </summary>
        /// <param name="objectType">the type of the object to create a TargetSource for</param>
        /// <param name="name">the name of the object</param>
        /// <returns>a TargetSource for this object</returns>
        protected virtual ITargetSource GetCustomTargetSource(Type objectType, string name)
        {
            // We can't create fancy target sources for directly registered singletons.
            if (customTargetSourceCreators != null &&
                owningObjectFactory != null && owningObjectFactory.ContainsObject(name))
            {
                for (int i = 0; i < customTargetSourceCreators.Count; i++)
                {
                    ITargetSourceCreator tsc = (ITargetSourceCreator)customTargetSourceCreators[i];
                    ITargetSource        ts  = tsc.GetTargetSource(objectType, name, owningObjectFactory);
                    if (ts != null)
                    {
                        // found a match
                        if (logger.IsInfoEnabled)
                        {
                            logger.Info(string.Format("TargetSourceCreator [{0} found custom TargetSource for object with objectName '{1}'", tsc, name));
                        }
                        return(ts);
                    }
                }
            }

            // no custom TargetSource found
            return(null);
        }
Beispiel #3
0
        public void FactoryDoesNotContainTargetObject()
        {
            Expect.Call(factory.ContainsObject("bojangles")).Return(false);
            mocks.ReplayAll();

            ObjectReferenceFactoryObject fac = new ObjectReferenceFactoryObject();

            fac.TargetObjectName = "bojangles";
            try
            {
                // simulate IFactoryObjectAware interface...
                fac.ObjectFactory = factory;
                Assert.Fail("Must have bailed with a " +
                            "NoSuchObjectDefinitionException 'cos the object doesn't " +
                            "exist in the associated factory.");
            }
            catch (NoSuchObjectDefinitionException)
            {
                mocks.VerifyAll();
            }
        }
Beispiel #4
0
 protected override IConversationCreationInterceptor GetConversationCreationInterceptor(Type configuredConcreteType)
 {
     // TODO: Spring throws an exception when the type does not exist so, for the moment,
     // this is a restriction to register the IConversationCreationInterceptor
     // The restriction : IConversationCreationInterceptor, if registered, should be registered
     // with its fullname as key.
     if (factory.ContainsObject(configuredConcreteType.FullName))
     {
         return((IConversationCreationInterceptor)factory.GetObject(configuredConcreteType.FullName, configuredConcreteType));
     }
     return(null);
 }
Beispiel #5
0
        private static T GetObjectOfType <T>(IObjectFactory objectFactory, string objectName) where T : class
        {
            if (!objectFactory.ContainsObject(objectName))
            {
                return(null);
            }
            object obj = objectFactory.GetObject(objectName);

            AssertUtils.State(obj is T, "incorrect type for object '" + objectName
                              + "' expected [" + typeof(T) + "], but actual type is [" + obj.GetType() + "].");

            return((T)obj);
        }
Beispiel #6
0
 public void When_ExplicitIdSetWithoutExplicitName_ObjectRegistrationUsesIdAsObjectDefintionName()
 {
     Assert.That(objectFactory.ContainsObject("explicit-id-but-no-explicit-name"), Is.True);
 }