public void SingleConfigLocation()
        {
            XmlApplicationContext ctx =
                new XmlApplicationContext(false, "assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context.Support/simpleContext.xml");

            Assert.IsTrue(ctx.ContainsObject("someMessageSource"));
            ctx.Dispose();
        }
        public void GetObjectOnUnknownIdThrowsNoSuchObjectDefinition()
        {
            XmlApplicationContext ctx =
                new XmlApplicationContext(false, "assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context.Support/objects.xml");
            string DOES_NOT_EXIST = "does_not_exist";

            Assert.IsFalse(ctx.ContainsObject(DOES_NOT_EXIST));
            Assert.Throws <NoSuchObjectDefinitionException>(() => ctx.GetObject(DOES_NOT_EXIST));
        }
        public void ContextWithInvalidLazyType()
        {
            XmlApplicationContext ctx =
                new XmlApplicationContext(false,
                                          "assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context.Support/invalidType.xml");

            Assert.IsTrue(ctx.ContainsObject("someMessageSource"));
            ctx.GetObject("someMessageSource");
        }
        public void CaseInsensitiveContext()
        {
            XmlApplicationContext ctx =
                new XmlApplicationContext(false, "assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context.Support/objects.xml");

            Assert.IsTrue(ctx.ContainsObject("goran"));
            Assert.IsTrue(ctx.ContainsObject("Goran"));
            Assert.IsTrue(ctx.ContainsObject("GORAN"));
            Assert.AreEqual(ctx.GetObject("goran"), ctx.GetObject("GORAN"));
        }
        public void ContextWithPostProcessors()
        {
            CountingObjectPostProcessor.Count       = 0;
            CoutingObjectFactoryPostProcessor.Count = 0;

            IApplicationContext ctx =
                new XmlApplicationContext("assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context.Support/objects.xml");

            Assert.IsTrue(ctx.ContainsObject("abstractObjectProcessorPrototype"));
            Assert.IsTrue(ctx.ContainsObject("abstractFactoryProcessorPrototype"));

            Assert.AreEqual(0, CountingObjectPostProcessor.Count);
            Assert.AreEqual(0, CoutingObjectFactoryPostProcessor.Count);
        }
 public void InnerObjectWithPostProcessing()
 {
     try
     {
         XmlApplicationContext ctx = new XmlApplicationContext(false, "assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context.Support/innerObjectsWithPostProcessor.xml");
         ctx.GetObject("hasInnerObjects");
         Assert.Fail("should throw ObjectCreationException");
     }
     catch (ObjectCreationException e)
     {
         NoSuchObjectDefinitionException ex = e.InnerException as NoSuchObjectDefinitionException;
         Assert.IsNotNull(ex);
         //Pass
     }
 }
 public void ContextWithInvalidValueType()
 {
     try
     {
         XmlApplicationContext ctx =
             new XmlApplicationContext(false,
                                       "assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context.Support/invalidValueType.xml");
         Assert.Fail("Should have thrown ObjectCreationException for context", ctx);
     }
     catch (ObjectCreationException ex)
     {
         Assert.IsTrue(ex.Message.IndexOf((typeof(TypeMismatchException).Name)) != -1);
         Assert.IsTrue(ex.Message.IndexOf(("UseCodeAsDefaultMessage")) != -1);
     }
 }
        public void MultipleConfigLocations()
        {
            XmlApplicationContext ctx =
                new XmlApplicationContext(false, "assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context.Support/contextB.xml",
                                          "assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context.Support/contextC.xml",
                                          "assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context.Support/contextA.xml");

            Assert.IsTrue(ctx.ContainsObject("service"));
            Assert.IsTrue(ctx.ContainsObject("logicOne"));
            Assert.IsTrue(ctx.ContainsObject("logicTwo"));
            Service service = (Service)ctx.GetObject("service");

            ctx.Refresh();
            Assert.IsTrue(service.ProperlyDestroyed);
            service = (Service)ctx.GetObject("service");
            ctx.Dispose();
            Assert.IsTrue(service.ProperlyDestroyed);
        }
        public void RefreshDisposesExistingObjectFactory_SPRNET479()
        {
            string tmp = typeof(DestroyTester).FullName;

            Console.WriteLine(tmp);

            IApplicationContext ctx =
                new XmlApplicationContext("assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context.Support/objects.xml");

            DestroyTester destroyTester = (DestroyTester)ctx.GetObject("destroyTester");
            DisposeTester disposeTester = (DisposeTester)ctx.GetObject("disposeTester");

            Assert.IsFalse(destroyTester.IsDestroyed);
            Assert.IsFalse(disposeTester.IsDisposed);

            ((IConfigurableApplicationContext)ctx).Refresh();

            Assert.IsTrue(destroyTester.IsDestroyed);
            Assert.IsTrue(disposeTester.IsDisposed);
        }
        public void ContextLifeCycle()
        {
            IApplicationContext ctx =
                new XmlApplicationContext("assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context/contextlifecycle.xml");
            IConfigurableApplicationContext configCtx = ctx as IConfigurableApplicationContext;

            Assert.IsNotNull(configCtx);
            ContextListenerObject clo;

            using (configCtx)
            {
                clo = configCtx["contextListenerObject"] as ContextListenerObject;
                Assert.IsNotNull(clo);
                Assert.IsTrue(clo.AppListenerContextRefreshed,
                              "Object did not receive context refreshed event via IApplicationListener");
                Assert.IsTrue(clo.CtxRefreshed, "Object did not receive context refreshed event via direct wiring");
            }
            Assert.IsTrue(clo.AppListenerContextClosed,
                          "Object did not receive context closed event via IApplicationContextListener");
            Assert.IsTrue(clo.CtxClosed, "Object did not receive context closed event via direct wiring.");
        }
        public void ConfigureObject()
        {
            const string objDefLocation = "assembly://Oragon.Spring.Core.Tests/Oragon.Spring.Context.Support/objects.xml";

            XmlApplicationContext xmlContext = new XmlApplicationContext(new string[] { objDefLocation });

            object objGoran = xmlContext.GetObject("goran");

            Assert.IsTrue(objGoran is TestObject);
            TestObject fooGet = objGoran as TestObject;

            TestObject fooConfigure = new TestObject();

            xmlContext.ConfigureObject(fooConfigure, "goran");
            Assert.IsNotNull(fooGet);
            Assert.AreEqual(fooGet.Name, fooConfigure.Name);
            Assert.AreEqual(fooGet.Age, fooConfigure.Age);
            Assert.AreEqual(fooGet.ObjectName, fooConfigure.ObjectName);
            Assert.IsNotNull(fooGet.ObjectName);
            Assert.AreEqual(xmlContext, fooGet.ApplicationContext);
            Assert.AreEqual(xmlContext, fooConfigure.ApplicationContext);
        }
 public void SPRNET1231_DoesNotInvokeFactoryMethodDuringObjectFactoryPostProcessing()
 {
     string configLocation     = TestResourceLoader.GetAssemblyResourceUri(this.GetType(), "XmlApplicationContextTests-SPRNET1231.xml");
     XmlApplicationContext ctx = new XmlApplicationContext(configLocation);
 }