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")); }
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); }
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")); }
public void CanAddPolicyToBagAndRetrieveIt() { PolicyList list = new PolicyList(); list.Set <IBuilderPolicy>(new MockPolicy(), typeof(object), null); Assert.IsNotNull(list.Get <IBuilderPolicy>(typeof(object), null)); }
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")); }
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)); }
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); }
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); }
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); }
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); }