public void TestInstantiation() { IInjectionBinding defaultBinding = new InjectionBinding(resolver).Bind <InjectableSuperClass> ().To <InjectableDerivedClass> (); InjectableDerivedClass testResult = factory.Get(defaultBinding) as InjectableDerivedClass; Assert.IsNotNull(testResult); }
public void TestValueMap() { InjectableDerivedClass testvalue = new InjectableDerivedClass(); testvalue.intValue = 42; IInjectionBinding binding = new InjectionBinding(resolver).Bind <InjectableSuperClass> ().To <InjectableDerivedClass> ().ToValue(testvalue); InjectableDerivedClass testResult = factory.Get(binding) as InjectableDerivedClass; Assert.IsNotNull(testResult); Assert.That(testResult.intValue == testvalue.intValue); Assert.That(testResult.intValue == 42); }
public void TestInstantiateSingleton() { IInjectionBinding defaultBinding = new InjectionBinding(resolver).Bind <InjectableSuperClass> ().To <InjectableDerivedClass> ().ToSingleton(); InjectableDerivedClass testResult = factory.Get(defaultBinding) as InjectableDerivedClass; Assert.IsNotNull(testResult); //Set a value testResult.intValue = 42; //Now get an instance again and ensure it's the same instance InjectableDerivedClass testResult2 = factory.Get(defaultBinding) as InjectableDerivedClass; Assert.That(testResult2.intValue == 42); }
public void TestInstantiationFactory() { IInjectionBinding defaultBinding = new InjectionBinding(resolver).Bind <InjectableSuperClass> ().To <InjectableDerivedClass> (); InjectableDerivedClass testResult = factory.Get(defaultBinding) as InjectableDerivedClass; Assert.IsNotNull(testResult); int defaultValue = testResult.intValue; //Set a value testResult.intValue = 42; //Now get an instance again and ensure it's a different instance InjectableDerivedClass testResult2 = factory.Get(defaultBinding) as InjectableDerivedClass; Assert.That(testResult2.intValue == defaultValue); }
public void TestValueChainBinding() { int a = 0; InjectableDerivedClass testValue = new InjectableDerivedClass(); Binder.BindingResolver resolver = delegate(IBinding binding) { if (a == 2) { Assert.That(binding.value == testValue); InjectionBindingType correctType = (a == 0) ? InjectionBindingType.DEFAULT : InjectionBindingType.VALUE; Assert.That((binding as InjectionBinding).type == correctType); } a++; }; new InjectionBinding(resolver).Bind <InjectableSuperClass>().To <InjectableDerivedClass>().ToValue(testValue); }
public void TestValueChainBinding() { int a = 0; InjectableDerivedClass testValue = new InjectableDerivedClass (); Binder.BindingResolver resolver = delegate (IBinding binding) { if (a == 2) { Assert.That (binding.value == testValue); InjectionBindingType correctType = (a == 0) ? InjectionBindingType.DEFAULT : InjectionBindingType.VALUE; Assert.That ((binding as InjectionBinding).type == correctType); } a++; }; new InjectionBinding (resolver).Key<InjectableSuperClass>().To<InjectableDerivedClass>().ToValue (testValue); }
public void TestNamedSingletons() { //Create two named singletons IInjectionBinding defaultBinding = new InjectionBinding(resolver).Bind <InjectableSuperClass> ().To <InjectableDerivedClass> ().ToName(SomeEnum.ONE).ToSingleton(); IInjectionBinding defaultBinding2 = new InjectionBinding(resolver).Bind <InjectableSuperClass> ().To <InjectableDerivedClass> ().ToName(SomeEnum.TWO).ToSingleton(); InjectableDerivedClass testResult = factory.Get(defaultBinding) as InjectableDerivedClass; int defaultValue = testResult.intValue; Assert.IsNotNull(testResult); //Set a value testResult.intValue = 42; //Now get an instance again and ensure it's a different instance InjectableDerivedClass testResult2 = factory.Get(defaultBinding2) as InjectableDerivedClass; Assert.IsNotNull(testResult2); Assert.That(testResult2.intValue == defaultValue); }
public void TestValueMap() { InjectableDerivedClass testvalue = new InjectableDerivedClass (); testvalue.intValue = 42; IInjectionBinding binding = new InjectionBinding (resolver).Key<InjectableSuperClass> ().To <InjectableDerivedClass> ().ToValue (testvalue); InjectableDerivedClass testResult = factory.Get (binding) as InjectableDerivedClass; Assert.IsNotNull (testResult); Assert.That (testResult.intValue == testvalue.intValue); Assert.That (testResult.intValue == 42); }