Ejemplo n.º 1
0
        public void decorate_closed_type_no_filter_does_not_match_on_plugin_type()
        {
            var policy = new DecoratorPolicy(typeof(IWidget), typeof(WidgetDecorator));

            policy.DetermineInterceptors(typeof(AWidget), new SmartInstance <AWidget>())
            .Any().ShouldBeFalse();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Applies a decorator type to all Instances that return a type that can be cast to this PluginType
        /// </summary>
        /// <param name="decoratorType"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public ConfiguredInstance DecorateAllWith(Type decoratorType, Func <Instance, bool> filter = null)
        {
            var instance = new ConfiguredInstance(decoratorType);
            var policy   = new DecoratorPolicy(_pluginType, instance, filter);

            _registry.alter = graph => graph.Policies.Interceptors.Add(policy);

            return(instance);
        }
Ejemplo n.º 3
0
        public void wrap_negative()
        {
            var policy = new DecoratorPolicy <ISomething, WrappedThing>();

            var instance = new ObjectInstance(GetType(), this);

            policy.TryWrap(instance, out var wrapped).ShouldBeFalse();

            wrapped.ShouldBeNull();
        }
Ejemplo n.º 4
0
        public void open_generics_happy_path()
        {
            var policy = new DecoratorPolicy(typeof(IFoo <,>), typeof(DecoratedFoo <,>));

            policy.DetermineInterceptors(typeof(IFoo <string, int>), new SmartInstance <Foo <string, int> >())
            .Single()
            .ShouldBeOfType <DecoratorInterceptor>()
            .Instance.PluggedType
            .ShouldBe(typeof(DecoratedFoo <string, int>));
        }
Ejemplo n.º 5
0
        public void decorate_closed_type_uses_filter()
        {
            var policy = new DecoratorPolicy(typeof(IWidget), typeof(WidgetDecorator), i => i.Name == "ok");

            policy.DetermineInterceptors(typeof(IWidget), new SmartInstance <AWidget>().Named("not right"))
            .Any().ShouldBeFalse();

            policy.DetermineInterceptors(typeof(IWidget), new SmartInstance <AWidget>().Named("ok"))
            .Any().ShouldBeTrue();
        }
Ejemplo n.º 6
0
        public void decorate_closed_type_no_filter_matches_on_plugin_type()
        {
            var policy = new DecoratorPolicy(typeof(IWidget), typeof(WidgetDecorator));

            policy.DetermineInterceptors(typeof(IWidget), new SmartInstance <AWidget>())
            .Single()
            .ShouldBeOfType <DecoratorInterceptor>()
            .Instance
            .PluggedType
            .ShouldBe(typeof(WidgetDecorator));
        }
Ejemplo n.º 7
0
        public void wrap_positive()
        {
            var policy = new DecoratorPolicy <ISomething, WrappedThing>();

            var instance = new ConstructorInstance(typeof(ISomething), typeof(InnerThing), ServiceLifetime.Transient);

            policy.TryWrap(instance, out var wrapped).ShouldBeTrue();
            var configured = wrapped.ShouldBeOfType <ConstructorInstance>();

            configured.ServiceType.ShouldBe(typeof(ISomething));
            configured.ImplementationType.ShouldBe(typeof(WrappedThing));


            configured.InlineDependencies.Single().ShouldBeSameAs(instance);
        }