Beispiel #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"]);
        }
        public void SetUp()
        {
            this.container = new UnityContainer();
            this.extension = new TestHelperExtension();

            this.configuration
                = new TestClassConfiguration("string 1", "string 2", "42", "bar", "bar-baz");
            this.configuration.Prop6 = new Dictionary <string, int>();
            this.configuration.Prop6.Add("bar", 0);
            this.configuration.Prop6.Add("baz", 42);
        }
Beispiel #3
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);
        }