예제 #1
0
        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);
        }
예제 #2
0
        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 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);
        }