private void AddInjector(InjectorData injectorData, InjectorCollectionNode injectorsNode) { ConfigurationNode injectorNode = NodeCreationService.CreateNodeByDataType(injectorData.GetType(), new object[] { injectorData }); if (injectorNode == null) { LogNodeMapError(injectorsNode, injectorData.GetType()); } else { injectorsNode.AddNode(injectorNode); } }
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); InjectorData remotingInjectorData = new RemotingInjectorData("remoting"); FakeInjectorData fakeInjectorData = new FakeInjectorData("fake"); fakeInjectorData.ExtraValue = 75; settings.Injectors.Add(remotingInjectorData); settings.Injectors.Add(fakeInjectorData); settings.Injectors.DefaultInjector = fakeInjectorData.Name; 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); Assert.AreEqual(2, deserializedSection.Injectors.Count); Assert.AreEqual(settings.Injectors.DefaultInjector, deserializedSection.Injectors.DefaultInjector); InjectorData injector1Data = settings.Injectors[0]; InjectorData injector2Data = settings.Injectors[1]; Assert.AreEqual(typeof(RemotingInjectorData), injector1Data.GetType()); Assert.AreEqual(typeof(FakeInjectorData), injector2Data.GetType()); Assert.AreEqual(fakeInjectorData.ExtraValue, ((FakeInjectorData)injector2Data).ExtraValue); }