Beispiel #1
0
        public void ComponentsLazyLoaded()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan4.xml", GetType()));
            var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("LazyInit");

            Assert.That(objectDefinition.IsLazyInit, Is.True);
        }
Beispiel #2
0
 public void Setup()
 {
     // WELLKNOWN
     //NamespaceParserRegistry.RegisterParser(typeof(NmsNamespaceParser));
     ctx   = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("NmsNamespaceHandlerTests.xml", GetType()));
     mocks = new MockRepository();
 }
Beispiel #3
0
        public void ComponentsUseDefaultAutoWire()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan5.xml", GetType()));
            var prototypeDef = _applicationContext.ObjectFactory.GetObjectDefinition("Prototype");

            Assert.That(prototypeDef.AutowireMode == AutoWiringMode.ByName);
        }
Beispiel #4
0
        //[Test]
        public void BasicConfig()
        {
            NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
            IApplicationContext ctx = new XmlApplicationContext(
                ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.BasicConfig.xml", this.GetType()));

            Assert.IsTrue(ctx.ContainsObjectDefinition("channel"));

            RootObjectDefinition rod = ((IObjectDefinitionRegistry)ctx).GetObjectDefinition("channel") as RootObjectDefinition;

            Assert.IsNotNull(rod);

            Assert.IsTrue(rod.HasObjectType);
            Assert.AreEqual(typeof(ChannelFactoryObject <IContract>), rod.ObjectType);
            Assert.AreEqual(1, rod.ConstructorArgumentValues.NamedArgumentValues.Count);
            Assert.AreEqual("ecn", rod.ConstructorArgumentValues.GetNamedArgumentValue("endpointConfigurationName").Value);

            ChannelFactoryObject <IContract> cfo = ctx.GetObject("&channel") as ChannelFactoryObject <IContract>;

            Assert.IsNotNull(cfo);
            Assert.AreEqual(typeof(IContract), cfo.ObjectType);

            IContract contract = ctx.GetObject("channel") as IContract;

            Assert.IsNotNull(contract);
        }
Beispiel #5
0
        //[Test]
        public void CustomProperties()
        {
            NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
            IApplicationContext ctx = new XmlApplicationContext(
                ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.CustomProperties.xml", this.GetType()));

            Assert.IsTrue(ctx.ContainsObjectDefinition("channel"));

            RootObjectDefinition rod = ((IObjectDefinitionRegistry)ctx).GetObjectDefinition("channel") as RootObjectDefinition;

            Assert.IsNotNull(rod);

            Assert.IsTrue(rod.HasObjectType);
            Assert.AreEqual(typeof(ChannelFactoryObject <IContract>), rod.ObjectType);
            Assert.AreEqual(1, rod.ConstructorArgumentValues.NamedArgumentValues.Count);
            Assert.AreEqual("ecn", rod.ConstructorArgumentValues.GetNamedArgumentValue("endpointConfigurationName").Value);
            Assert.IsTrue(rod.PropertyValues.Contains("Credentials.Windows.ClientCredential"));
            Assert.AreEqual("Spring\\Bruno:gnirpS", rod.PropertyValues.GetPropertyValue("Credentials.Windows.ClientCredential").Value);

            ChannelFactoryObject <IContract> cfo = ctx.GetObject("&channel") as ChannelFactoryObject <IContract>;

            Assert.IsNotNull(cfo);
            Assert.AreEqual(typeof(IContract), cfo.ObjectType);
            Assert.AreEqual("Spring", cfo.Credentials.Windows.ClientCredential.Domain);
            Assert.AreEqual("Bruno", cfo.Credentials.Windows.ClientCredential.UserName);
            Assert.AreEqual("gnirpS", cfo.Credentials.Windows.ClientCredential.Password);

            IContract contract = ctx.GetObject("channel") as IContract;

            Assert.IsNotNull(contract);
        }
Beispiel #6
0
        public void ComponentsUseDefaults()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan5.xml", GetType()));
            var prototypeDef = _applicationContext.ObjectFactory.GetObjectDefinition("Prototype");

            Assert.That(prototypeDef.IsLazyInit, Is.True);
        }
        public void ConfigureUsingXmlApplicationContext_CanMergePropertyValues()
        {
            XmlApplicationContext appContext = new XmlApplicationContext(false, ReadOnlyXmlTestResource.GetFilePath("HttpApplicationConfigurerMergablePropertiesTests.xml", typeof(HttpApplicationConfigurerTests)));

            ParentHttpModule module = new ParentHttpModule();

            TestApplication appObject = new TestApplication(new ModuleEntry[]
            {
                new ModuleEntry("DirectoryServicesAuthentication", module)
            });

            HttpApplicationConfigurer.Configure(appContext, appObject);

            //base class property has carried through successfully
            Assert.Contains("GrandParentValue1", module.GrandParentProperty);

            //parent property values remain in the final instance
            Assert.Contains("ParentValue1", module.ParentProperty);
            Assert.Contains("ParentValue2", module.ParentProperty);
            Assert.Contains("ParentValue3", module.ParentProperty);
            Assert.Contains("ParentValue4", module.ParentProperty);

            //the new additional value has been merged into the property
            Assert.Contains("MergedValueToFind", module.ParentProperty);
        }
 public void Setup()
 {
     // IS WELLKNOWN NOW
     //NamespaceParserRegistry.RegisterParser(typeof(AopNamespaceParser));
     //ctx = new XmlApplicationContext( "assembly://Spring.Aop.Tests/Spring.Aop.Config/AopNamespaceParserTests.xml");
     ctx = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("AopNamespaceParserTests.xml", this.GetType()));
 }
