public void find_concrete_type_for_a_type_that_is_marked_with_default_constructor()
        {
            var pluginGraph = new PluginGraph();
            var objectGraph = new ObjectGraph(typeof (ClassMarkedWithDefaultConstructor));

            pluginGraph.InitializeConcreteType(objectGraph);

            // Should choose the no arg constructor
            objectGraph.ConcreteType.Constructor.GetParameters().Any().ShouldBeFalse();
        }
        public ObjectGraphBuilder(ObjectGraph graph, PluginGraph pluginGraph)
        {
            _graph = graph;

            _builder = new Lazy<IInstanceBuilder>(() =>
            {
                graph.InitializeConcreteType(pluginGraph);

                // Move this to pluginGraph.  IBuilderCompiler may need to be pluggable later
                return BuilderCompiler.CreateBuilder(graph.ConcreteType);
            });
        }
        public void use_the_constructor_selector_to_build_a_concrete_type()
        {
            var theCtor = GetType().GetConstructors().First();
            var selector = MockRepository.GenerateMock<IConstructorSelector>();
            var pluginGraph = new PluginGraph{
                ConstructorSelector = selector
            };

            var objectGraph = new ObjectGraph(GetType());

            selector.Stub(x => x.Select(objectGraph, pluginGraph)).Return(theCtor);

            pluginGraph.InitializeConcreteType(objectGraph);

            objectGraph.ConcreteType.Constructor.ShouldBeTheSameAs(theCtor);
        }
        public void build_the_object()
        {
            var objectGraph = new ObjectGraph<ClassWithMultipleCtorArguments>();
            objectGraph.ByType[typeof (Color)] = "Red";
            objectGraph.ByName["name"] = "Jeremy";
            objectGraph.ByType[typeof (int)] = "36";
            objectGraph.ByName["day"] = DateTime.Today;

            var pipeline = new PipelineContext();

            var pluginGraph = new PluginGraph();

            var builder = new ObjectGraphBuilder(objectGraph, pluginGraph);
            var pluginType = pluginGraph.PluginTypeFor(typeof (ClassWithMultipleCtorArguments));
            var target = builder.Build(pluginType, pipeline).ShouldBeOfType<ClassWithMultipleCtorArguments>();

            target.Color.ShouldEqual(Color.Red);
            target.Name.ShouldEqual("Jeremy");
            target.Age.ShouldEqual(36);
            target.Day.ShouldEqual(DateTime.Today);
        }
 public ConstructorInfo Select(IObjectGraph objectGraph, PluginGraph pluginGraph)
 {
     return
         objectGraph.ConcreteType.Type.GetConstructors().OrderByDescending(x => x.GetParameters().Count()).
             FirstOrDefault();
 }