public void MatchingRuleHasTransientLifetime()
        {
            MethodSignatureMatchingRuleData ruleData = new MethodSignatureMatchingRuleData("ruleName", "Foo");
            TypeRegistration registration = ruleData.GetRegistrations("").First();

            Assert.AreEqual(TypeRegistrationLifetime.Transient, registration.Lifetime);
        }
        public void MatchingRuleHasTransientLifetime()
        {
            MethodSignatureMatchingRuleData ruleData = new MethodSignatureMatchingRuleData("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(MethodSignatureMatchingRule), registration.MappedToType);
                Assert.AreSame(typeof(TransientLifetimeManager), registration.LifetimeManagerType);
            }
        }
        public void CanSerializeTypeMatchingRule()
        {
            MethodSignatureMatchingRuleData sigMatchingRule = new MethodSignatureMatchingRuleData("RuleName", "Contains");
            sigMatchingRule.IgnoreCase = true;
            sigMatchingRule.Parameters.Add(new ParameterTypeElement("p1", "String"));

            MethodSignatureMatchingRuleData deserializedRule = SerializeAndDeserializeMatchingRule(sigMatchingRule) as MethodSignatureMatchingRuleData;

            Assert.IsNotNull(deserializedRule);
            AssertAreSame(sigMatchingRule, deserializedRule);
            ParameterTypeElement param = deserializedRule.Parameters.Get(0);
            Assert.IsNotNull(param);
            Assert.AreEqual("String", param.ParameterTypeName);
        }
        public void CanSerializeMethodSignatureContainingDuplicatedTypes()
        {
            MethodSignatureMatchingRuleData ruleData =
                new MethodSignatureMatchingRuleData("ruleName", "Foo");
            ruleData.Parameters.Add(new ParameterTypeElement("p1", "System.String"));
            ruleData.Parameters.Add(new ParameterTypeElement("p2", "System.Int"));
            ruleData.Parameters.Add(new ParameterTypeElement("p3", "System.String"));

            Assert.AreEqual(3, ruleData.Parameters.Count);

            MethodSignatureMatchingRuleData deserializedRule = SerializeAndDeserializeMatchingRule(ruleData) as MethodSignatureMatchingRuleData;

            Assert.IsNotNull(deserializedRule);
            AssertAreSame(ruleData, deserializedRule);
        }
Exemple #5
0
        /// <summary>
        /// Builds an instance of the subtype of IMatchingRule type that the receiver knows how to build, based on
        /// an 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)
        {
            MethodSignatureMatchingRuleData castedRuleData = (MethodSignatureMatchingRuleData)objectConfiguration;

            List <string> parameterTypes = new List <string>();

            foreach (ParameterTypeElement parameterType in castedRuleData.Parameters)
            {
                parameterTypes.Add(parameterType.ParameterTypeName);
            }

            MethodSignatureMatchingRule matchingRule = new MethodSignatureMatchingRule(castedRuleData.Match, parameterTypes, castedRuleData.IgnoreCase);

            return(matchingRule);
        }
        void AssertAreSame(MethodSignatureMatchingRuleData expected,
                           MethodSignatureMatchingRuleData actual)
        {
            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.Match, actual.Match);
            Assert.AreEqual(expected.IgnoreCase, actual.IgnoreCase);

            Assert.AreEqual(expected.Parameters.Count, actual.Parameters.Count);
            for (int i = 0; i < expected.Parameters.Count; ++i)
            {
                ParameterTypeElement expectedElement = expected.Parameters.Get(i);
                ParameterTypeElement actualElement = actual.Parameters.Get(i);

                Assert.AreEqual(expectedElement.ParameterTypeName, actualElement.ParameterTypeName,
                                "Parameter type mismatch at element {0}", i);
            }
        }