/// <summary> /// Create a new <see cref="CustomCallHandlerNode"/> with the supplied settings. /// </summary> /// <param name="callHandlerData">Settings read from configuration source for this handler.</param> public CustomCallHandlerNode(CustomCallHandlerData callHandlerData) : base(callHandlerData) { typeName = callHandlerData.TypeName; foreach (string key in callHandlerData.Attributes) { editableAttributes.Add(new EditableKeyValue(key, callHandlerData.Attributes[key])); } }
/// <summary> /// Convert the data stored into this node into the corresponding /// configuration class (<see cref="CustomCallHandlerData"/>). /// </summary> /// <returns>Newly created <see cref="CustomCallHandlerData"/> containing /// the configuration data from this node.</returns> public override CallHandlerData CreateCallHandlerData() { CustomCallHandlerData callHandlerData = new CustomCallHandlerData(Name, typeName); foreach (EditableKeyValue kv in editableAttributes) { callHandlerData.Attributes.Add(kv.Key, kv.Value); } return(callHandlerData); }
public void CanSerializeConfigurationFixture() { PolicyInjectionSettings settings = new PolicyInjectionSettings(); PolicyData policy1 = new PolicyData(policy1Name); PolicyData policy2 = new PolicyData(policy2Name); settings.Policies.Add(policy1); settings.Policies.Add(policy2); CustomCallHandlerData handler1 = new CustomCallHandlerData(handler1Name, typeof(CallCountHandler)); handler1.SetAttributeValue("customHandlerAttribute", "customHandlerAttributeValue"); CustomMatchingRuleData customMatchingRule = new CustomMatchingRuleData(matchingRule1Name, typeof(TypeMatchingAssignmentRule)); customMatchingRule.SetAttributeValue("customMatchingRuleAttribute", "customMatchingRuleAttributeValue"); policy1.Handlers.Add(handler1); policy1.MatchingRules.Add(customMatchingRule); Dictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>(); sections.Add(PolicyInjectionSettings.SectionName, settings); IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections); PolicyInjectionSettings deserializedSection = (PolicyInjectionSettings)configurationSource.GetSection(PolicyInjectionSettings.SectionName); Assert.AreEqual(2, deserializedSection.Policies.Count); PolicyData deserializedPolicy1 = deserializedSection.Policies.Get(0); Assert.IsNotNull(deserializedPolicy1); Assert.AreEqual(policy1Name, deserializedPolicy1.Name); CallHandlerData deserializedHandler = deserializedPolicy1.Handlers.Get(0); Assert.IsNotNull(deserializedHandler); Assert.IsNotNull(deserializedHandler as CustomCallHandlerData); Assert.AreEqual(handler1Name, deserializedHandler.Name); Assert.AreEqual(typeof(CallCountHandler), deserializedHandler.Type); Assert.AreEqual("customHandlerAttributeValue", (string)deserializedHandler.ElementInformation.Properties["customHandlerAttribute"].Value); Assert.AreEqual(policy2Name, deserializedSection.Policies.Get(1).Name); MatchingRuleData deserializedMatchingRule = deserializedPolicy1.MatchingRules.Get(0); Assert.IsNotNull(deserializedMatchingRule as CustomMatchingRuleData); Assert.AreEqual(matchingRule1Name, deserializedMatchingRule.Name); Assert.AreEqual(typeof(TypeMatchingAssignmentRule), deserializedMatchingRule.Type); Assert.AreEqual("customMatchingRuleAttributeValue", (string)deserializedMatchingRule.ElementInformation.Properties["customMatchingRuleAttribute"].Value); }
private IConfigurationSource CreateConfigurationSource(string globalCallHandlerName) { PolicyInjectionSettings injectionSettings = new PolicyInjectionSettings(); PolicyData policyData = new PolicyData(); CustomCallHandlerData customCallHandlerData = new CustomCallHandlerData("globalCountHandler", typeof(GlobalCountCallHandler)); customCallHandlerData.Attributes.Add("callhandler", globalCallHandlerName); policyData.Handlers.Add(customCallHandlerData); policyData.MatchingRules.Add(new CustomMatchingRuleData("alwaystrue", typeof(AlwaysMatchingRule))); injectionSettings.Policies.Add(policyData); DictionaryConfigurationSource configSource = new DictionaryConfigurationSource(); configSource.Add(PolicyInjectionSettings.SectionName, injectionSettings); return(configSource); }
public void CanSerializeConfigurationFixture() { PolicyInjectionSettings settings = new PolicyInjectionSettings(); PolicyData policy1 = new PolicyData(policy1Name); PolicyData policy2 = new PolicyData(policy2Name); settings.Policies.Add(policy1); settings.Policies.Add(policy2); CustomCallHandlerData handler1 = new CustomCallHandlerData(handler1Name, typeof(CallCountHandler)); handler1.SetAttributeValue("customHandlerAttribute", "customHandlerAttributeValue"); CustomMatchingRuleData customMatchingRule = new CustomMatchingRuleData(matchingRule1Name, typeof(TypeMatchingAssignmentRule)); customMatchingRule.SetAttributeValue("customMatchingRuleAttribute", "customMatchingRuleAttributeValue"); policy1.Handlers.Add(handler1); policy1.MatchingRules.Add(customMatchingRule); Dictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>(); sections.Add(PolicyInjectionSettings.SectionName, settings); IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections); PolicyInjectionSettings deserializedSection = (PolicyInjectionSettings)configurationSource.GetSection(PolicyInjectionSettings.SectionName); Assert.AreEqual(2, deserializedSection.Policies.Count); PolicyData deserializedPolicy1 = deserializedSection.Policies.Get(0); Assert.IsNotNull(deserializedPolicy1); Assert.AreEqual(policy1Name, deserializedPolicy1.Name); CallHandlerData deserializedHandler = deserializedPolicy1.Handlers.Get(0); Assert.IsNotNull(deserializedHandler); Assert.IsNotNull(deserializedHandler as CustomCallHandlerData); Assert.AreEqual(handler1Name, deserializedHandler.Name); Assert.AreEqual(typeof(CallCountHandler), deserializedHandler.Type); Assert.AreEqual("customHandlerAttributeValue", (string)deserializedHandler.ElementInformation.Properties["customHandlerAttribute"].Value); Assert.AreEqual(policy2Name, deserializedSection.Policies.Get(1).Name); MatchingRuleData deserializedMatchingRule = deserializedPolicy1.MatchingRules.Get(0); Assert.IsNotNull(deserializedMatchingRule as CustomMatchingRuleData); Assert.AreEqual(matchingRule1Name, deserializedMatchingRule.Name); Assert.AreEqual(typeof(TypeMatchingAssignmentRule), deserializedMatchingRule.Type); Assert.AreEqual("customMatchingRuleAttributeValue", (string)deserializedMatchingRule.ElementInformation.Properties["customMatchingRuleAttribute"].Value); }
public void CanCreateCustomAttributeMatchingRuleNodeFromData() { CustomCallHandlerData handlerData = new CustomCallHandlerData(); handlerData.Name = "customHandler"; handlerData.TypeName = "HandlerType"; handlerData.Attributes.Add("Attribute1", "Value1"); handlerData.Attributes.Add("Attribute2", "Value2"); CustomCallHandlerNode handlerNode = new CustomCallHandlerNode(handlerData); Assert.AreEqual(handlerData.TypeName, handlerNode.Type); Assert.AreEqual(handlerData.Attributes.Count, handlerNode.Attributes.Count); Assert.AreEqual(handlerData.Attributes[0], handlerNode.Attributes[0].Value); Assert.AreEqual(handlerData.Attributes.AllKeys[0], handlerNode.Attributes[0].Key); Assert.AreEqual(handlerData.Attributes[1], handlerNode.Attributes[1].Value); Assert.AreEqual(handlerData.Attributes.AllKeys[1], handlerNode.Attributes[1].Key); }
public void CanCreateRuleDataFromCustomAttributeMatchingRuleNode() { CustomCallHandlerNode handlerNode = new CustomCallHandlerNode(); handlerNode.Name = "cacheHandler"; handlerNode.Type = "HandlerType"; handlerNode.Attributes.Add(new Microsoft.Practices.EnterpriseLibrary.Configuration.Design.EditableKeyValue("Attribute1", "Value1")); handlerNode.Attributes.Add(new Microsoft.Practices.EnterpriseLibrary.Configuration.Design.EditableKeyValue("Attribute2", "Value2")); CustomCallHandlerData handlerData = handlerNode.CreateCallHandlerData() as CustomCallHandlerData; Assert.IsNotNull(handlerData); Assert.AreEqual(handlerNode.Type, handlerData.TypeName); Assert.AreEqual(handlerNode.Attributes.Count, handlerData.Attributes.Count); Assert.AreEqual(handlerNode.Attributes[0].Value, handlerData.Attributes[0]); Assert.AreEqual(handlerNode.Attributes[0].Key, handlerData.Attributes.AllKeys[0]); Assert.AreEqual(handlerNode.Attributes[1].Value, handlerData.Attributes[1]); Assert.AreEqual(handlerNode.Attributes[1].Key, handlerData.Attributes.AllKeys[1]); }
IConfigurationSource CreateConfigurationSource(string globalCallHandlerName) { PolicyInjectionSettings injectionSettings = new PolicyInjectionSettings(); PolicyData policyData = new PolicyData(); CustomCallHandlerData customCallHandlerData = new CustomCallHandlerData("globalCountHandler", typeof(GlobalCountCallHandler)); customCallHandlerData.Attributes.Add("callhandler", globalCallHandlerName); policyData.Handlers.Add(customCallHandlerData); policyData.MatchingRules.Add(new CustomMatchingRuleData("alwaystrue", typeof(AlwaysMatchingRule))); injectionSettings.Policies.Add(policyData); DictionaryConfigurationSource configSource = new DictionaryConfigurationSource(); configSource.Add(PolicyInjectionSettings.SectionName, injectionSettings); return configSource; }