public void MatchingRuleHasTransientLifetime() { PropertyMatchingRuleData ruleData = new PropertyMatchingRuleData("Foo"); TypeRegistration registration = ruleData.GetRegistrations("").First(); Assert.AreEqual(TypeRegistrationLifetime.Transient, registration.Lifetime); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyMatchingRuleNode"/> class for representing a <see cref="PropertyMatchingRuleData"/> instance. /// </summary> /// <param name="ruleData">The <see cref="PropertyMatchingRuleData"/> to represent.</param> public PropertyMatchingRuleNode(PropertyMatchingRuleData ruleData) : base(ruleData) { matches = new List <PropertyMatch>(); foreach (PropertyMatchData match in ruleData.Matches) { matches.Add(new PropertyMatch(match.Match, match.IgnoreCase, match.MatchOption)); } }
/// <summary> /// Returs the represented <see cref="PropertyMatchingRuleData"/> instance. /// </summary> /// <returns>A newly created <see cref="PropertyMatchingRuleData"/> instance.</returns> public override MatchingRuleData GetConfigurationData() { PropertyMatchingRuleData ruleData = new PropertyMatchingRuleData(Name); foreach (PropertyMatch match in matches) { ruleData.Matches.Add(new PropertyMatchData(match.Value, match.MatchOption, match.IgnoreCase)); } return(ruleData); }
public void MatchingRuleHasTransientLifetime() { PropertyMatchingRuleData ruleData = new PropertyMatchingRuleData("Foo"); using (var container = new UnityContainer()) { ruleData.ConfigureContainer(container, "-test"); var registration = container.Registrations.Single(r => r.Name == "Foo-test"); Assert.AreSame(typeof(IMatchingRule), registration.RegisteredType); Assert.AreSame(typeof(PropertyMatchingRule), registration.MappedToType); Assert.AreSame(typeof(TransientLifetimeManager), registration.LifetimeManagerType); } }
public void CanCreateRuleDataFromPropertyMatchingRuleNode() { PropertyMatchingRuleNode ruleNode = new PropertyMatchingRuleNode(); ruleNode.Name = "RuleName"; ruleNode.Matches.Add(new PropertyMatch("Property1", true, PropertyMatchingOption.GetOrSet)); ruleNode.Matches.Add(new PropertyMatch("Property2", false, PropertyMatchingOption.Set)); PropertyMatchingRuleData ruleData = ruleNode.GetConfigurationData() as PropertyMatchingRuleData; 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[0].MatchOption, ruleData.Matches[0].MatchOption); Assert.AreEqual(ruleNode.Matches[1].IgnoreCase, ruleData.Matches[1].IgnoreCase); Assert.AreEqual(ruleNode.Matches[1].Value, ruleData.Matches[1].Match); Assert.AreEqual(ruleNode.Matches[1].MatchOption, ruleData.Matches[1].MatchOption); }
public void CanCreatePropertyMatchingRuleNodeFromData() { PropertyMatchingRuleData ruleData = new PropertyMatchingRuleData(); ruleData.Name = "name o' rule"; ruleData.Matches.Add(new PropertyMatchData("Property1", PropertyMatchingOption.GetOrSet, false)); ruleData.Matches.Add(new PropertyMatchData("Property2", PropertyMatchingOption.Set, false)); PropertyMatchingRuleNode ruleNode = new PropertyMatchingRuleNode(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].MatchOption, ruleNode.Matches[0].MatchOption); 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].MatchOption, ruleNode.Matches[1].MatchOption); Assert.AreEqual(ruleData.Matches[1].Match, ruleNode.Matches[1].Value); }
public void ShouldSerializeAndDeserializeCorrectly() { PropertyMatchingRuleData original = new PropertyMatchingRuleData("MatchMyProperty", new PropertyMatchData[] { new PropertyMatchData("MyProperty", PropertyMatchingOption.Set, true), new PropertyMatchData("*Name"), new PropertyMatchData("Foo??", PropertyMatchingOption.Get) }); PropertyMatchingRuleData rehydrated = (PropertyMatchingRuleData)SerializeAndDeserializeMatchingRule(original); Assert.IsNotNull(rehydrated); Assert.AreEqual(original.Name, rehydrated.Name); Assert.AreEqual(original.Matches.Count, rehydrated.Matches.Count); for (int i = 0; i < original.Matches.Count; ++i) { AssertPropertyMatchEqual(original.Matches[i], rehydrated.Matches[i], "Match at index {0} is incorrect", i); } }