Beispiel #1
0
        public void TryGetNotFoundTest()
        {
            var context = TestsFactory.BindingContext();
            int exit    = 0;

            Assert.DoesNotThrow(() => context.TryGet <int>(out exit));
        }
Beispiel #2
0
        public void TryGetNamedNotFoundReturnFalseTest()
        {
            var context = TestsFactory.BindingContext();
            int exit    = 0;

            Assert.That(!context.TryGet <int>("testName", out exit));
        }
        public void CanFallbakcToMultipleTypes()
        {
            var context = TestsFactory.BindingContext();

            context.FallBack((name, key, extras) => {
                if (key.Key.Equals(typeof(string)))
                {
                    return("str");
                }

                return(null);
            });

            context.FallBack((name, key, extras) => {
                if (key.Key.Equals(typeof(int)))
                {
                    return(3);
                }

                return(null);
            });


            var result = context.Get <string>();

            Assert.AreEqual(result, "str");
        }
Beispiel #4
0
        public void TypedGetTest()
        {
            var context = TestsFactory.BindingContext();

            context.Bind <int> ().To(() => 42);

            Assert.DoesNotThrow(() => TypedGet <int>(context));
        }
Beispiel #5
0
        public void GetItselfEmptyName()
        {
            var context = TestsFactory.BindingContext();

            IBindingContext meAgain = context.Get <IBindingContext>();

            Assert.AreEqual(context, meAgain);
        }
Beispiel #6
0
        public void GetItself()
        {
            var context = TestsFactory.BindingContext();

            IBindingContext meAgain = context.Get <IBindingContext>(InnerBindingNames.CurrentBindingContext);

            Assert.AreEqual(context, meAgain);
        }
Beispiel #7
0
        public void NamedBindingDifferentNameError()
        {
            IBindingContext context = TestsFactory.BindingContext();

            context.Bind <int>("foo").To(() => 45);

            Assert.Throws <BindingNotFound>(() => context.Get <int>("notFoo"));
        }
Beispiel #8
0
        public void BindToAnObjectReturnsTheRightObject()
        {
            var context = TestsFactory.BindingContext();

            context.Bind <int>().To(33);

            Assert.AreEqual(33, context.Get <int>());
        }
Beispiel #9
0
        public void TryGetFoundTest()
        {
            var context = TestsFactory.BindingContext();

            context.Bind <int>().To(() => 93);
            int exit = 0;

            Assert.That(context.TryGet <int>(out exit));
        }
Beispiel #10
0
        public void TypedInterfaceGetTest()
        {
            var context = TestsFactory.BindingContext();

            var bind = context.Bind <ITestInterface> ();

            bind.To(() => new TestClass());

            Assert.DoesNotThrow(() => TypedGet <ITestInterface>(context));
        }
Beispiel #11
0
        public void BindingSimpleInt()
        {
            IBindingContext context = TestsFactory.BindingContext();

            int expected = 45;

            context.Bind <int>().To(() => expected);

            Assert.AreEqual(context.Get <int>(), expected);
        }
Beispiel #12
0
        public void OneArgumentBindingError()
        {
            //Requires a string to get the int binging

            IBindingContext context = TestsFactory.BindingContext();

            context.Bind <int>().With <string>().To((value) => 45);

            Assert.Throws <BindingNotFound>(() => context.Get <int>());
        }
Beispiel #13
0
        public void TryGetFoundRightValueTest()
        {
            var context = TestsFactory.BindingContext();

            context.Bind <int>().To(() => 93);
            int exit = 0;

            context.TryGet <int>(out exit);
            Assert.AreEqual(93, exit);
        }
Beispiel #14
0
        public void BindToSingletonReturnsTheSame()
        {
            var context = TestsFactory.BindingContext();
            var val     = 0;

            context.Bind <int>().ToSingleton(() => val++);
            var first  = context.Get <int>();
            var second = context.Get <int>();

            Assert.AreEqual(first, second);
        }
Beispiel #15
0
        public void UnsafeSelfRequirementBindingError()
        {
            IBindingContext     context     = TestsFactory.BindingContext();
            IBindingRequirement requirement = BindingRequirements.Instance.With <int>();

            System.Func <int> func = () => 45;

            IBinding binding = new Binding(func, requirement);

            Assert.Throws <BindingSelfRequirement>(() => context.Unsafe.Bind(typeof(int)).To(binding));
        }
Beispiel #16
0
        public void CanGetValueFromSubcontext()
        {
            var context    = TestsFactory.BindingContext();
            var subcontext = context.GetSubcontext("a");

            subcontext.Bind <int>().To(25);

            var first = context.GetSubcontext("a").Get <int>();

            Assert.AreEqual(25, first);
        }
