public void MatchingRuleHasTransientLifetime() { NamespaceMatchingRuleData ruleData = new NamespaceMatchingRuleData("ruleName", "Foo"); TypeRegistration registration = ruleData.GetRegistrations("").First(); Assert.AreEqual(TypeRegistrationLifetime.Transient, registration.Lifetime); }
/// <summary> /// Initializes a new instance of the <see cref="NamespaceMatchingRuleNode"/> class for representing a <see cref="NamespaceMatchingRuleData"/> instance. /// </summary> /// <param name="ruleData">The <see cref="NamespaceMatchingRuleData"/> to represent.</param> public NamespaceMatchingRuleNode(NamespaceMatchingRuleData ruleData) : base(ruleData) { matches = new List <Match>(); foreach (MatchData match in ruleData.Matches) { matches.Add(new Match(match.Match, match.IgnoreCase)); } }
/// <summary> /// Returs the represented <see cref="NamespaceMatchingRuleData"/> instance. /// </summary> /// <returns>A newly created <see cref="NamespaceMatchingRuleData"/> instance.</returns> public override MatchingRuleData GetConfigurationData() { NamespaceMatchingRuleData ruleData = new NamespaceMatchingRuleData(Name); foreach (Match match in matches) { ruleData.Matches.Add(new MatchData(match.Value, match.IgnoreCase)); } return(ruleData); }
public void MatchingRuleHasTransientLifetime() { NamespaceMatchingRuleData ruleData = new NamespaceMatchingRuleData("ruleName", "Foo"); using (var container = new UnityContainer()) { ruleData.ConfigureContainer(container, "-test"); var registration = container.Registrations.Single(r => r.Name == "ruleName-test"); Assert.AreSame(typeof(IMatchingRule), registration.RegisteredType); Assert.AreSame(typeof(NamespaceMatchingRule), registration.MappedToType); Assert.AreSame(typeof(TransientLifetimeManager), registration.LifetimeManagerType); } }
public void CanCreateRuleDataFromNamespaceMatchingRuleNode() { NamespaceMatchingRuleNode ruleNode = new NamespaceMatchingRuleNode(); ruleNode.Name = "RuleName"; ruleNode.Matches.Add(new Match("Namespace1", false)); ruleNode.Matches.Add(new Match("Namspsace1.Namespace2", true)); NamespaceMatchingRuleData ruleData = ruleNode.GetConfigurationData() as NamespaceMatchingRuleData; Assert.IsNotNull(ruleData); Assert.AreEqual(ruleNode.Name, ruleData.Name); Assert.AreEqual(ruleNode.Matches[0].IgnoreCase, ruleData.Matches[0].IgnoreCase); Assert.AreEqual(ruleNode.Matches[0].Value, ruleData.Matches[0].Match); Assert.AreEqual(ruleNode.Matches[1].IgnoreCase, ruleData.Matches[1].IgnoreCase); Assert.AreEqual(ruleNode.Matches[1].Value, ruleData.Matches[1].Match); }
public void CanCreateNamespaceMatchingRuleNodeFromData() { NamespaceMatchingRuleData ruleData = new NamespaceMatchingRuleData(); ruleData.Name = "name o' rule"; ruleData.Matches.Add(new MatchData("Namespace1", false)); ruleData.Matches.Add(new MatchData("Namspsace1.Namespace2", true)); NamespaceMatchingRuleNode ruleNode = new NamespaceMatchingRuleNode(ruleData); Assert.AreEqual(ruleData.Name, ruleNode.Name); Assert.AreEqual(ruleData.Matches.Count, ruleNode.Matches.Count); Assert.AreEqual(ruleData.Matches[0].IgnoreCase, ruleNode.Matches[0].IgnoreCase); Assert.AreEqual(ruleData.Matches[0].Match, ruleNode.Matches[0].Value); Assert.AreEqual(ruleData.Matches[1].IgnoreCase, ruleNode.Matches[1].IgnoreCase); Assert.AreEqual(ruleData.Matches[1].Match, ruleNode.Matches[1].Value); }
public void CanSerializeTypeMatchingRule() { NamespaceMatchingRuleData namespaceMatchingRule = new NamespaceMatchingRuleData("RuleName", new MatchData[] { new MatchData("System.*"), new MatchData("microsoft.*", true), new MatchData("Microsoft.Practices.EnterpriseLibrary.PolicyInjection") }); Assert.AreEqual(3, namespaceMatchingRule.Matches.Count); NamespaceMatchingRuleData deserializedRule = SerializeAndDeserializeMatchingRule(namespaceMatchingRule) as NamespaceMatchingRuleData; Assert.IsNotNull(deserializedRule); Assert.AreEqual(namespaceMatchingRule.Name, deserializedRule.Name); Assert.AreEqual(namespaceMatchingRule.Matches.Count, deserializedRule.Matches.Count); for (int i = 0; i < namespaceMatchingRule.Matches.Count; ++i) { AssertMatchDataEqual(namespaceMatchingRule.Matches[i], deserializedRule.Matches[i], "Match data at index {0} is incorrect", i); } }