Exemplo n.º 1
0
        public void close_an_open_type()
        {
            var argument = new Argument
            {
                Type = typeof(IService<>),
                Dependency = new ConfiguredInstance(typeof(Service<>)),
                Name = "foo"
            };

            var closed = argument.CloseType(typeof(int));

            closed.Type.ShouldBe(typeof(IService<int>));
            closed.Dependency.ShouldBeOfType<ConstructorInstance>()
                .PluggedType.ShouldBe(typeof(Service<int>));
            closed.Name.ShouldBe("foo");
        }
Exemplo n.º 2
0
        public void close_an_already_closed_type_just_clones_2()
        {
            var argument = new Argument
            {
                Type = typeof(IGateway),
                Dependency = new ConstructorInstance(typeof(StubbedGateway)),
                Name = "Foo"
            };

            var closed = argument.CloseType(typeof(int));
            closed.ShouldNotBeTheSameAs(argument);

            closed.Type.ShouldBe(argument.Type);
            closed.Dependency.ShouldBe(argument.Dependency);
            closed.Name.ShouldBe(argument.Name);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a "closed" Argument for open generic dependency types
        /// </summary>
        /// <param name="types"></param>
        /// <returns></returns>
        public Argument CloseType(params Type[] types)
        {
            var clone = new Argument
            {
                Name = Name
            };

            if (Type != null)
            {
                clone.Type = Type.IsOpenGeneric() ? Type.MakeGenericType(types) : Type;
            }

            if (Dependency is Instance)
            {
                clone.Dependency = Dependency.As<Instance>().CloseType(types) ?? Dependency;
            }
            else
            {
                clone.Dependency = Dependency;
            }

            return clone;
        }