Beispiel #17
0
        public void UnsafeNamedBinding()
        {
            IBindingContext context = TestsFactory.BindingContext();

            System.Func <int> func    = () => 45;
            IBinding          binding = new Binding(func);

            context.Unsafe.Bind("name", typeof(int)).To(binding);

            Assert.AreEqual(context.Get <int>("name"), 45);
        }
Beispiel #18
0
        public void UnsafeTypedGetTest()
        {
            var context = TestsFactory.BindingContext();

            context.Bind <int>().To(() => 42);

            var name = new BindingName(InnerBindingNames.Empty);
            var key  = new BindingKey(typeof(int));

            Assert.DoesNotThrow(() => context.Unsafe.TryGet(name, key, new object[0]));
        }
Beispiel #19
0
        public void NamedBindingInt()
        {
            IBindingContext context = TestsFactory.BindingContext();

            int    expected    = 45;
            string bindingName = "foo";

            context.Bind <int>(bindingName).To(() => expected);

            Assert.AreEqual(context.Get <int>(bindingName), expected);
        }
Beispiel #20
0
        public void BindingContextFallsBackToFallback()
        {
            var context = TestsFactory.BindingContext();

            context.FallBack((name, key, extras) => {
                return(3);
            });

            var result = context.Get <int>();

            Assert.AreEqual(result, 3);
        }
Beispiel #21
0
        public void OneArgumentBinding()
        {
            IBindingContext context = TestsFactory.BindingContext();

            context.Bind <int>().With <string>().To((strParam) => 45);

            context.Bind <string>().To(() => "uhul");

            int ret = context.Get <int>();

            Assert.AreEqual(ret, 45);
        }
Beispiel #22
0
        public void SubcontextFallbacksAllTheWayUp()
        {
            var context = TestsFactory.BindingContext();

            context.Bind <string>().To("str");

            var subcontext = context.GetSubcontext("a", "b");

            var str = subcontext.Get <string>();

            Assert.AreEqual(str, "str");
        }
Beispiel #23
0
        public void SubcontextHasMainContextAsFallback()
        {
            var context = TestsFactory.BindingContext();

            context.Bind <string>().To("str");

            var subcontext = context.GetSubcontext("a");

            var str = subcontext.Get <string>();

            Assert.AreEqual(str, "str");
        }
Beispiel #24
0
        public void FallbackToAnotherContext()
        {
            var context1 = TestsFactory.BindingContext();
            var context2 = TestsFactory.BindingContext();

            context1.Bind <string>().To("str");

            context2.FallBack(context1);

            var result = context2.Get <string>();

            Assert.AreEqual(result, "str");
        }
Beispiel #25
0
        public void FallbackConsiderNames()
        {
            var context1 = TestsFactory.BindingContext();
            var context2 = TestsFactory.BindingContext();

            context1.Bind <string>().To("str");
            context1.Bind <string>("name").To("str2");

            context2.FallBack(context1);

            var result = context2.Get <string>("name");

            Assert.AreEqual(result, "str2");
        }
Beispiel #26
0
        public void TwoArgumentBinding()
        {
            IBindingContext context = TestsFactory.BindingContext();

            context.Bind <int>().With <string>().With <float>().To((str, flt) => 45);

            context.Bind <string>().To(() => "uhul");

            context.Bind <float>().To(() => 3.0f);

            int ret = context.Get <int>();

            Assert.AreEqual(ret, 45);
        }
Beispiel #27
0
        public void UsesOriginalWhenThereIsNoNeedToFallback()
        {
            var context1 = TestsFactory.BindingContext();
            var context2 = TestsFactory.BindingContext();

            context1.Bind <string>().To("fallback");
            context2.Bind <string>().To("original");

            context2.FallBack(context1);

            var result = context2.Get <string>();

            Assert.AreEqual(result, "original");
        }
Beispiel #28
0
        public void OneArgumentNamedBinding()
        {
            IBindingContext context = TestsFactory.BindingContext();

            int expected = 45;

            context.Bind <int>().With <string>("MyText").To((value) => expected);

            context.Bind <string>("MyText").To(() => "uhul");

            int ret = context.Get <int>();

            Assert.AreEqual(ret, expected);
        }
Beispiel #29
0
        public void OneCorrectArgumentBinding()
        {
            IBindingContext context = TestsFactory.BindingContext();

            string parameter = "";

            context.Bind <int>().With <string>().To((value) => { parameter = value; return(45); });

            context.Bind <string>().To(() => "uhul");

            context.Get <int>();

            Assert.AreEqual(parameter, "uhul");
        }
Beispiel #30
0
        public void FallbackToAnotherWorksEvenIfFirstContextDoesntContain()
        {
            var context1 = TestsFactory.BindingContext();
            var context2 = TestsFactory.BindingContext();
            var context3 = TestsFactory.BindingContext();

            context2.Bind <string>().To("str");

            context3.FallBack(context1);
            context3.FallBack(context2);

            var result = context3.Get <string>();

            Assert.AreEqual(result, "str");
        }