static void AssertHasAttributesUnderConvention <TSource>(RegistrationBuilder convention, IEnumerable <object> expected)
        {
            var mapped  = convention.MapType(typeof(TSource).GetTypeInfo());
            var applied = mapped.GetCustomAttributes(true);

            // Was: CollectionAssert.AreEquivalent(expected, applied) - output is not much good.
            AssertEquivalentAttributes(expected, applied);
        }
        static void AssertHasAttributesUnderConvention <TSource>(Expression <Func <TSource, object> > property, RegistrationBuilder convention, IEnumerable <object> expected)
        {
            var mapped  = convention.MapType(typeof(TSource).GetTypeInfo());
            var pi      = GetPropertyFromAccessor(property);
            var applied = mapped.GetProperty(pi.Name).GetCustomAttributes(true);

            // Was: CollectionAssert.AreEquivalent(expected, applied) - output is not much good.
            AssertEquivalentAttributes(expected, applied);
        }
        public void ConstructorConvention_OverrideOnDeclaration_ConventionIgnored()
        {
            var rb = new RegistrationBuilder();

            rb.ForType <TwoConstructorsWithOverride>()
            .SelectConstructor(pi => new TwoConstructorsWithOverride(pi.Import <IContractA>(), pi.Import <IContractB>()));

            var mapped = rb.MapType(typeof(TwoConstructorsWithOverride).GetTypeInfo());

            var conventional      = mapped.GetConstructor(new[] { rb.MapType(typeof(IContractA).GetTypeInfo()), rb.MapType(typeof(IContractB).GetTypeInfo()) });
            var conventionalAttrs = conventional.GetCustomAttributes(true);

            Assert.IsFalse(conventionalAttrs.Any());

            var overridden     = mapped.GetConstructor(new[] { rb.MapType(typeof(IContractA).GetTypeInfo()) });
            var overriddenAttr = overridden.GetCustomAttributes(true).Single();

            Assert.AreEqual(new ImportingConstructorAttribute(), overriddenAttr);
        }
        public void ConventionsInInnerAndOuterRCs_InnerRCTakesPrecendence()
        {
            var innerConvention = new RegistrationBuilder();

            innerConvention.ForType <ConventionTarget>().Export(eb => eb.AsContractName(ContractNames.ContractX));
            var innerType = innerConvention.MapType(typeof(ConventionTarget).GetTypeInfo());

            var outerConvention = new RegistrationBuilder();

            outerConvention.ForType <ConventionTarget>().Export(eb => eb.AsContractName(ContractNames.ContractY));
            var outerType = outerConvention.MapType(innerType /*.GetTypeInfo()*/);

            var export = outerType.GetCustomAttributes(false).OfType <ExportAttribute>().Single();

            Assert.AreEqual(ContractNames.ContractX, export.ContractName);
        }