public void TryGetNotFoundTest() { var context = TestsFactory.BindingContext(); int exit = 0; Assert.DoesNotThrow(() => context.TryGet <int>(out exit)); }
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"); }
public void TypedGetTest() { var context = TestsFactory.BindingContext(); context.Bind <int> ().To(() => 42); Assert.DoesNotThrow(() => TypedGet <int>(context)); }
public void GetItselfEmptyName() { var context = TestsFactory.BindingContext(); IBindingContext meAgain = context.Get <IBindingContext>(); Assert.AreEqual(context, meAgain); }
public void GetItself() { var context = TestsFactory.BindingContext(); IBindingContext meAgain = context.Get <IBindingContext>(InnerBindingNames.CurrentBindingContext); Assert.AreEqual(context, meAgain); }
public void NamedBindingDifferentNameError() { IBindingContext context = TestsFactory.BindingContext(); context.Bind <int>("foo").To(() => 45); Assert.Throws <BindingNotFound>(() => context.Get <int>("notFoo")); }
public void BindToAnObjectReturnsTheRightObject() { var context = TestsFactory.BindingContext(); context.Bind <int>().To(33); Assert.AreEqual(33, context.Get <int>()); }
public void TryGetFoundTest() { var context = TestsFactory.BindingContext(); context.Bind <int>().To(() => 93); int exit = 0; Assert.That(context.TryGet <int>(out exit)); }
public void TypedInterfaceGetTest() { var context = TestsFactory.BindingContext(); var bind = context.Bind <ITestInterface> (); bind.To(() => new TestClass()); Assert.DoesNotThrow(() => TypedGet <ITestInterface>(context)); }
public void BindingSimpleInt() { IBindingContext context = TestsFactory.BindingContext(); int expected = 45; context.Bind <int>().To(() => expected); Assert.AreEqual(context.Get <int>(), expected); }
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>()); }
public void TryGetFoundRightValueTest() { var context = TestsFactory.BindingContext(); context.Bind <int>().To(() => 93); int exit = 0; context.TryGet <int>(out exit); Assert.AreEqual(93, exit); }
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); }
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)); }
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); }
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); }
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])); }
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); }
public void BindingContextFallsBackToFallback() { var context = TestsFactory.BindingContext(); context.FallBack((name, key, extras) => { return(3); }); var result = context.Get <int>(); Assert.AreEqual(result, 3); }
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); }
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"); }
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"); }
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"); }
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"); }
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); }
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"); }
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); }
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"); }
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"); }