Example #1
0
        public void Should_return_instances_that_apply_to_instance_context(
            [Values(true, false)] bool orDefault)
        {
            var plugin1 = new ContextConditionalPlugin3 {
                DoesApplyTo = x => x.Value == 2
            };
            var plugin2 = new ContextConditionalPlugin2 {
                DoesApplyTo = x => x.Value == 1
            };
            var plugin3 = new ContextConditionalPlugin3 {
                DoesApplyTo = x => x.Value == 1
            };

            var instances = new IContextConditionalPluginType[] { plugin1, plugin3, plugin2 };

            var plugins = new Plugins <IContextConditionalPluginType>(false)
                          .Configure(x => x
                                     .Append <ContextConditionalPlugin1>()
                                     .Append <ContextConditionalPlugin2>()
                                     .Append <ContextConditionalPlugin3>());

            var context = new InstanceContext {
                Value = 1
            };
            var apply = (orDefault
                ? plugins.ThatApplyToOrDefault(instances, context)
                : plugins.ThatApplyTo(instances, context)).ToList();

            apply.ShouldOnlyContain(plugin2, plugin3);
        }
Example #2
0
        public void Should_return_list_only_containing_last_default_if_no_instances_appy_to_plugin_and_instance_context_and_a_default_is_specified()
        {
            var plugin1 = new ContextConditionalPlugin1 {
                DoesApplyTo = c => false
            };
            var plugin2 = new ContextConditionalPlugin2 {
                DoesApplyTo = c => false
            };
            var plugin3 = new ContextConditionalPlugin3 {
                DoesApplyTo = c => false
            };

            var instances = new IContextConditionalPluginType[] { plugin1, plugin2, plugin3 };

            var plugins = new ConditionalPlugins <IContextConditionalPluginType, PluginContext>(false)
                          .Configure(x => x
                                     .Append <ContextConditionalPlugin1>()
                                     .Append <ContextConditionalPlugin2>(@default: true)
                                     .Append <ContextConditionalPlugin3>(@default: true));

            var applies = plugins.ThatAppliesToOrDefault(instances,
                                                         new PluginContext(), new InstanceContext());

            applies.ShouldOnlyContain(plugin3);
        }
Example #3
0
        public void Should_return_instances_that_apply_to_plugin_and_instance_context_when_they_exist_and_not_the_default()
        {
            var plugin1 = new ContextConditionalPlugin1 {
                DoesApplyTo = c => c.Value == 2
            };
            var plugin2 = new ContextConditionalPlugin2 {
                DoesApplyTo = c => c.Value == 1
            };
            var plugin3 = new ContextConditionalPlugin3 {
                DoesApplyTo = c => c.Value == 1
            };

            var instances = new IContextConditionalPluginType[] { plugin1, plugin3, plugin2 };

            var plugins = new ConditionalPlugins <IContextConditionalPluginType, PluginContext>(false)
                          .Configure(x => x
                                     .Append <ContextConditionalPlugin1>(@default: true)
                                     .Append <ContextConditionalPlugin2>(c => c.Value == 1)
                                     .Append <ContextConditionalPlugin3>(c => c.Value == 1));

            var applies = plugins.ThatAppliesToOrDefault(instances,
                                                         new PluginContext {
                Value = 1
            },
                                                         new InstanceContext {
                Value = 1
            });

            applies.ShouldOnlyContain(plugin2, plugin3);
        }
Example #4
0
        public void Should_return_instances_that_apply_to_plugin_and_instance_context()
        {
            var plugin1 = new ContextConditionalPlugin1 {
                DoesApplyTo = c => c.Value == 1
            };
            var plugin2 = new ContextConditionalPlugin2 {
                DoesApplyTo = c => c.Value == 2
            };
            var plugin3 = new ContextConditionalPlugin3 {
                DoesApplyTo = c => c.Value == 2
            };

            var instances = new IContextConditionalPluginType[] { plugin1, plugin3, plugin2 };

            var plugins = new ConditionalPlugins <IContextConditionalPluginType, PluginContext>(false)
                          .Configure(x => x
                                     .Append <ContextConditionalPlugin1>()
                                     .Append <ContextConditionalPlugin2>()
                                     .Append <ContextConditionalPlugin3>(c => c.Value == 1));

            var apply = plugins.ThatAppliesTo(instances,
                                              new PluginContext {
                Value = 1
            },
                                              new InstanceContext {
                Value = 2
            }).ToList();

            apply.ShouldOnlyContain(plugin2, plugin3);
        }
Example #5
0
        public void Should_return_first_instance_that_applies_to_instance_context()
        {
            var plugin1 = new ContextConditionalPlugin3 {
                DoesApplyTo = x => x.Value == 2
            };
            var plugin2 = new ContextConditionalPlugin2 {
                DoesApplyTo = x => x.Value == 1
            };
            var plugin3 = new ContextConditionalPlugin3 {
                DoesApplyTo = x => x.Value == 1
            };

            var instances = new IContextConditionalPluginType[] { plugin1, plugin3, plugin2 };

            var plugins = new Plugins <IContextConditionalPluginType>(false)
                          .Configure(x => x
                                     .Append <ContextConditionalPlugin1>()
                                     .Append <ContextConditionalPlugin2>()
                                     .Append <ContextConditionalPlugin3>());

            var context = new InstanceContext {
                Value = 1
            };
            var apply = plugins.ThatAppliesToOrDefault(instances, context);

            apply.ShouldEqual(plugin2);
        }
Example #6
0
        public void Should_return_default_instances_if_none_apply_to_instance_context()
        {
            var plugin1 = new ContextConditionalPlugin3 {
                DoesApplyTo = x => x.Value == 2
            };
            var plugin2 = new ContextConditionalPlugin2 {
                DoesApplyTo = x => x.Value == 2
            };

            var instances = new IContextConditionalPluginType[] { plugin1, plugin2 };

            var plugins = new Plugins <IContextConditionalPluginType>(false)
                          .Configure(x => x
                                     .Append <ContextConditionalPlugin1>()
                                     .Append <ContextConditionalPlugin2>(@default: true));

            var context = new InstanceContext {
                Value = 1
            };
            var apply = plugins.ThatApplyToOrDefault(instances, context).ToList();

            apply.ShouldOnlyContain(plugin2);
        }