public void DoesntCallContextRegistryForLocalObjectFactoryReferences()
        {
            string xml = string.Format(
                @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>
	<object id='foo' type='{0}'>
        <property name='MyField' expression='@(theObject)' />
    </object>
</objects>"
                            , typeof(MyTestObject).AssemblyQualifiedName
                            );

            XmlObjectFactory of = new XmlObjectFactory(new StringResource(xml, Encoding.UTF8));
            object theObject = new object();
            of.RegisterSingleton("theObject", theObject);

            MyTestObject to = (MyTestObject) of.GetObject("foo");
            Assert.AreSame( theObject, to.MyField );
        }
        public void AutowireWithCtorArrayArgs()
        {
            XmlObjectFactory xof = new XmlObjectFactory(new ReadOnlyXmlTestResource("array-autowire.xml", GetType()));
            TestObject spouse = new TestObject("kerry", 0);
            xof.RegisterSingleton("spouse", spouse);

            TestObject spouse2 = new TestObject("kerry2", 0);
            xof.RegisterSingleton("spouse2", spouse2);

            ITestObject kerry = (ITestObject) xof.GetObject("spouse");
            ITestObject kerry2 = (ITestObject)xof.GetObject("spouse2");
            ArrayCtorDependencyObject rod7 = (ArrayCtorDependencyObject) xof.GetObject("rod7");

            Assert.AreEqual(kerry, rod7.Spouse1);
            Assert.AreEqual(kerry2, rod7.Spouse2);
        }
 public void Autowire()
 {
     XmlObjectFactory xof = new XmlObjectFactory(new ReadOnlyXmlTestResource("autowire.xml", GetType()));
     TestObject spouse = new TestObject("kerry", 0);
     xof.RegisterSingleton("Spouse", spouse);
     DoTestAutowire(xof);
 }
        public void AnObjectCanBeInjectedFromCodeIntoTheContext ()
        {
            string inject = @"
<objects xmlns='http://www.springframework.net' 
		xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
		xsi:schemaLocation='http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd'>

    <object 
        name='inject' 
        type='Spring.Services.WindowsService.Common.Deploy.FileSystem.Inject' 
        singleton='false'>
      <property name='Application'>
        <ref object='app'/>
      </property>
    </object>
</objects>
";            
            XmlObjectFactory factory = new XmlObjectFactory(new InputStreamResource(new MemoryStream(Encoding.Default.GetBytes(inject)), ""));
            IApplication app = new Application("foo");
            factory.RegisterSingleton("app", app);
            Inject injected = (Inject) factory.GetObject("inject");
            Assert.IsNotNull(injected);
            Assert.IsNotNull(injected.Application);
            Assert.AreEqual(app, injected.Application);
        }
        public void CanBeConfiguredToIncludeOrExcludePathsForEvents ()
        {
            string simple = "Data/Xml/watcher-simple.xml";
            XmlObjectFactory f = new XmlObjectFactory(new FileSystemResource(simple));
            f.RegisterSingleton(DefaultApplicationWatcherFactory.InjectedApplicationName, application);
            watcher = f["watcher"] as FileSystemApplicationWatcher;
            Assert.IsNotNull(watcher, 
                String.Format("test file [{0}] should define a file sistem resource!", simple));
            Assert.AreEqual(1, watcher.Excludes.Count);
            Assert.AreEqual(1, watcher.Includes.Count);

            watcher.StartWatching(dispatcher);

            // propagated
            string subDir = Path.Combine(appFullPath, "foo");
            Directory.CreateDirectory(subDir);
            using (File.Create(Path.Combine (subDir, "foo.bar"))) {}
            eventLatch.Acquire();            
            Assert.IsFalse(dispatched);
        }