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.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); } }
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.AreSame(expectedCtor, result.Constructor); }