Exemple #1
0
 public InjectionBinding(Binder.BindingResolver resolver)
 {
     this.resolver         = resolver;
     keyConstraint         = BindingConstraintType.MANY;
     valueConstraint       = BindingConstraintType.ONE;
     supplyList.constraint = BindingConstraintType.MANY;
 }
        public void TestGetSupply()
        {
            Type[] supplied = new Type[3];
            supplied [0] = typeof(HasANamedInjection);
            supplied [1] = typeof(HasANamedInjection2);
            supplied [2] = typeof(InjectsClassToBeInjected);
            int iterator = 0;

            Binder.BindingResolver resolver = delegate(IBinding bound)
            {
                object[] value = (bound as IInjectionBinding).GetSupply();
                Assert.AreEqual(value[value.Length - 1], supplied[iterator]);
            };

            InjectionBinding binding = new InjectionBinding(resolver);

            while (iterator < 3)
            {
                binding.SupplyTo(supplied[iterator]);
                iterator++;
            }

            object[] supply = binding.GetSupply();
            Assert.AreEqual(3, supply.Length);

            for (var a = 0; a < supply.Length; a++)
            {
                Assert.AreEqual(supply[a], supplied[a]);
            }
        }
Exemple #3
0
        public Binding(Binder.BindingResolver resolver)
        {
            this.resolver = resolver;
            _key          = new SemiBinding();
            _value        = new SemiBinding();
            _name         = new SemiBinding();

            keyConstraint   = BindingConstraintType.ONE;
            nameConstraint  = BindingConstraintType.ONE;
            valueConstraint = BindingConstraintType.MANY;
        }
        public void TestSupplyOne()
        {
            Binder.BindingResolver resolver = delegate(IBinding bound)
            {
                object[] value = (bound as IInjectionBinding).GetSupply();
                Assert.AreEqual(value[0], typeof(HasANamedInjection));
            };
            InjectionBinding binding = new InjectionBinding(resolver);

            binding.SupplyTo <HasANamedInjection> ();
        }
        public void TestSingletonChainBinding()
        {
            int a = 0;

            Binder.BindingResolver resolver = delegate(IBinding binding)
            {
                Assert.That(binding.value == typeof(InjectableDerivedClass));
                InjectionBindingType correctType = (a == 0) ? InjectionBindingType.DEFAULT : InjectionBindingType.SINGLETON;
                Assert.That((binding as InjectionBinding).type == correctType);
                a++;
            };
            new InjectionBinding(resolver).Bind <InjectableSuperClass> ().To <InjectableDerivedClass> ().ToSingleton();
        }
        public void TestValueType()
        {
            const string TEST_KEY = "TEST_KEY";

            Binder.BindingResolver resolver = delegate(IBinding binding)
            {
                (binding as IInjectionBinding).type = InjectionBindingType.VALUE;
                Assert.That(TEST_KEY == binding.value as string);
                Assert.That((binding as InjectionBinding).type == InjectionBindingType.VALUE);
            };
            InjectionBinding defaultBinding = new InjectionBinding(resolver);

            defaultBinding.To(TEST_KEY);
        }
        public void TestIllegalValueBinding()
        {
            MarkerClass illegalValue = new MarkerClass();

            Binder.BindingResolver resolver     = delegate(IBinding binding){};
            TestDelegate           testDelegate = delegate()
            {
                new InjectionBinding(resolver).Bind <InjectableSuperClass> ().To <InjectableDerivedClass> ().ToValue(illegalValue);
            };
            InjectionException ex =
                Assert.Throws <InjectionException> (testDelegate);

            Assert.That(ex.type == InjectionExceptionType.ILLEGAL_BINDING_VALUE);
        }
        public void TestUnsupply()
        {
            Binder.BindingResolver resolver = delegate(IBinding bound)
            {
            };
            InjectionBinding binding = new InjectionBinding(resolver);

            binding.To <ClassToBeInjected>().SupplyTo <HasANamedInjection> ();
            Assert.AreEqual(typeof(HasANamedInjection), binding.GetSupply()[0]);
            Assert.AreEqual(typeof(ClassToBeInjected), binding.value);

            binding.Unsupply <HasANamedInjection> ();
            Assert.IsNull(binding.GetSupply());
        }
        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 CommandBinding(Binder.BindingResolver resolver) : base(resolver)
 {
     _value.uniqueValues = false;
 }
 public void SetUp()
 {
     factory  = new InjectorFactory();
     resolver = delegate(IBinding binding){};
 }
Exemple #12
0
 public Binding(Binder.BindingResolver resolver)
 {
     this.Resolver = resolver;
     Binded        = new Dictionary <object, object>();
     SingleRunList = new Dictionary <object, bool>();
 }
 public void SetUp()
 {
     factory = new InjectorFactory ();
     resolver = delegate (IBinding binding){};
 }
Exemple #14
0
 public EventBinding(Binder.BindingResolver resolver) : base(resolver)
 {
     keyConstraint   = BindingConstraintType.ONE;
     valueConstraint = BindingConstraintType.MANY;
     callbackTypes   = new Dictionary <Delegate, EventCallbackType>();
 }
Exemple #15
0
 public EventBinding(Binder.BindingResolver resolver) : base(resolver)
 {
     keyConstraint   = BindingConstraintType.ONE;
     valueConstraint = BindingConstraintType.MANY;
     nameConstraint  = BindingConstraintType.ONE;
 }
 public CommandBinding(Binder.BindingResolver resolver) : base(resolver)
 {
 }
Exemple #17
0
 public SequenceBinding(Binder.BindingResolver resolver) : base(resolver)
 {
 }
Exemple #18
0
 public MediationBinding(Binder.BindingResolver resolver) : base(resolver)
 {
 }
Exemple #19
0
 public MediationBinding(Binder.BindingResolver resolver) : base(resolver)
 {
     _abstraction            = new SemiBinding();
     _abstraction.constraint = BindingConstraintType.ONE;
 }
Exemple #20
0
 public Binding(Binder.BindingResolver resolver)
 {
     this.resolver = resolver;
     binded        = new Dictionary <object, object>();
 }