public void Test_Resolve_Implementation_Handles_Non_Lazy_Bindings_Correctly() { IBinding <ISample> binding = new ConstructorBinding <ISample>(() => new Sample()); LazyConstructorBinding <IHasSample> lazyBinding = new LazyConstructorBinding <IHasSample>( new IBinding[0], bindings => new HasSample(binding.Resolve())); IHasSample sample = lazyBinding.Resolve(); Assert.IsType <HasSample>(sample); Assert.IsType <ConstructorBinding <IHasSample> >(lazyBinding.Constructor); }
public void Test_Resolve_Implementation_Flattens_Multiple_Lazy_Bindings() { LazyConstructorBinding <IHasSample> lazyBinding = new LazyConstructorBinding <IHasSample>(new IBinding[] { new LazyConstructorBinding <ISample>(new IBinding[0], bindings => new Sample()) }, bindings => new HasSample(((LazyConstructorBinding <ISample>)bindings[0]).Resolve())); IHasSample sample = lazyBinding.Resolve(); Assert.IsType <HasSample>(sample); Assert.IsType <ConstructorBinding <IHasSample> >(lazyBinding.Constructor); }
public void Test_Binding_With_Dependencies_Using_Extension_Method_Can_Be_Resolved() { IBinding <ISample> sampleBinding = from value in Bind <ISample>() select new Sample(); IBinding <IHasSample> hasSampleBinding = from value in Bind <IHasSample>() select new HasSample(sampleBinding.AsDependency()); IHasSample hasSample = hasSampleBinding.Resolve(); Assert.NotNull(hasSample); Assert.IsType <HasSample>(hasSample); Assert.NotNull(hasSample.Sample); Assert.IsType <Sample>(hasSample.Sample); }
public void Test_MethodCall_With_Dependencies_And_NonDependant_Methods_Can_Be_Resolved() { IBinding <ISample> sampleBinding = Bind <ISample>().Select(value => new Sample()); Func <ISample, int, HasSample> providerFunc = (sample, i) => new HasSample(sample); IBinding <IHasSample> binding = from value in Bind <IHasSample>() select providerFunc(Dependency(sampleBinding), Math.Abs(-9)); IHasSample hasSample = binding.Resolve(); Assert.NotNull(hasSample); Assert.IsType <HasSample>(hasSample); Assert.NotNull(hasSample.Sample); Assert.IsType <Sample>(hasSample.Sample); }