public void TestRepeatedNamedArgs() { IInjector i = tang.NewInjector(); i.BindVolatileParameter(GenericType <RepeatedNamedSingletonArgs.A> .Class, (MustBeSingleton)i.GetInstance(typeof(MustBeSingleton))); i.BindVolatileParameter(GenericType <RepeatedNamedSingletonArgs.B> .Class, (MustBeSingleton)i.GetInstance(typeof(MustBeSingleton))); i.GetInstance(typeof(RepeatedNamedSingletonArgs)); }
public void TestTwoNamedStringArgsBindVolatile() { ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(); TwoNamedStringArgs a = tang.NewInjector(cb.Build()).GetInstance <TwoNamedStringArgs>(); Assert.AreEqual("defaultA", a.a); Assert.AreEqual("defaultB", a.b); IInjector i = tang.NewInjector(cb.Build()); i.BindVolatileParameter(GenericType <TwoNamedStringArgs.A> .Class, "not defaultA"); i.BindVolatileParameter(GenericType <TwoNamedStringArgs.B> .Class, "not defaultB"); Assert.AreEqual("not defaultA", i.GetInstance <TwoNamedStringArgs>().a); Assert.AreEqual("not defaultB", i.GetInstance <TwoNamedStringArgs>().b); }
public void TestOneNamedSingletonOKArgs() { IInjector i = tang.NewInjector(); i.BindVolatileParameter(GenericType <OneNamedSingletonArgs.A> .Class, i.GetInstance <MustBeSingleton>()); OneNamedSingletonArgs o = i.GetInstance <OneNamedSingletonArgs>(); Assert.IsNotNull(o); }
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); }
public void TestBindVolatileParameterForSet() { IInjector i = TangFactory.GetTang().NewInjector(); ISet <INumber> numbers = new HashSet <INumber>(); numbers.Add(new Integer(42)); numbers.Add(new Float(42.0001f)); i.BindVolatileParameter(GenericType <SetOfClasses> .Class, numbers); ISet <INumber> actual = ((Pool)i.GetInstance(typeof(Pool))).Numbers; Assert.True(actual.Contains(new Integer(42))); Assert.True(actual.Contains(new Float(42.0001f))); }
public void TestTwoNamedStringArgsReBindVolatileFail() { ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(); TwoNamedStringArgs a = tang.NewInjector(cb.Build()).GetInstance <TwoNamedStringArgs>(); Assert.AreEqual("defaultA", a.a); Assert.AreEqual("defaultB", a.b); cb.BindNamedParameter <TwoNamedStringArgs.A, string>(GenericType <TwoNamedStringArgs.A> .Class, "not defaultA"); cb.BindNamedParameter <TwoNamedStringArgs.B, string>(GenericType <TwoNamedStringArgs.B> .Class, "not defaultB"); IInjector i = tang.NewInjector(cb.Build()); string msg = null; try { i.BindVolatileParameter(GenericType <TwoNamedStringArgs.A> .Class, "not defaultA"); i.BindVolatileParameter(GenericType <TwoNamedStringArgs.B> .Class, "not defaultB"); msg = "Attempt to re-bind named parameter TwoNamedStringArgs+A. Old value was [not defaultA] new value is [not defaultA]"; } catch (Exception) { } Assert.IsNull(msg); }
public void TestInjectionWithSetFromSameInterface() { IConfiguration c = TangFactory.GetTang() .NewConfigurationBuilder() .BindImplementation(GenericType <INumber> .Class, GenericType <PoolNumber> .Class) .Build(); IInjector i = TangFactory.GetTang().NewInjector(c); ISet <INumber> numbers = new HashSet <INumber>(); numbers.Add(new Integer(42)); numbers.Add(new Float(42.0001f)); i.BindVolatileParameter(GenericType <SetOfClasses> .Class, numbers); var actual = ((PoolNumber)i.GetInstance(typeof(INumber))).Numbers; Assert.True(actual.Contains(new Integer(42))); Assert.True(actual.Contains(new Float(42.0001f))); }
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); }