예제 #1
0
        public void find_instance_negative_when_family_does_not_exist_does_not_create_family()
        {
            var graph = PluginGraph.CreateRoot();

            graph.FindInstance(typeof(BigThingy), "blue").ShouldBeNull();
            graph.Families.Has(typeof(BigThingy)).ShouldBeFalse();
        }
예제 #2
0
        public static IPipelineGraph BuildEmpty()
        {
            var pluginGraph = PluginGraph.CreateRoot();

            return(new PipelineGraph(pluginGraph, new RootInstanceGraph(pluginGraph), null, pluginGraph.SingletonCache,
                                     new NulloTransientCache()));
        }
예제 #3
0
        public void if_a_dependency_value_is_IDependencySource_just_use_that()
        {
            var source = Substitute.For <IDependencySource>();

            ConcreteType.SourceFor(new Policies(PluginGraph.CreateRoot()), ConcreteType.ConstructorArgument, "SomeArg", typeof(IGateway), source)
            .ShouldBeTheSameAs(source);
        }
예제 #4
0
        public void SetUp()
        {
            family = new PluginFamily(typeof(IService <>));
            PluginGraph.CreateRoot("something").AddFamily(family);

            configuration = new GenericFamilyConfiguration(family, PipelineGraph.BuildEmpty());
        }
예제 #5
0
        public void use_all_possible_for_list()
        {
            var enumerableType = typeof(List <IGateway>);

            ConcreteType.SourceFor(new Policies(PluginGraph.CreateRoot()), ConcreteType.ConstructorArgument, "SomeProp", enumerableType, null)
            .ShouldBe(new AllPossibleValuesDependencySource(enumerableType));
        }
예제 #6
0
        public void has_instance_negative_when_the_family_has_not_been_created()
        {
            var graph = PluginGraph.CreateRoot();

            graph.HasInstance(typeof(IThingy), "red")
            .ShouldBeFalse();
        }
예제 #7
0
        public void has_default_positive()
        {
            var graph = PluginGraph.CreateRoot();

            graph.Families[typeof(IThingy)].SetDefault(new SmartInstance <BigThingy>());

            graph.HasDefaultForPluginType(typeof(IThingy));
        }
예제 #8
0
        public void find_instance_negative_when_family_does_exist_but_instance_does_not()
        {
            var graph = PluginGraph.CreateRoot();

            graph.Families[typeof(BigThingy)].AddInstance(new SmartInstance <BigThingy>().Named("red"));

            graph.FindInstance(typeof(BigThingy), "blue").ShouldBeNull();
        }
        public void transient_cache_by_default_is_a_nullo()
        {
            var plugins = PluginGraph.CreateRoot();

            var pipeline = PipelineGraph.BuildRoot(plugins);

            pipeline.Transients.ShouldBeOfType <NulloTransientCache>();
        }
        public void transient_cache_of_nested_pipeline_graph_is_a_stateful_cache()
        {
            var plugins = PluginGraph.CreateRoot();

            var pipeline = PipelineGraph.BuildRoot(plugins);

            pipeline.ToNestedGraph().Transients.ShouldBeOfType <ContainerSpecificObjectCache>();
        }
예제 #11
0
        public void should_get_the_greediest_constructor_if_there_is_more_than_one()
        {
            var selector    = new ConstructorSelector(PluginGraph.CreateRoot());
            var constructor = selector.Select(typeof(GreaterThanRule), new DependencyCollection());

            constructor.GetParameters().Select(x => x.ParameterType)
            .ShouldHaveTheSameElementsAs(typeof(IWidget), typeof(Rule));
        }
예제 #12
0
        public void all_instances_when_family_has_not_been_created()
        {
            var graph = PluginGraph.CreateRoot();

            graph.AllInstances(typeof(BigThingy)).Any().ShouldBeFalse();

            graph.Families.Has(typeof(BigThingy)).ShouldBeFalse();
        }
예제 #13
0
        public void build_root_for_tracked_transients()
        {
            var pluginGraph = PluginGraph.CreateRoot();

            pluginGraph.TransientTracking = TransientTracking.ExplicitReleaseMode;
            var graph = PipelineGraph.BuildRoot(pluginGraph);

            graph.Transients.ShouldBeOfType <TrackingTransientCache>();
        }
예제 #14
0
        public void find_instance_positive()
        {
            var graph    = PluginGraph.CreateRoot();
            var instance = new SmartInstance <BigThingy>().Named("red");

            graph.Families[typeof(BigThingy)].AddInstance(instance);

            graph.FindInstance(typeof(BigThingy), "red").ShouldBeTheSameAs(instance);
        }
예제 #15
0
        public void default_lifecycle_not_set_on_any_level()
        {
            var graph = PluginGraph.CreateRoot();

            var pipeline = PipelineGraph.BuildRoot(graph).Profiles.For("Red");

            pipeline.Instances.DefaultLifecycleFor(typeof(IGateway))
            .ShouldBeNull();
        }
예제 #16
0
        public void value_is_instance_for_non_simple_resolves_to_lifecycle_source()
        {
            var instance = new FakeInstance();

            instance.SetLifecycleTo(new SingletonLifecycle());

            ConcreteType.SourceFor(new Policies(PluginGraph.CreateRoot()), ConcreteType.ConstructorArgument, "SomeProp", typeof(IGateway), instance)
            .ShouldBeTheSameAs(instance.DependencySource);
        }