Beispiel #9
0
        public void UseSpecifiedObjectNameGenerator()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan3.xml", GetType()));
            var objectDefinitionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames();

            Assert.That(objectDefinitionNames.Contains("prototype"), Is.True);
        }
 public void Setup()
 {
     appContext = new XmlApplicationContext(false,
                                            ReadOnlyXmlTestResource.GetFilePath(
                                                "VelocityEngineFactoryObjectTests.xml",
                                                typeof(VelocityEngineFactoryObjectTests)));
     model.Add("var1", TEST_VALUE);
 }
        public void SetUp()
        {
            string configLocation =
                ReadOnlyXmlTestResource.GetFilePath("objectNameAutoProxyCreatorTests.xml",
                                                    typeof(ObjectNameAutoProxyCreatorTests));

            ctx = new XmlApplicationContext(configLocation);
        }
        public void IncludeAttributeExpressionFilter()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.TypeScannerTestAttributeInclude.xml", GetType()));

            Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.EqualTo(6));
            Assert.That(_applicationContext.GetObject("SomeIncludeType2"), Is.Not.Null);
            Assert.That(() => { _applicationContext.GetObject("SomeExcludeType"); }, Throws.Exception.TypeOf <NoSuchObjectDefinitionException>());
        }
Beispiel #13
0
        //[Test]
        public void WithoutId()
        {
            NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
            IApplicationContext ctx = new XmlApplicationContext(
                ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.WithoutId.xml", this.GetType()));

            IDictionary <string, IContract> channels = ctx.GetObjects <IContract>();

            Assert.AreEqual(1, channels.Count);
        }
Beispiel #14
0
        public void RegisteredComponents()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.AttributeConfigParser.xml", GetType()));
            var objectDefintionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames();

            Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.True);
            Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.AUTOWIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.True);
            Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.REQUIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.True);
            Assert.That(objectDefintionNames.Contains(AttributeConfigUtils.INITDESTROY_ATTRIBUTE_PROCESSOR_OBJECT_NAME), Is.True);
        }
Beispiel #15
0
        public void ComponentWithQualifier()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan6.xml", GetType()));
            var objectDef = _applicationContext.ObjectFactory.GetObjectDefinition("Prototype") as ScannedGenericObjectDefinition;

            Assert.That(objectDef.HasQualifier(typeof(QualifierAttribute).Name), Is.True);

            var attr = objectDef.GetQualifier(typeof(QualifierAttribute).Name).GetAttribute(AutowireCandidateQualifier.VALUE_KEY);

            Assert.That(attr, Is.EqualTo("action"));
        }
