Beispiel #1
0
 public void AttemptToCreatePoliciesWithNonMatchingConfigurationObjectThrows()
 {
     container.AddExtension(
         new TestHelperExtension(context =>
     {
         IContainerPolicyCreator creator = new ConstructorArgumentMatchingPolicyCreator(typeof(TestClass));
         creator.CreatePolicies(context.Policies,
                                instanceName,
                                new TestClassEmptySource(),
                                null);
     }));
 }
Beispiel #2
0
        public void ChoosesNoArgsConstructor()
        {
            container.AddExtension(
                new TestHelperExtension(context =>
            {
                IContainerPolicyCreator creator
                    = new ConstructorArgumentMatchingPolicyCreator(typeof(TestClassWithNoArgsConstructor));
                creator.CreatePolicies(context.Policies,
                                       instanceName,
                                       new TestClassEmptySource(),
                                       null);
            }));
            TestClassWithNoArgsConstructor provider
                = container.Resolve <TestClassWithNoArgsConstructor>(instanceName);

            Assert.IsNotNull(provider);
        }
Beispiel #3
0
        public void IndexerPropertiesAreNotConsideredForMatching()
        {
            TestClassSourceWithIndexerProperty source = new TestClassSourceWithIndexerProperty();

            source.Property1 = 1;
            container.AddExtension(
                new TestHelperExtension(context =>
            {
                IContainerPolicyCreator creator
                    = new ConstructorArgumentMatchingPolicyCreator(typeof(TestClassWithItemArgument));
                creator.CreatePolicies(context.Policies,
                                       instanceName,
                                       source,
                                       null);
            }));
            TestClassWithItemArgument provider
                = container.Resolve <TestClassWithItemArgument>(instanceName);

            Assert.IsNotNull(provider);
            Assert.AreEqual(source.Property1, provider.Property1);
            Assert.AreEqual("no value set", provider.Property2);
        }
Beispiel #4
0
        public void ChoosesConstructorWithMaximalNumberOfMatchingParameters()
        {
            TestClassSource source = new TestClassSource();

            source.Property1 = 1;
            source.Property2 = "value2";
            container.AddExtension(
                new TestHelperExtension(context =>
            {
                IContainerPolicyCreator creator
                    = new ConstructorArgumentMatchingPolicyCreator(typeof(TestClassWhereLongestConstructorCannotBeMatched));
                creator.CreatePolicies(context.Policies,
                                       instanceName,
                                       source,
                                       null);
            }));
            TestClassWhereLongestConstructorCannotBeMatched provider
                = container.Resolve <TestClassWhereLongestConstructorCannotBeMatched>(instanceName);

            Assert.IsNotNull(provider);
            Assert.AreEqual(source.Property1, provider.Property1);
            Assert.AreEqual(source.Property2, provider.Property2);
        }
Beispiel #5
0
        public void DerivedTypesAreAllowedWhenMatchingProperties()
        {
            TestClassSource source = new TestClassSource();

            source.Property1 = 1;
            source.Property2 = "value2";
            container.AddExtension(
                new TestHelperExtension(context =>
            {
                IContainerPolicyCreator creator
                    = new ConstructorArgumentMatchingPolicyCreator(typeof(TestClassWithInterfaceArgument));
                creator.CreatePolicies(context.Policies,
                                       instanceName,
                                       source,
                                       null);
            }));
            TestClassWithInterfaceArgument provider
                = container.Resolve <TestClassWithInterfaceArgument>(instanceName);

            Assert.IsNotNull(provider);
            Assert.AreEqual(source.Property1, provider.Property1);
            Assert.AreEqual("value2", provider.Property2);
        }
Beispiel #6
0
        public void TypesAreConsideredWhenMatchingProperties()
        {
            TestClassSourceWithPropertyOfNonMatchingType source = new TestClassSourceWithPropertyOfNonMatchingType();

            source.Property1 = 1;
            source.Property2 = new object();
            container.AddExtension(
                new TestHelperExtension(context =>
            {
                IContainerPolicyCreator creator
                    = new ConstructorArgumentMatchingPolicyCreator(typeof(TestClass));
                creator.CreatePolicies(context.Policies,
                                       instanceName,
                                       source,
                                       null);
            }));
            TestClass provider
                = container.Resolve <TestClass>(instanceName);

            Assert.IsNotNull(provider);
            Assert.AreEqual(source.Property1, provider.Property1);
            Assert.AreEqual("not set", provider.Property2);
        }