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

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

            Assert.That(!context.TryGet <int>("testName", out exit));
        }
示例#3
0
        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");
        }
示例#4
0
        public void TypedGetTest()
        {
            var context = TestsFactory.BindingContext();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            int expected = 45;

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

            Assert.AreEqual(context.Get <int>(), expected);
        }
示例#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>());
        }
示例#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);
        }
示例#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);
        }
示例#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));
        }
示例#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);
        }
示例#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);
        }
示例#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]));
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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");
        }
示例#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");
        }
示例#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");
        }
示例#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");
        }
示例#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);
        }
示例#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");
        }
示例#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);
        }
示例#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");
        }
示例#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");
        }