Beispiel #16
0
        public void ComponentsUseSpecifiedName()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan2.xml", GetType()));
            var objectDefinitionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames();

            Assert.That(objectDefinitionNames.Count, Is.EqualTo(5 + 4));
            Assert.That(_applicationContext.GetObject("Component"), Is.Not.Null);
            Assert.That(_applicationContext.GetObject("Service"), Is.Not.Null);
            Assert.That(_applicationContext.GetObject("Repository"), Is.Not.Null);
            Assert.That(_applicationContext.GetObject("Controller"), Is.Not.Null);
            Assert.That(_applicationContext.GetObject("Configuration"), Is.Not.Null);
        }
Beispiel #17
0
        public void ViaXML()
        {
            IResource                  resource = new ReadOnlyXmlTestResource("PropertyResourceConfigurerTests.xml", GetType());
            XmlObjectFactory           xbf      = new XmlObjectFactory(resource);
            PropertyOverrideConfigurer poc      = (PropertyOverrideConfigurer)xbf.GetObject("OverrideConfigurer");

            Assert.IsNotNull(poc);
            poc.PostProcessObjectFactory(xbf);
            TestObject to = (TestObject)xbf.GetObject("Test2");

            Assert.AreEqual("Overriden Name", to.Name);
        }
        public void ViaXML()
        {
            IResource        resource         = new ReadOnlyXmlTestResource("PropertyResourceConfigurerTests.xml", GetType());
            XmlObjectFactory xbf              = new XmlObjectFactory(resource);
            PropertyPlaceholderConfigurer ppc = (PropertyPlaceholderConfigurer)xbf.GetObject("PlaceholderConfigurer");

            Assert.IsNotNull(ppc);
            ppc.PostProcessObjectFactory(xbf);
            TestObject to = (TestObject)xbf.GetObject("Test1");

            Assert.AreEqual("A DefName", to.Name);
        }
        public void ViaXMLAndConfigSection()
        {
            IResource        resource         = new ReadOnlyXmlTestResource("PropertyResourceConfigurerTests.xml", GetType());
            XmlObjectFactory xbf              = new XmlObjectFactory(resource);
            PropertyPlaceholderConfigurer ppc = (PropertyPlaceholderConfigurer)xbf.GetObject("ConfigSectionPlaceholderConfigurer");

            Assert.IsNotNull(ppc);
            ppc.PostProcessObjectFactory(xbf);

            Assert.AreEqual("name from section", ((TestObject)xbf.GetObject("Test3")).Name);
            Assert.AreEqual("name from sectiongroup/section", ((TestObject)xbf.GetObject("Test4")).Name);
        }
Beispiel #20
0
        public void ComponentsInDifferentScope()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan4.xml", GetType()));
            var singletonDef = _applicationContext.ObjectFactory.GetObjectDefinition("Singleton");
            var prototypeDef = _applicationContext.ObjectFactory.GetObjectDefinition("Prototype");

            Assert.That(singletonDef.IsSingleton, Is.True);
            Assert.That(singletonDef.Scope, Is.EqualTo(ObjectScope.Singleton.ToString().ToLower()));

            Assert.That(prototypeDef.IsSingleton, Is.False);
            Assert.That(prototypeDef.Scope, Is.EqualTo(ObjectScope.Prototype.ToString().ToLower()));
        }