예제 #17
0
        public void build_root_for_default_tracking_style()
        {
            var pluginGraph = PluginGraph.CreateRoot();

            pluginGraph.TransientTracking = TransientTracking.DefaultNotTrackedAtRoot;
            var graph = PipelineGraph.BuildRoot(pluginGraph);

            graph.Transients.ShouldBeOfType <NulloTransientCache>();
        }
예제 #18
0
        public void all_instances_when_the_family_already_exists()
        {
            var graph = PluginGraph.CreateRoot();

            // just forcing the family to be created
            graph.Families[typeof(BigThingy)].ShouldNotBeNull();

            graph.AllInstances(typeof(BigThingy)).Any().ShouldBeFalse();
        }
예제 #19
0
        public void get_the_first_constructor_marked_with_the_attribute_if_it_exists()
        {
            var selector = new ConstructorSelector(PluginGraph.CreateRoot());

            var constructor = selector.Select(typeof(ComplexRule), new DependencyCollection());

            constructor.GetParameters().Length
            .ShouldBe(7);
        }
예제 #20
0
        public void custom_selectors_have_precedence()
        {
            var selector = new ConstructorSelector(PluginGraph.CreateRoot());

            selector.Add(new PickTheFirstOne());

            selector.Select(typeof(ClassWithMultipleConstructors), new DependencyCollection())
            .GetParameters().Select(x => x.ParameterType)
            .ShouldHaveTheSameElementsAs(typeof(IGateway));
        }
예제 #21
0
        public void source_for_missing_string_setter_arg()
        {
            var source = ConcreteType.SourceFor(new Policies(PluginGraph.CreateRoot()), ConcreteType.SetterProperty, "SomeProp", typeof(string), null)
                         .ShouldBeOfType <DependencyProblem>();

            source.Name.ShouldBe("SomeProp");
            source.Type.ShouldBe(ConcreteType.SetterProperty);
            source.Message.ShouldBe("Required primitive dependency is not explicitly defined");
            source.ReturnedType.ShouldBe(typeof(string));
        }
        public void singleton_is_just_the_plugin_graph_singletons()
        {
            var plugins = PluginGraph.CreateRoot();

            plugins.SingletonCache.ShouldNotBeNull();

            var pipeline = PipelineGraph.BuildRoot(plugins);

            pipeline.Singletons.ShouldBeTheSameAs(plugins.SingletonCache);
        }
        public void default_lifecycle_is_explicitly_set()
        {
            var graph = PluginGraph.CreateRoot();

            graph.Families[typeof(IGateway)].SetLifecycleTo <SingletonLifecycle>();

            var root = new RootInstanceGraph(graph);

            root.DefaultLifecycleFor(typeof(IGateway)).ShouldBeOfType <SingletonLifecycle>();
        }
        public void default_lifecycle_is_null_if_family_has_no_lifecycle()
        {
            var graph = PluginGraph.CreateRoot();

            graph.Families[typeof(IGateway)].SetDefault(new SmartInstance <StubbedGateway>());

            var root = new RootInstanceGraph(graph);

            root.DefaultLifecycleFor(typeof(IGateway)).ShouldBeNull();
        }
예제 #25
0
        public void has_default_with_family_but_no_default()
        {
            var graph = PluginGraph.CreateRoot();

            graph.Families[typeof(IThingy)].AddInstance(new SmartInstance <BigThingy>());
            graph.Families[typeof(IThingy)].AddInstance(new SmartInstance <BigThingy>());

            graph.HasDefaultForPluginType(typeof(IThingy))
            .ShouldBeFalse();
        }
예제 #26
0
        public void has_instance_negative_with_the_family_already_existing()
        {
            var graph = PluginGraph.CreateRoot();

            graph.Families[typeof(IThingy)]
            .AddInstance(new SmartInstance <BigThingy>().Named("blue"));

            graph.HasInstance(typeof(IThingy), "red")
            .ShouldBeFalse();
        }
예제 #27
0
        public void find_root()
        {
            var top  = PluginGraph.CreateRoot();
            var node = top.Profile("Foo");
            var leaf = node.Profile("Bar");

            top.Root.ShouldBeTheSameAs(top);
            node.Root.ShouldBeTheSameAs(top);
            leaf.Root.ShouldBeTheSameAs(top);
        }
예제 #28
0
        public void has_instance_positive()
        {
            var graph = PluginGraph.CreateRoot();

            graph.Families[typeof(IThingy)]
            .AddInstance(new SmartInstance <BigThingy>().Named("blue"));

            graph.HasInstance(typeof(IThingy), "blue")
            .ShouldBeTrue();
        }
예제 #29
0
        public void returns_missing_instance_if_it_exists_and_the_requested_instance_is_not_found()
        {
            var graph   = PluginGraph.CreateRoot();
            var family  = graph.Families[typeof(IWidget)];
            var missing = new ObjectInstance(new AWidget());

            family.MissingInstance = missing;

            graph.FindInstance(typeof(IWidget), "anything").ShouldNotBeNull();
            graph.FindInstance(typeof(IWidget), Guid.NewGuid().ToString()).ShouldNotBeNull();
        }
예제 #30
0
        public void lifecyle_for_pluginType_not_explicitly_set_falls_back_to_parent()
        {
            var graph = PluginGraph.CreateRoot();

            graph.Families[typeof(IGateway)].SetLifecycleTo <SingletonLifecycle>();

            var pipeline = PipelineGraph.BuildRoot(graph).Profiles.For("Red");

            pipeline.Instances.DefaultLifecycleFor(typeof(IGateway))
            .ShouldBeOfType <SingletonLifecycle>();
        }