Exemplo n.º 1
0
        public void SelectConstructorWith2Parameters()
        {
            ConstructorInfo ctor = typeof(ClassWithConstructorParameters).GetMatchingConstructor(Types(typeof(int), typeof(string)));

            var policy = new SpecifiedConstructorSelectorPolicy(ctor,
                                                                new InjectionParameterValue[]
            {
                new InjectionParameter <int>(37),
                new InjectionParameter <string>("abc")
            });

            var builderContext = new BuilderContextMock(new NamedTypeBuildKey(typeof(ClassWithConstructorParameters)));

            SelectedConstructor selectedCtor = policy.SelectConstructor(builderContext, builderContext.PersistentPolicies);

            Assert.Equal(ctor, selectedCtor.Constructor);
            Assert.Equal(2, selectedCtor.GetParameterResolvers().Length);

            var resolvers = selectedCtor.GetParameterResolvers();

            Assert.Equal(2, resolvers.Length);
            foreach (var resolverPolicy in resolvers)
            {
                AssertPolicyIsCorrect(resolverPolicy);
            }
        }
        public void SelectConstructorWith2Parameters()
        {
            ConstructorInfo ctor = typeof(ClassWithConstructorParameters).GetMatchingConstructor(Types(typeof(int), typeof(string)));

            var policy = new SpecifiedConstructorSelectorPolicy(ctor,
                new InjectionParameterValue[]
                {
                    new InjectionParameter<int>(37),
                    new InjectionParameter<string>("abc")
                });

            var builderContext = new BuilderContextMock(new NamedTypeBuildKey(typeof(ClassWithConstructorParameters)));

            SelectedConstructor selectedCtor = policy.SelectConstructor(builderContext, builderContext.PersistentPolicies);

            Assert.Equal(ctor, selectedCtor.Constructor);
            Assert.Equal(2, selectedCtor.GetParameterResolvers().Length);

            var resolvers = selectedCtor.GetParameterResolvers();
            Assert.Equal(2, resolvers.Length);
            foreach (var resolverPolicy in resolvers)
            {
                AssertPolicyIsCorrect(resolverPolicy);
            }
        }
Exemplo n.º 3
0
        public void SelectConstructorWith2Parameters()
        {
            ConstructorInfo ctor = typeof(ClassWithConstructorParameters).GetConstructor(Types(typeof(int), typeof(string)));

            SpecifiedConstructorSelectorPolicy policy = new SpecifiedConstructorSelectorPolicy(ctor,
                                                                                               new InjectionParameterValue[]
            {
                new InjectionParameter <int>(37),
                new InjectionParameter <string>("abc")
            });

            BuilderContextMock builderContext = new BuilderContextMock(typeof(ClassWithConstructorParameters));

            SelectedConstructor selectedCtor = policy.SelectConstructor(builderContext);

            Assert.AreEqual(ctor, selectedCtor.Constructor);
            Assert.AreEqual(2, selectedCtor.GetParameterKeys().Length);

            string[] keys = selectedCtor.GetParameterKeys();
            Assert.AreEqual(2, keys.Length);
            foreach (string key in keys)
            {
                AssertPolicyIsCorrect(key, builderContext);
            }
        }
Exemplo n.º 4
0
        public void SelectConstructorWithNoParameters()
        {
            ConstructorInfo ctor = typeof(ClassWithSimpleConstructor).GetMatchingConstructor(new Type[0]);

            var policy         = new SpecifiedConstructorSelectorPolicy(ctor, new InjectionParameterValue[0]);
            var builderContext = new BuilderContextMock(new NamedTypeBuildKey(typeof(ClassWithSimpleConstructor)));

            SelectedConstructor selectedCtor = policy.SelectConstructor(builderContext, new PolicyList());

            Assert.Equal(ctor, selectedCtor.Constructor);
            Assert.Equal(0, selectedCtor.GetParameterResolvers().Length);
        }
