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); } }
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); } }
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); }
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); }
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); }
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); }