public void DoesNotAcceptInfrastructureAdvisorsDuringScanning() { DefaultListableObjectFactory of = new DefaultListableObjectFactory(); GenericObjectDefinition infrastructureAdvisorDefinition = new GenericObjectDefinition(); infrastructureAdvisorDefinition.ObjectType = typeof (TestAdvisor); infrastructureAdvisorDefinition.PropertyValues.Add("Name", "InfrastructureAdvisor"); infrastructureAdvisorDefinition.Role = ObjectRole.ROLE_INFRASTRUCTURE; of.RegisterObjectDefinition("infrastructure", infrastructureAdvisorDefinition); GenericObjectDefinition regularAdvisorDefinition = new GenericObjectDefinition(); regularAdvisorDefinition.ObjectType = typeof (TestAdvisor); regularAdvisorDefinition.PropertyValues.Add("Name", "RegularAdvisor"); // regularAdvisorDefinition.Role = ObjectRole.ROLE_APPLICATION; of.RegisterObjectDefinition("regular", regularAdvisorDefinition); TestAdvisorAutoProxyCreator apc = new TestAdvisorAutoProxyCreator(); apc.ObjectFactory = of; object[] advisors = apc.GetAdvicesAndAdvisorsForObject(typeof (object), "dummyTarget"); Assert.AreEqual(1, advisors.Length); Assert.AreEqual( "RegularAdvisor", ((TestAdvisor)advisors[0]).Name ); Assert.AreEqual(1, apc.CheckedAdvisors.Count); Assert.AreEqual("regular", apc.CheckedAdvisors[0]); }
public void ClearWithDynamicProxies() { CompositionProxyTypeBuilder typeBuilder = new CompositionProxyTypeBuilder(); typeBuilder.TargetType = typeof(TestObject); Type proxyType = typeBuilder.BuildProxyType(); DefaultListableObjectFactory of = new DefaultListableObjectFactory(); RootObjectDefinition od1 = new RootObjectDefinition(proxyType, false); od1.PropertyValues.Add("Name", "Bruno"); of.RegisterObjectDefinition("testObject", od1); GenericApplicationContext ctx1 = new GenericApplicationContext(of); ContextRegistry.RegisterContext(ctx1); ITestObject to1 = ContextRegistry.GetContext().GetObject("testObject") as ITestObject; Assert.IsNotNull(to1); Assert.AreEqual("Bruno", to1.Name); DefaultListableObjectFactory of2 = new DefaultListableObjectFactory(); RootObjectDefinition od2 = new RootObjectDefinition(proxyType, false); od2.PropertyValues.Add("Name", "Baia"); of2.RegisterObjectDefinition("testObject", od2); GenericApplicationContext ctx2 = new GenericApplicationContext(of2); ContextRegistry.Clear(); ITestObject to2 = ctx2.GetObject("testObject") as ITestObject; Assert.IsNotNull(to2); Assert.AreEqual("Baia", to2.Name); }
protected void SetUp() { parent = new DefaultListableObjectFactory(); IDictionary<string, object> m = new Dictionary<string, object>(); m["name"] = "Albert"; parent.RegisterObjectDefinition("father", new RootObjectDefinition(typeof(TestObject), new MutablePropertyValues(m))); m = new Dictionary<string, object>(); m["name"] = "Roderick"; parent.RegisterObjectDefinition("rod", new RootObjectDefinition(typeof(TestObject), new MutablePropertyValues(m))); // for testing dynamic ctor arguments + parent.GetObject() call propagation parent.RegisterObjectDefinition("namedfather", new RootObjectDefinition(typeof(TestObject), false)); parent.RegisterObjectDefinition("typedfather", new RootObjectDefinition(typeof(TestObject), false)); // add unsupported IObjectDefinition implementation... //UnsupportedObjectDefinitionImplementation unsupportedDefinition = new UnsupportedObjectDefinitionImplementation(); //parent.RegisterObjectDefinition("unsupportedDefinition", unsupportedDefinition); XmlObjectFactory factory; factory = new XmlObjectFactory(new ReadOnlyXmlTestResource("test.xml", GetType()), parent); // TODO: should this be allowed? //this.factory.RegisterObjectDefinition("typedfather", new RootObjectDefinition(typeof(object), false)); factory.AddObjectPostProcessor(new AnonymousClassObjectPostProcessor()); factory.AddObjectPostProcessor(new LifecycleObject.PostProcessor()); factory.PreInstantiateSingletons(); base.ObjectFactory = factory; }
private void InitFactory(DefaultListableObjectFactory factory) { Console.WriteLine("init factory"); RootObjectDefinition tee = new RootObjectDefinition(typeof(Tee), true); tee.IsLazyInit = true; ConstructorArgumentValues teeValues = new ConstructorArgumentValues(); teeValues.AddGenericArgumentValue("test"); tee.ConstructorArgumentValues = teeValues; RootObjectDefinition bar = new RootObjectDefinition(typeof(BBar), false); ConstructorArgumentValues barValues = new ConstructorArgumentValues(); barValues.AddGenericArgumentValue(new RuntimeObjectReference("tee")); barValues.AddGenericArgumentValue(5); bar.ConstructorArgumentValues = barValues; RootObjectDefinition foo = new RootObjectDefinition(typeof(FFoo), false); MutablePropertyValues fooValues = new MutablePropertyValues(); fooValues.Add("i", 5); fooValues.Add("bar", new RuntimeObjectReference("bar")); fooValues.Add("copy", new RuntimeObjectReference("bar")); fooValues.Add("s", "test"); foo.PropertyValues = fooValues; factory.RegisterObjectDefinition("foo", foo); factory.RegisterObjectDefinition("bar", bar); factory.RegisterObjectDefinition("tee", tee); }
/// <summary> /// Load all registered configuration into spring. This method should only be called internally by the FluentApplicationContext, i.e. you shouldn't call it. /// </summary> /// <param name="objectFactory">The object factory.</param> public static void LoadConfiguration(DefaultListableObjectFactory objectFactory) { // This check is mainly for backward compability and avoid people trying to register their configuration twice. if (!_configurationRegistry.ContainsConfiguration()) { if (_assembliesList.Count == 0) { _assembliesList.Add(() => AppDomain.CurrentDomain.GetAssemblies()); } IList<Type> applicationContextConfigurerTypes = new List<Type>(); // only load the configuration once (in case the assembly was registered twice) foreach (Type type in from assemblies in _assembliesList from assembly in assemblies() from type in assembly.GetTypes() where type.GetInterfaces().Contains(typeof (ICanConfigureApplicationContext)) where !applicationContextConfigurerTypes.Contains(type) select type) { applicationContextConfigurerTypes.Add(type); } // load each class containing configuration. foreach (ICanConfigureApplicationContext contextConfigurer in applicationContextConfigurerTypes.Select(applicationContextConfigurerType => (ICanConfigureApplicationContext) Activator.CreateInstance(applicationContextConfigurerType))) { contextConfigurer.Configure(); } } _configurationRegistry.LoadObjectDefinitions(objectFactory); }
private static NamedObjectDefinition Find( string url, string objectName ) { DefaultListableObjectFactory of = new DefaultListableObjectFactory(); RootObjectDefinition rod = new RootObjectDefinition( typeof( Type1 ) ); of.RegisterObjectDefinition( objectName, rod ); return FindWebObjectDefinition( url, of ); }
public void Can_Create_Custom_Scan_Routine() { var scanner = new ScanOverridingAssemblyObjectDefinitionScanner(); var registry = new DefaultListableObjectFactory(); scanner.ScanAndRegisterTypes(registry); Assert.That(registry.ObjectDefinitionCount, Is.EqualTo(1), "found multiple definitions"); Assert.That(registry.GetObject<ComponentScan.ScanComponentsAndAddToContext.ConfigurationImpl>(), Is.Not.Null, "correct single defintion was not registered"); }
protected override void LoadObjectDefinitions(DefaultListableObjectFactory objectFactory) { //wrap the objectFactory with our own proxy so that we keep track of the objects ids defined in the Spring.NET context callbacks.Add(new BeanohObjectFactoryMethodInterceptor(objectFactory)); ProxyGenerator generator = new ProxyGenerator(); DefaultListableObjectFactory wrapper = (DefaultListableObjectFactory)generator.CreateClassProxy(objectFactory.GetType(), callbacks.ToArray()); //delegate to our proxy base.LoadObjectDefinitions(wrapper); }
public void CanCreateHostTwice() { DefaultListableObjectFactory of = new DefaultListableObjectFactory(); string svcRegisteredName = System.Guid.NewGuid().ToString(); of.RegisterObjectDefinition(svcRegisteredName, new RootObjectDefinition(new RootObjectDefinition(typeof(Service)))); SpringServiceHost ssh = new SpringServiceHost(svcRegisteredName, of, true); SpringServiceHost ssh1 = new SpringServiceHost(svcRegisteredName, of, true); }
public virtual void StaticEventWiring() { DefaultListableObjectFactory factory = new DefaultListableObjectFactory(); XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory); reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("event-wiring.xml", GetType())); TestEventHandler staticHandler = factory["staticEventListener"] as TestEventHandler; // raise the event... handlers should be notified at this point (obviously) TestObject.OnStaticClick(); Assert.IsTrue(staticHandler.EventWasHandled, "The instance handler did not get notified when the static event was raised (and was probably not wired up in the first place)."); }
protected override void AddPersistenceExceptionTranslation(ProxyFactory pf, IPersistenceExceptionTranslator pet) { if (AttributeUtils.FindAttribute(pf.TargetType, typeof(RepositoryAttribute)) != null) { DefaultListableObjectFactory of = new DefaultListableObjectFactory(); of.RegisterObjectDefinition("peti", new RootObjectDefinition(typeof(PersistenceExceptionTranslationInterceptor))); of.RegisterSingleton("pet", pet); pf.AddAdvice((PersistenceExceptionTranslationInterceptor) of.GetObject("peti")); } }
public void BailsIfTargetNotFound() { using (DefaultListableObjectFactory of = new DefaultListableObjectFactory()) { SaoExporter saoExporter = new SaoExporter(); saoExporter.ObjectFactory = of; saoExporter.TargetName = "DOESNOTEXIST"; saoExporter.ServiceName = "RemotedSaoSingletonCounter"; saoExporter.AfterPropertiesSet(); } }
public virtual void EventWiringInstanceSinkToPrototypeSource() { DefaultListableObjectFactory factory = new DefaultListableObjectFactory(); XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory); reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("event-wiring-prototypes.xml", GetType())); TestEventHandler instanceHandler = factory["instanceSink"] as TestEventHandler; ITestObject source = factory["source"] as ITestObject; // raise the event... handlers should be notified at this point (obviously) source.OnClick(); Assert.IsTrue(instanceHandler.EventWasHandled, "The instance handler did not get notified when the instance event was raised (and was probably not wired up in the first place)."); }
public void ProxyObjectWithoutInterface() { DefaultListableObjectFactory of = new DefaultListableObjectFactory(); of.RegisterObjectDefinition("bar", new RootObjectDefinition(typeof(ObjectWithoutInterface))); TestAutoProxyCreator apc = new TestAutoProxyCreator(of); of.AddObjectPostProcessor(apc); ObjectWithoutInterface o = of.GetObject("bar") as ObjectWithoutInterface; Assert.IsTrue(AopUtils.IsAopProxy(o)); o.Foo(); Assert.AreEqual(1, apc.NopInterceptor.Count); }
public void SetUp() { _singletonDefinition = new RootObjectDefinition(typeof (TestObject), AutoWiringMode.No); _singletonDefinitionWithFactory = new RootObjectDefinition(_singletonDefinition); _singletonDefinitionWithFactory.FactoryMethodName = "GetObject"; _singletonDefinitionWithFactory.FactoryObjectName = "TestObjectFactoryDefinition"; _testObjectFactory = new RootObjectDefinition(typeof (TestObjectFactory), AutoWiringMode.No); DefaultListableObjectFactory myFactory = new DefaultListableObjectFactory(); myFactory.RegisterObjectDefinition("SingletonObjectDefinition", SingletonDefinition); myFactory.RegisterObjectDefinition("SingletonDefinitionWithFactory", SingletonDefinitionWithFactory); myFactory.RegisterObjectDefinition("TestObjectFactoryDefinition", TestObjectFactoryDefinition); _factory = myFactory; }
public void ConvertsWriteConcernCorrectly() { DefaultListableObjectFactory factory = new DefaultListableObjectFactory(); factory.RegisterCustomConverter(typeof(WriteConcern), new WriteConcernTypeConverter()); RootObjectDefinition definition = new RootObjectDefinition(typeof(MongoFactoryObject)); definition.PropertyValues.Add("Url", "mongodb://localhost"); definition.PropertyValues.Add("WriteConcern", "Acknowledged"); factory.RegisterObjectDefinition("factory", definition); MongoFactoryObject obj = factory.GetObject<MongoFactoryObject>("&factory"); Assert.That(ReflectionUtils.GetInstanceFieldValue(obj, "_writeConcern"), Is.EqualTo(WriteConcern.Acknowledged)); }
public void SetUp() { _singletonDefinition = new RootObjectDefinition(typeof(TestObject), AutoWiringMode.No); _singletonDefinitionWithFactory = new RootObjectDefinition(_singletonDefinition); _singletonDefinitionWithFactory.FactoryMethodName = "GetObject"; _singletonDefinitionWithFactory.FactoryObjectName = "TestObjectFactoryDefinition"; _testObjectFactory = new RootObjectDefinition(typeof(TestObjectFactory), AutoWiringMode.No); DefaultListableObjectFactory myFactory = new DefaultListableObjectFactory(); myFactory.RegisterObjectDefinition("SingletonObjectDefinition", SingletonDefinition); myFactory.RegisterObjectDefinition("SingletonDefinitionWithFactory", SingletonDefinitionWithFactory); myFactory.RegisterObjectDefinition("TestObjectFactoryDefinition", TestObjectFactoryDefinition); _factory = myFactory; }
public void ExportSingleton() { using (DefaultListableObjectFactory of = new DefaultListableObjectFactory()) { of.RegisterSingleton("simpleCounter", new SimpleCounter()); SaoExporter saoExporter = new SaoExporter(); saoExporter.ObjectFactory = of; saoExporter.TargetName = "simpleCounter"; saoExporter.ServiceName = "RemotedSaoSingletonCounter"; saoExporter.AfterPropertiesSet(); of.RegisterSingleton("simpleCounterExporter", saoExporter); // also tests SaoExporter.Dispose()! AssertExportedService(saoExporter.ServiceName, 2); } }
public void Test() { int numIterations = 10000; start = DateTime.Now; DefaultListableObjectFactory factory = new DefaultListableObjectFactory(); InitFactory(factory); for (int i = 0; i < numIterations; i++) { FFoo foo = (FFoo)factory.GetObject("foo"); } stop = DateTime.Now; double timeElapsed = Elapsed; PrintTest("Creations", numIterations, timeElapsed); }
public void ShouldAllowConfigurationClassInheritance() { var factory = new DefaultListableObjectFactory(); factory.RegisterObjectDefinition("DerivedConfiguration", new GenericObjectDefinition { ObjectType = typeof(DerivedConfiguration) }); var processor = new ConfigurationClassPostProcessor(); processor.PostProcessObjectFactory(factory); // we should get singleton instances only TestObject testObject = (TestObject) factory.GetObject("DerivedDefinition"); string singletonParent = (string) factory.GetObject("BaseDefinition"); Assert.That(testObject.Value, Is.SameAs(singletonParent)); }
public void SunnyDayReplaceMethod() { RootObjectDefinition replacerDef = new RootObjectDefinition(typeof (NewsFeedFactory)); RootObjectDefinition managerDef = new RootObjectDefinition(typeof (ReturnsNullNewsFeedManager)); managerDef.MethodOverrides.Add(new ReplacedMethodOverride("CreateNewsFeed", "replacer")); DefaultListableObjectFactory factory = new DefaultListableObjectFactory(); factory.RegisterObjectDefinition("manager", managerDef); factory.RegisterObjectDefinition("replacer", replacerDef); INewsFeedManager manager = (INewsFeedManager) factory["manager"]; NewsFeed feed1 = manager.CreateNewsFeed(); Assert.IsNotNull(feed1, "The CreateNewsFeed() method is not being replaced."); Assert.AreEqual(NewsFeedFactory.DefaultName, feed1.Name); NewsFeed feed2 = manager.CreateNewsFeed(); // NewsFeedFactory always yields a new NewsFeed (see class definition below)... Assert.IsFalse(ReferenceEquals(feed1, feed2)); }
public void _TestSetUp() { DefaultListableObjectFactory parentFactory = new DefaultListableObjectFactory(); _factory = new DefaultListableObjectFactory(parentFactory); RootObjectDefinition rodA = new RootObjectDefinition(_expectedtype); RootObjectDefinition rodB = new RootObjectDefinition(_expectedtype); RootObjectDefinition rodC = new RootObjectDefinition(_expectedtype); RootObjectDefinition rod2A = new RootObjectDefinition(_expectedtype); RootObjectDefinition rod2C = new RootObjectDefinition(_expectedtype); _factory.RegisterObjectDefinition("objA", rodA); _factory.RegisterObjectDefinition("objB", rodB); _factory.RegisterObjectDefinition("objC", rodC); parentFactory.RegisterObjectDefinition("obj2A", rod2A); parentFactory.RegisterObjectDefinition("objB", rodB); parentFactory.RegisterObjectDefinition("obj2C", rod2C); }
/// <summary> /// Create a special TargetSource for the given object, if any. /// </summary> /// <param name="objectType">the type of the object to create a TargetSource for</param> /// <param name="name">the name of the object</param> /// <param name="factory">the containing factory</param> /// <returns> /// a special TargetSource or null if this TargetSourceCreator isn't /// interested in the particular object /// </returns> public ITargetSource GetTargetSource(Type objectType, string name, IObjectFactory factory) { AbstractPrototypeTargetSource prototypeTargetSource = CreatePrototypeTargetSource(objectType, name, factory); if (prototypeTargetSource == null) { return null; } else { if (!(factory is IObjectDefinitionRegistry)) { if (logger.IsWarnEnabled) logger.Warn("Cannot do autopooling with a IObjectFactory that doesn't implement IObjectDefinitionRegistry"); return null; } IObjectDefinitionRegistry definitionRegistry = (IObjectDefinitionRegistry) factory; RootObjectDefinition definition = (RootObjectDefinition) definitionRegistry.GetObjectDefinition(name); if (logger.IsInfoEnabled) logger.Info("Configuring AbstractPrototypeBasedTargetSource..."); // Infinite cycle will result if we don't use a different factory, // because a GetObject() call with this objectName will go through the autoproxy // infrastructure again. // We to override just this object definition, as it may reference other objects // and we're happy to take the parent's definition for those. DefaultListableObjectFactory objectFactory = new DefaultListableObjectFactory(factory); // Override the prototype object objectFactory.RegisterObjectDefinition(name, definition); // Complete configuring the PrototypeTargetSource prototypeTargetSource.TargetObjectName = name; prototypeTargetSource.ObjectFactory = objectFactory; return prototypeTargetSource; } }
/// <summary> /// Initializes a new instance of the <see cref="GenericApplicationContext"/> class. /// </summary> /// <param name="objectFactory">The object factory instance to use for this context.</param> public GenericApplicationContext(DefaultListableObjectFactory objectFactory) : this(null, true, null, objectFactory) { // noop }
/// <summary> /// Initializes a new instance of the <see cref="GenericApplicationContext"/> class. /// </summary> /// <param name="name">The name of the application context.</param> /// <param name="caseSensitive">if set to <c>true</c> names in the context are case sensitive.</param> /// <param name="parent">The parent application context.</param> /// <param name="objectFactory">The object factory to use for this context</param> public GenericApplicationContext(string name, bool caseSensitive, IApplicationContext parent, DefaultListableObjectFactory objectFactory) : base(name, caseSensitive, parent) { AssertUtils.ArgumentNotNull(objectFactory, "objectFactory", "ObjectFactory must not be null"); this.objectFactory = objectFactory; this.objectFactory.ParentObjectFactory = base.GetInternalParentObjectFactory(); }
/// <summary> /// Customizes the internal object factory used by this context. /// </summary> /// <remarks>Called for each <see cref="AbstractApplicationContext.Refresh()"/> attempt. /// <p> /// The default implementation is empty. Can be overriden in subclassses to customize /// DefaultListableBeanFatory's standard settings. /// </p></remarks> /// <param name="objectFactory">The newly created object factory for this context</param> protected virtual void CustomizeObjectFactory(DefaultListableObjectFactory objectFactory) { // noop }
/// <summary> /// Create a new reader instance for importing object definitions into the specified <paramref name="objectFactory"/>. /// </summary> /// <param name="objectFactory">the <see cref="DefaultListableObjectFactory"/> to be associated with the reader</param> /// <returns>a new <see cref="XmlObjectDefinitionReader"/> instance.</returns> protected virtual XmlObjectDefinitionReader CreateXmlObjectDefinitionReader(DefaultListableObjectFactory objectFactory) { return new XmlObjectDefinitionReader(objectFactory); }
/// <summary> /// Loads the object definitions into the given object factory, typically through /// delegating to one or more object definition readers. /// </summary> /// <param name="objectFactory">The object factory to lead object definitions into</param> /// <see cref="XmlObjectDefinitionReader"/> /// <see cref="PropertiesObjectDefinitionReader"/> protected virtual void LoadObjectDefinitions(DefaultListableObjectFactory objectFactory) { //Create a new XmlObjectDefinitionReader for the given ObjectFactory XmlObjectDefinitionReader objectDefinitionReader = CreateXmlObjectDefinitionReader(objectFactory); // Configure the bean definition reader with this context's // resource loading environment. objectDefinitionReader.ResourceLoader = this; // Allow a subclass to provide custom initialization of the reader, // then proceed with actually loading the object definitions. InitObjectDefinitionReader(objectDefinitionReader); LoadObjectDefinitions(objectDefinitionReader); }
/// <summary> /// Instantiates and populates the underlying /// <see cref="Spring.Objects.Factory.IObjectFactory"/> with the object /// definitions yielded up by the <see cref="ConfigurationLocations"/> /// method. /// </summary> /// <exception cref="Spring.Objects.ObjectsException"> /// In the case of errors encountered while refreshing the object factory. /// </exception> /// <exception cref="ApplicationContextException"> /// In the case of errors encountered reading any of the resources /// yielded by the <see cref="ConfigurationLocations"/> method. /// </exception> /// <seealso cref="Spring.Context.Support.AbstractApplicationContext.RefreshObjectFactory()"/> protected override void RefreshObjectFactory() { // Shut down previous object factory, if any. DefaultListableObjectFactory oldObjectFactory = _objectFactory; _objectFactory = null; if (oldObjectFactory != null) { oldObjectFactory.Dispose(); } try { DefaultListableObjectFactory objectFactory = CreateObjectFactory(); CustomizeObjectFactory(objectFactory); LoadObjectDefinitions(objectFactory); _objectFactory = objectFactory; #region Instrumentation if (log.IsDebugEnabled) { log.Debug( string.Format( "Refreshed ObjectFactory for application context '{0}'.", Name)); } #endregion } catch (IOException ex) { throw new ApplicationContextException( string.Format( "I/O error parsing XML resource for application context '{0}'.", Name), ex); } catch (UriFormatException ex) { throw new ApplicationContextException( string.Format( "Error parsing resource locations [{0}] for application context '{1}'.", StringUtils.ArrayToCommaDelimitedString(ConfigurationLocations), Name), ex); } }
public void ThrowsTypeLoadExceptionIfProxyInterfacesValueIsSpecifiedInsteadOfListElement() { using (DefaultListableObjectFactory of = new DefaultListableObjectFactory()) { XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of); reader.LoadObjectDefinitions(new StringResource( @"<?xml version='1.0' encoding='UTF-8' ?> <objects xmlns='http://www.springframework.net' xmlns:r='http://www.springframework.net/remoting'> <r:saoExporter id='ISimpleCounterExporter' targetName='ISimpleCounterProxy' serviceName='RemotedSaoCounterProxy' /> <object id='ISimpleCounter' type='Spring.Remoting.SimpleCounter, Spring.Services.Tests' /> <object id='ISimpleCounterProxy' type='Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop'> <property name='proxyInterfaces' value='Spring.Remoting.ISimpleCounter, Spring.Services.Tests' /> <property name='target' ref='ISimpleCounter'/> </object> </objects> ")); try { SaoExporter saoExporter = (SaoExporter) of.GetObject("ISimpleCounterExporter"); Assert.Fail(); } catch (ObjectCreationException oce) { TypeLoadException tle = (TypeLoadException) oce.GetBaseException(); Assert.AreEqual("Could not load type from string value ' Spring.Services.Tests'.", tle.Message); } } }
public void CanExportFromFactoryObjectIfObjectTypeIsInterface() { using (DefaultListableObjectFactory of = new DefaultListableObjectFactory()) { MockRepository mocks = new MockRepository(); IFactoryObject simpleCounterFactory = (IFactoryObject) mocks.DynamicMock(typeof (IFactoryObject)); Expect.Call(simpleCounterFactory.ObjectType).Return(typeof (ISimpleCounter)); Expect.Call(simpleCounterFactory.IsSingleton).Return(true); Expect.Call(simpleCounterFactory.GetObject()).Return(new SimpleCounter()); mocks.ReplayAll(); of.RegisterSingleton("simpleCounter", simpleCounterFactory); SaoExporter saoExporter = new SaoExporter(); saoExporter.ObjectFactory = of; saoExporter.TargetName = "simpleCounter"; saoExporter.ServiceName = "RemotedSaoCallCounter"; saoExporter.AfterPropertiesSet(); of.RegisterSingleton("simpleCounterExporter", saoExporter); // also tests SaoExporter.Dispose()! AssertExportedService(saoExporter.ServiceName, 2); mocks.VerifyAll(); } }