示例#1
0
        public void SetOverwritesExistingPolicy()
        {
            PolicyList list    = new PolicyList();
            MockPolicy policy1 = new MockPolicy();
            MockPolicy policy2 = new MockPolicy();

            list.Set <IBuilderPolicy>(policy1, typeof(string), "1");
            list.Set <IBuilderPolicy>(policy2, typeof(string), "1");

            Assert.AreSame(policy2, list.Get <IBuilderPolicy>(typeof(string), "1"));
        }
示例#2
0
        public void CanClearAllPolicies()
        {
            PolicyList list = new PolicyList();

            list.Set <IBuilderPolicy>(new MockPolicy(), typeof(object), null);
            list.Set <IBuilderPolicy>(new MockPolicy(), typeof(object), "1");

            list.ClearAll();

            Assert.AreEqual(0, list.Count);
        }
示例#3
0
        public void CanAddMultiplePoliciesToBagAndRetrieveThem()
        {
            PolicyList list    = new PolicyList();
            MockPolicy policy1 = new MockPolicy();
            MockPolicy policy2 = new MockPolicy();

            list.Set <IBuilderPolicy>(policy1, typeof(object), "1");
            list.Set <IBuilderPolicy>(policy2, typeof(string), "2");

            Assert.AreSame(policy1, list.Get <IBuilderPolicy>(typeof(object), "1"));
            Assert.AreSame(policy2, list.Get <IBuilderPolicy>(typeof(string), "2"));
        }
示例#4
0
        public void CanAddPolicyToBagAndRetrieveIt()
        {
            PolicyList list = new PolicyList();

            list.Set <IBuilderPolicy>(new MockPolicy(), typeof(object), null);

            Assert.IsNotNull(list.Get <IBuilderPolicy>(typeof(object), null));
        }
示例#5
0
        public void CanClearPolicy()
        {
            PolicyList list   = new PolicyList();
            MockPolicy policy = new MockPolicy();

            list.Set <IBuilderPolicy>(policy, typeof(string), "1");
            list.Clear <IBuilderPolicy>(typeof(string), "1");

            Assert.IsNull(list.Get <IBuilderPolicy>(typeof(string), "1"));
        }
示例#6
0
        public void SpecificPolicyOverridesDefaultPolicy()
        {
            PolicyList list           = new PolicyList();
            MockPolicy defaultPolicy  = new MockPolicy();
            MockPolicy specificPolicy = new MockPolicy();

            list.Set <IBuilderPolicy>(specificPolicy, typeof(object), null);
            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            Assert.AreSame(specificPolicy, list.Get <IBuilderPolicy>(typeof(object), null));
        }
示例#7
0
        public void TestSettingAndRetrievePolicy()
        {
            PolicyList         policies = new PolicyList();
            MockCreationPolicy policy   = new MockCreationPolicy();

            policies.Set <IBuilderPolicy>(policy, typeof(object), null);
            BuilderContext context = new BuilderContext(null, null, policies);

            IBuilderPolicy outPolicy = context.Policies.Get <IBuilderPolicy>(typeof(object), null);

            Assert.IsNotNull(outPolicy);
            Assert.AreSame(policy, outPolicy);
        }
示例#8
0
        public void SettingPolicyViaContextDoesNotAffectPoliciesPassedToContextConstructor()
        {
            PolicyList         policies = new PolicyList();
            MockCreationPolicy policy1  = new MockCreationPolicy();

            policies.Set <IBuilderPolicy>(policy1, typeof(object), null);
            BuilderContext context = new BuilderContext(null, null, policies);

            MockCreationPolicy policy2 = new MockCreationPolicy();

            context.Policies.Set <IBuilderPolicy>(policy2, typeof(string), null);

            Assert.AreEqual(1, policies.Count);
        }
示例#9
0
        public void BuilderCanTakeTransientPolicies()
        {
            Builder    builder  = new Builder();
            Locator    locator  = CreateLocator();
            PolicyList policies = new PolicyList();

            PropertySetterPolicy policy = new PropertySetterPolicy();

            policy.Properties.Add("IntProp", new PropertySetterInfo("IntProp", new ValueParameter <int>(96)));
            policies.Set <IPropertySetterPolicy>(policy, typeof(PropertyObject), null);

            PropertyObject obj = builder.BuildUp <PropertyObject>(locator, null, null, policies);

            Assert.AreEqual(96, obj.IntProp);
        }
示例#10
0
        public void TransientPoliciesOverrideBuilderPolicies()
        {
            Builder    builder  = new Builder();
            Locator    locator  = CreateLocator();
            PolicyList policies = new PolicyList();

            PropertySetterPolicy builderPolicy = new PropertySetterPolicy();

            builderPolicy.Properties.Add("IntProp", new PropertySetterInfo("IntProp", new ValueParameter <int>(11)));
            builder.Policies.Set <IPropertySetterPolicy>(builderPolicy, typeof(PropertyObject), null);

            PropertySetterPolicy transientPolicy = new PropertySetterPolicy();

            transientPolicy.Properties.Add("IntProp", new PropertySetterInfo("IntProp", new ValueParameter <int>(22)));
            policies.Set <IPropertySetterPolicy>(transientPolicy, typeof(PropertyObject), null);

            PropertyObject obj = builder.BuildUp <PropertyObject>(locator, null, null, policies);

            Assert.AreEqual(22, obj.IntProp);
        }