Beispiel #21
0
        public void ComponentWithQualifierAttributes()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan6.xml", GetType()));
            var objectDef = _applicationContext.ObjectFactory.GetObjectDefinition("Attribute") as ScannedGenericObjectDefinition;
            var qualifier = objectDef.GetQualifier(typeof(MyQualifier).Name);

            Assert.That(qualifier, Is.Not.Null);

            var attr = qualifier.GetMetadataAttribute("Foo");

            Assert.That(attr, Is.Not.Null);
            Assert.That(attr.Value, Is.EqualTo("Funny"));
        }
        public void IsInheritanceBasedProxy()
        {
            using (var ctx = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("IsAopProxyTests.xml", this.GetType())))
            {
                var proxy = (TestObject)ctx["michael"];
                Assert.AreEqual("Michael", proxy.Name);

                Assert.True(AopUtils.IsInheritanceAopProxyType(proxy.GetType()));
                Assert.True(AopUtils.IsAopProxyType(proxy.GetType()));

                Assert.True(AopUtils.IsInheritanceAopProxy(proxy));
                Assert.True(AopUtils.IsAopProxy(proxy));
            }
        }
Beispiel #23
0
        public void ScanComponentsAndAddToContext()
        {
            var prefix = "ComponentScan.ScanComponentsAndAddToContext.";

            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan1.xml", GetType()));
            var objectDefinitionNames = _applicationContext.ObjectFactory.GetObjectDefinitionNames();

            Assert.That(objectDefinitionNames.Count, Is.EqualTo(5 + 4));
            Assert.That(_applicationContext.GetObject(prefix + "ComponentImpl"), Is.Not.Null);
            Assert.That(_applicationContext.GetObject(prefix + "ServiceImpl"), Is.Not.Null);
            Assert.That(_applicationContext.GetObject(prefix + "RepositoryImpl"), Is.Not.Null);
            Assert.That(_applicationContext.GetObject(prefix + "ControllerImpl"), Is.Not.Null);
            Assert.That(_applicationContext.GetObject(prefix + "ConfigurationImpl"), Is.Not.Null);
        }
        public void AdvisorAdapterRegistrationManagerPresentInContext()
        {
            string configLocation   = ReadOnlyXmlTestResource.GetFilePath("withBPPContext.xml", typeof(AdvisorAdapterRegistrationTests));
            IApplicationContext ctx = new XmlApplicationContext(configLocation);
            ITestObject         to  = (ITestObject)ctx.GetObject("testObject");

            // just invoke any method to see if advice fired
            try
            {
                to.ReturnsThis();
                Assert.AreEqual(1, GetAdviceImpl(to).InvocationCounter);
            }
            catch (UnknownAdviceTypeException)
            {
                Assert.Fail("Should not throw UnknownAdviceTypeException");
            }
        }
        public void ConfigureUsingXmlApplicationContext()
        {
            XmlApplicationContext appContext = new XmlApplicationContext(false, ReadOnlyXmlTestResource.GetFilePath("HttpApplicationConfigurerTests.xml", typeof(HttpApplicationConfigurerTests)));

            TestModule m1 = new TestModule();
            TestModule m2 = new TestModule();

            TestApplication appObject = new TestApplication(new ModuleEntry[]
            {
                new ModuleEntry("TestModule1", m1)
                , new ModuleEntry("TestModule2", m2),
            });

            HttpApplicationConfigurer.Configure(appContext, appObject);
            // app configured
            Assert.AreEqual(appContext.GetObject("testObject"), appObject.TestObject);
            // modules configured
            Assert.AreEqual(appContext.GetObject("testObject1"), m1.TestObject);
            Assert.AreEqual(null, m2.TestObject);
        }
Beispiel #26
0
        public void SetUp()
        {
            IResource resource = new ReadOnlyXmlTestResource("concurrent.xml", GetType());

            factory = new XmlObjectFactory(resource);
        }
 public void Setup()
 {
     NamespaceParserRegistry.RegisterParser(typeof(EmsNamespaceParser));
     ctx = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("EmsNamespaceHandlerTests.xml", GetType()));
 }
Beispiel #28
0
 public void Setup()
 {
     _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("SimpleScanTest.xml", GetType()));
 }
Beispiel #29
0
        public void NegativeAssemblyNameProvided()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.BaseAssemblyTestNegative.xml", GetType()));

            Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.EqualTo(4));
        }
Beispiel #30
0
        public void MultipleAssemblyNameProvided()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.BaseAssemblyTestMultiple.xml", GetType()));

            Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.GreaterThan(0));
        }