Exemplo n.º 5
0
        public void SelectConstructorWithNoParameters()
        {
            ConstructorInfo ctor = typeof(ClassWithSimpleConstructor).GetConstructor(new Type[0]);

            SpecifiedConstructorSelectorPolicy policy = new SpecifiedConstructorSelectorPolicy(ctor, new InjectionParameterValue[0]);
            BuilderContextMock builderContext         = new BuilderContextMock(typeof(ClassWithSimpleConstructor));

            SelectedConstructor selectedCtor = policy.SelectConstructor(builderContext);

            Assert.AreEqual(ctor, selectedCtor.Constructor);
            Assert.AreEqual(0, selectedCtor.GetParameterKeys().Length);
        }
        public void SelectConstructorWithNoParameters()
        {
            ConstructorInfo ctor = typeof(ClassWithSimpleConstructor).GetConstructor(new Type[0]);

            var policy = new SpecifiedConstructorSelectorPolicy(ctor, new InjectionParameterValue[0]);
            var builderContext = new BuilderContextMock(new NamedTypeBuildKey(typeof(ClassWithSimpleConstructor)));

            SelectedConstructor selectedCtor = policy.SelectConstructor(builderContext, new PolicyList());

            Assert.AreEqual(ctor, selectedCtor.Constructor);
            Assert.AreEqual(0, selectedCtor.GetParameterKeys().Length);

        }
        public void CanSelectConcreteConstructorGivenGenericConstructor()
        {
            ConstructorInfo ctor = typeof(LoggingCommand<>).GetTypeInfo().DeclaredConstructors.ElementAt(0);
            var policy = new SpecifiedConstructorSelectorPolicy(
                ctor,
                new InjectionParameterValue[]
                {
                    new ResolvedParameter(typeof(ICommand<>), "concrete")
                });

            var ctx = new BuilderContextMock
                {
                    BuildKey = new NamedTypeBuildKey(typeof(LoggingCommand<User>))
                };

            SelectedConstructor result = policy.SelectConstructor(ctx, new PolicyList());

            ConstructorInfo expectedCtor = typeof(LoggingCommand<User>).GetMatchingConstructor(Types(typeof(ICommand<User>)));
            Assert.Same(expectedCtor, result.Constructor);
        }
Exemplo n.º 8
0
        public void CanSelectConcreteConstructorGivenGenericConstructor()
        {
            ConstructorInfo ctor = typeof(LoggingCommand <>).GetConstructors()[0];
            SpecifiedConstructorSelectorPolicy policy = new SpecifiedConstructorSelectorPolicy(
                ctor,
                new InjectionParameterValue[]
            {
                new ResolvedParameter(typeof(ICommand <>), "concrete")
            });

            BuilderContextMock ctx = new BuilderContextMock();

            ctx.BuildKey = typeof(LoggingCommand <User>);

            SelectedConstructor result = policy.SelectConstructor(ctx);

            ConstructorInfo expectedCtor = typeof(LoggingCommand <User>).GetConstructor(Types(typeof(ICommand <User>)));

            Assert.AreSame(expectedCtor, result.Constructor);
        }
Exemplo n.º 9
0
        public void CanSelectConcreteConstructorGivenGenericConstructor()
        {
            ConstructorInfo ctor   = typeof(LoggingCommand <>).GetTypeInfo().DeclaredConstructors.ElementAt(0);
            var             policy = new SpecifiedConstructorSelectorPolicy(
                ctor,
                new InjectionParameterValue[]
            {
                new ResolvedParameter(typeof(ICommand <>), "concrete")
            });

            var ctx = new BuilderContextMock
            {
                BuildKey = new NamedTypeBuildKey(typeof(LoggingCommand <User>))
            };

            SelectedConstructor result = policy.SelectConstructor(ctx, new PolicyList());

            ConstructorInfo expectedCtor = typeof(LoggingCommand <User>).GetMatchingConstructor(Types(typeof(ICommand <User>)));

            Assert.Same(expectedCtor, result.Constructor);
        }