コード例 #1
0
        public void CreatesAppropriatePoliciesIfProviderHasProperConstructor()
        {
            TestCustomProviderData data = new TestCustomProviderData();

            data.Name                = "name";
            data.Type                = typeof(TestCustomProviderWithValidConstructor);
            data.Attributes          = new NameValueCollection();
            data.Attributes["name1"] = "value1";
            data.Attributes["name2"] = "value2";
            CustomProviderPolicyCreator <TestCustomProviderData> policyCreator
                = new CustomProviderPolicyCreator <TestCustomProviderData>();
            TestHelperExtension extension = new TestHelperExtension();

            extension.initialize = context =>
            {
                ((IContainerPolicyCreator)policyCreator).CreatePolicies(context.Policies, data.Name, data, null);
            };
            IUnityContainer container = new UnityContainer();

            container.AddExtension(extension);
            TestCustomProviderWithValidConstructor createdObject
                = container.Resolve <TestCustomProviderWithValidConstructor>("name");

            Assert.IsNotNull(createdObject);
            Assert.AreEqual(2, createdObject.Attributes.Count);
            Assert.AreEqual("value1", createdObject.Attributes["name1"]);
            Assert.AreEqual("value2", createdObject.Attributes["name2"]);
        }
コード例 #2
0
        public void CreatesThrowsIfProviderDoesNotHaveProperConstructor()
        {
            TestCustomProviderData data = new TestCustomProviderData();

            data.Name                = "name";
            data.Type                = typeof(TestCustomProviderWithInvalidConstructor);
            data.Attributes          = new NameValueCollection();
            data.Attributes["name1"] = "value1";
            data.Attributes["name2"] = "value2";
            CustomProviderPolicyCreator <TestCustomProviderData> policyCreator
                = new CustomProviderPolicyCreator <TestCustomProviderData>();
            TestHelperExtension extension = new TestHelperExtension();

            extension.initialize = context =>
            {
                ((IContainerPolicyCreator)policyCreator).CreatePolicies(context.Policies, data.Name, data, null);
            };
            IUnityContainer container = new UnityContainer();

            container.AddExtension(extension);
        }