Пример #1
0
        protected override void Init()
        {
            SetupConfiguration();
            IConversionManager cm = (IConversionManager)Kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey);

            cm.Add(new RegularExpressionConverter());
            Kernel.AddComponent("policy.intercepter", typeof(AdvisorInterceptor));
            Kernel.ComponentRegistered += new global::Castle.MicroKernel.ComponentDataDelegate(ComponentRegistered);
        }
Пример #2
0
        public void GetValue_Simple_Works_As_Expected()
        {
            // arrange
            string path = EmbeddedResourceUtil.ExportToPath("Castle.Windsor.Extensions.Test.data", "castle.config", Path.GetTempPath());

            PropertiesSubSystem subSystem = new PropertiesSubSystem(path);
            WindsorContainer    container = new WindsorContainer();

            container.Kernel.AddSubSystem(PropertiesSubSystem.SubSystemKey, subSystem);

            IConversionManager manager = (IConversionManager)container.Kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey);

            manager.Add(new PersonTypeConverter());

            IPropertyResolver resolver = subSystem.Resolver;

            // act
            string strParam = resolver.GetValue("strParam");
            double dblParam = resolver.GetValue <double>("dblParam");

            string[] arrParam = resolver.GetValue <string[]>("arrParam");
            IDictionary <string, string> dictParam = resolver.GetValue <IDictionary <string, string> >("dictParam");
            List <double> listParam = resolver.GetValue <List <double> >("listParam");

            Person[] personArr = resolver.GetValue <Person[]>("personArr");

            // assert
            Assert.AreEqual("this is string", strParam);
            Assert.AreEqual(20.12, dblParam);
            Assert.AreEqual("arr item 1", arrParam[0]);
            Assert.AreEqual(strParam, arrParam[1]);
            Assert.AreEqual(@"..\etc\config.ini", arrParam[2]);
            Assert.IsTrue(dictParam.ContainsKey("key1"));
            Assert.IsTrue(dictParam.ContainsKey("key2"));
            Assert.AreEqual("value 1", dictParam["key1"]);
            Assert.AreEqual("value 2", dictParam["key2"]);
            Assert.AreEqual(21.2, listParam[0]);
            Assert.AreEqual(3, listParam[1]);
            Assert.AreEqual(dblParam, listParam[2]);
            Assert.AreEqual("Mihir", personArr[0].Name);
            Assert.AreEqual(30, personArr[0].PersonAge);
            Assert.AreEqual("Sneha", personArr[1].Name);
            Assert.AreEqual(33, personArr[1].PersonAge);

            // act
            Dependency[] dependencies = resolver.TryGetDependencies <TestClass>("strParam", "arrParam", "refParam", "dictParam", "listParam", "personArr");

            container.Register(Component.For <TestClass>().DependsOn(dependencies));

            // assert
            Assert.IsNotNull(container.Resolve <TestClass>());
        }