コード例 #1
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);
        }
コード例 #2
0
 public void Setup()
 {
     // WELLKNOWN
     //NamespaceParserRegistry.RegisterParser(typeof(NmsNamespaceParser));
     ctx   = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("NmsNamespaceHandlerTests.xml", GetType()));
     mocks = new MockRepository();
 }
コード例 #3
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);
        }
コード例 #4
0
        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);
        }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
0
 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()));
 }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
0
        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>());
        }
コード例 #12
0
 public void Setup()
 {
     appContext = new XmlApplicationContext(false,
                                            ReadOnlyXmlTestResource.GetFilePath(
                                                "VelocityEngineFactoryObjectTests.xml",
                                                typeof(VelocityEngineFactoryObjectTests)));
     model.Add("var1", TEST_VALUE);
 }
コード例 #13
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);
        }
コード例 #14
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);
        }
コード例 #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"));
        }
コード例 #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);
        }
コード例 #17
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()));
        }
コード例 #18
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"));
        }
コード例 #19
0
        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));
            }
        }
コード例 #20
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);
        }
コード例 #21
0
        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");
            }
        }
コード例 #22
0
        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);
        }
 protected override void CreateApplicationContext()
 {
     _ctx = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("SimpleScanTest.xml", GetType()));
 }
コード例 #24
0
 public void Setup()
 {
     _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("SimpleScanTest.xml", GetType()));
 }
コード例 #25
0
        public void NegativeAssemblyNameProvided()
        {
            _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.BaseAssemblyTestNegative.xml", GetType()));

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

            Assert.That(_applicationContext.GetObjectDefinitionNames().Count, Is.GreaterThan(0));
        }
コード例 #27
0
 public void BaseAssembliesAttributeRequired()
 {
     Assert.That(delegate { _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.BaseAssemblyTestWithout.xml", GetType())); },
                 Throws.Exception);
 }
コード例 #28
0
        public void TestAutoProxyCreation()
        {
            XmlApplicationContext         context         = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("advisorAutoProxyCreatorCircularReferencesTests.xml", typeof(AdvisorAutoProxyCreatorCircularReferencesTests)));
            CountingAfterReturningAdvisor countingAdvisor = (CountingAfterReturningAdvisor)context.GetObject("testAdvisor");

            // direct deps of AutoProxyCreator are not eligable for proxying
            Assert.IsFalse(AopUtils.IsAopProxy(context.GetObject("aapc")));
            Assert.IsFalse(AopUtils.IsAopProxy(countingAdvisor));

            TestObjectFactoryObject testObjectFactory = (TestObjectFactoryObject)context.GetObject("&testObjectFactory");

            Assert.IsFalse(AopUtils.IsAopProxy(testObjectFactory));

            Assert.IsFalse(AopUtils.IsAopProxy(context.GetObject("someOtherObject")));

            // this one is completely independent
            Assert.IsTrue(AopUtils.IsAopProxy(context.GetObject("independentObject")));


            // Asserts SPRNET-1225 - advisor dependencies most not be auto-proxied
            object testObject = context.GetObject("testObjectFactory");

            Assert.IsFalse(AopUtils.IsAopProxy(testObject));

            // Asserts SPRNET-1224 - factory product most be cached
            context.GetObject("testObjectFactory");
            testObjectFactory.GetObjectCounter = 0;
            context.GetObject("testObjectFactory");
            Assert.AreEqual(0, testObjectFactory.GetObjectCounter);

            ICloneable someOtherObject = (ICloneable)context.GetObject("someOtherObject");

            someOtherObject.Clone();
            ICloneable independentObject = (ICloneable)context.GetObject("independentObject");

            independentObject.Clone();
            Assert.AreEqual(1, countingAdvisor.GetCalls());
        }
コード例 #29
0
 public void Setup()
 {
     NamespaceParserRegistry.RegisterParser(typeof(EmsNamespaceParser));
     ctx = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("EmsNamespaceHandlerTests.xml", GetType()));
 }
コード例 #30
0
 public void Setup()
 {
     NamespaceParserRegistry.RegisterParser(typeof(ContextNamespaceParser));
     _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("SimpleScanTest.xml", GetType()));
 }