示例#1
0
文件: TestTang.cs 项目: beysims/reef
        public void TestOneNamedStringArgVolatile()
        {
            OneNamedStringArg a = tang.NewInjector().GetInstance <OneNamedStringArg>();

            Assert.AreEqual("default", a.s);
            IInjector i = tang.NewInjector();

            i.BindVolatileParameter(GenericType <OneNamedStringArg.A> .Class, "volatile");
            Assert.AreEqual("volatile", i.GetInstance <OneNamedStringArg>().s);
        }
示例#2
0
文件: TestTang.cs 项目: beysims/reef
        public void TestOneNamedStringArgBind()
        {
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
            OneNamedStringArg       a  = tang.NewInjector(cb.Build()).GetInstance <OneNamedStringArg>();

            Assert.AreEqual("default", a.s);
            cb.BindNamedParameter <OneNamedStringArg.A, string>(GenericType <OneNamedStringArg.A> .Class, "not default");
            IInjector i = tang.NewInjector(cb.Build());

            Assert.AreEqual("not default", i.GetInstance <OneNamedStringArg>().s);
        }
示例#3
0
文件: TestTang.cs 项目: beysims/reef
        public void TestOneNamedStringArgCantRebind()
        {
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
            OneNamedStringArg       a  =
                (OneNamedStringArg)tang.NewInjector(cb.Build()).GetInstance(typeof(OneNamedStringArg));

            Assert.AreEqual("default", a.s);
            cb.BindNamedParameter <OneNamedStringArg.A, string>(GenericType <OneNamedStringArg.A> .Class, "not default");
            IInjector i = tang.NewInjector(cb.Build());

            Assert.AreEqual("not default", ((OneNamedStringArg)i.GetInstance(typeof(OneNamedStringArg))).s);
            string msg = null;

            try
            {
                i.BindVolatileParameter(GenericType <OneNamedStringArg.A> .Class, "volatile");
                msg =
                    "Attempt to re-bind named parameter Org.Apache.Reef.Tang.OneNamedStringArg$A.  Old value was [not default] new value is [volatile]";
            }
            catch (Exception)
            {
            }
            Assert.IsNull(msg);
        }