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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds an instance of the subtype of IMatchingRule type the receiver knows how to build, based on
        /// a configuration object.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of the IMatchingRule subtype.</returns>
        public IMatchingRule Assemble(
            IBuilderContext context,
            MatchingRuleData objectConfiguration,
            IConfigurationSource configurationSource,
            ConfigurationReflectionCache reflectionCache)
        {
            PropertyMatchingRuleData    propertyData = (PropertyMatchingRuleData)objectConfiguration;
            List <PropertyMatchingInfo> info         = new List <PropertyMatchingInfo>();

            foreach (PropertyMatchData data in propertyData.Matches)
            {
                info.Add(new PropertyMatchingInfo(data.Match, data.MatchOption, data.IgnoreCase));
            }

            PropertyMatchingRule rule = new PropertyMatchingRule(info);

            return(rule);
        }
        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);
            }
        }