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);
            }
        }
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)
        {
            NamespaceMatchingRuleData castedRuleData = (NamespaceMatchingRuleData)objectConfiguration;

            List <MatchingInfo> matches = new List <MatchingInfo>();

            foreach (MatchData matchData in castedRuleData.Matches)
            {
                matches.Add(new MatchingInfo(matchData.Match, matchData.IgnoreCase));
            }

            NamespaceMatchingRule matchingRule = new NamespaceMatchingRule(matches);

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