public void Run(ConstructorTargetTests host) { host.Output.WriteLine("Running Upfront Binding Test \"{0}\"", Description ?? "Unknown binding test"); host.Output.WriteLine(ToString()); //we check that each parameter is bound; and that the bindings are the same as the ones //we were given or added dynamically if not supplied var parameterBindings = SuppliedBindingsFactory(Constructor) ?? new ParameterBinding[0]; ConstructorTarget target = new ConstructorTarget(Constructor, parameterBindings: parameterBindings); var compileContext = host.GetCompileContext(target); var binding = target.Bind(compileContext); ParameterBinding[] expectedBoundParameters = null; var allDefaultBoundParameters = Constructor.GetParameters() .Select(p => new ParameterBinding(p, new TestTarget(p.ParameterType, useFallBack: true))).ToArray(); if (parameterBindings.Length != Constructor.GetParameters().Length) { //join those bindings which match; generate 'fake' ones for those which don't expectedBoundParameters = allDefaultBoundParameters.Select(b => parameterBindings.SingleOrDefault(pb => pb.Parameter == b.Parameter) ?? b).ToArray(); } else { expectedBoundParameters = allDefaultBoundParameters; } Assert.NotNull(binding); Assert.Collection(binding.BoundArguments, expectedBoundParameters.Select(bb => new Action <ParameterBinding>(b => { Assert.Same(bb.Parameter, b.Parameter); //non fallback TestTarget means 'should be bound to this one' //expected fallback TestTarget means 'must be non-null' if (!(bb.Target is TestTarget) || !bb.Target.UseFallback) { Assert.Same(b.Target, bb.Target); } else { Assert.NotNull(bb.Target); } })).ToArray()); }
public void RunBindingTest(ConstructorTargetTests host) { host.Output.WriteLine("Running JIT Binding Test \"{0}\".", Description ?? "Unknown Bindings Test"); host.Output.WriteLine(ToString()); var namedArgs = NamedArgsFactory(); var target = new ConstructorTarget(Type, namedArgs: namedArgs); var compileContext = host.GetCompileContext(target, ContainerFactory()); var binding = target.Bind(compileContext); Xunit.Assert.NotNull(binding); Xunit.Assert.Same(ExpectedConstructor, binding.Constructor); if (namedArgs != null && namedArgs.Count != 0) { Assert.All(namedArgs, kvp => { var boundArg = binding.BoundArguments.SingleOrDefault(p => p.Parameter.Name == kvp.Key); Assert.NotNull(boundArg); Assert.Same(kvp.Value, boundArg.Target); }); } // host.Output.WriteLine("Test Complete"); }