public void Should_return_plugin_instances_that_apply_to_context() { var plugin1a = new Plugin1a(); var plugin1b = new Plugin1b(); var plugin2 = new Plugin2(); var plugin3 = new Plugin3(); var plugin4 = new Plugin4(); var instances = new IPluginType[] { plugin1a, plugin1b, plugin2, plugin3, plugin4 }; var plugins = new ConditionalPlugins <IPluginType, Context>(false) .Configure(x => x .Append <Plugin1a>(c => c.Value == 1) .Append <Plugin1b>(c => c.Value == 1) .Append <Plugin2>(c => c.Value == 2) .Append <Plugin3>()); var apply = plugins.ThatApplyTo(instances, new Context { Value = 1 }).ToList(); apply.Count.ShouldEqual(3); apply[0].Instance.ShouldEqual(plugin1a); apply[1].Instance.ShouldEqual(plugin1b); apply[2].Instance.ShouldEqual(plugin3); apply = plugins.ThatApplyTo(instances, new Context { Value = 2 }).ToList(); apply.Count.ShouldEqual(2); apply[0].Instance.ShouldEqual(plugin2); apply[1].Instance.ShouldEqual(plugin3); }
public void Should_get_the_default_instance() { var plugin1 = new Plugin1(); var plugin2 = new Plugin2(); var plugin3 = new Plugin3(); var plugin4 = new Plugin4(); var instances = new IPluginType[] { plugin1, plugin2, plugin3, plugin4 }; var plugins = new ConditionalPlugins <IPluginType, Context>(false) .Configure(x => x .Append <Plugin1>() .Append <Plugin2>(@default: true) .Append <Plugin3>(@default: true) .Append <Plugin4>()); plugins.GetDefaultInstance(instances).ShouldEqual(plugin3); }
public void Should_replace_all_instance_plugins_of_the_specified_instance_or_prepend( [Values(true, false)] bool @default) { var keep1 = Plugin <IPluginType> .Create(new Plugin2()); var keep2 = Plugin <IPluginType> .Create <Plugin1>(); var keep3 = Plugin <IPluginType> .Create(new Plugin1()); var instance = new Plugin4(); var replaceWith = Plugin <IPluginType> .Create(new Plugin3()); _plugins.Append(keep1); _plugins.Append(keep2); _plugins.Append(Plugin <IPluginType> .Create(instance)); _plugins.Append(keep3); _plugins.ReplaceInstancePluginWithPrepend(instance, replaceWith, @default) .ShouldOnlyContain(keep1, keep2, replaceWith, keep3); _plugins.IsDefault(replaceWith).ShouldEqual(@default); }