Beispiel #1
0
        public void AmbiguousConstructor_ShouldFail()
        {
            var ctx = new RegistrationBuilder();

            ctx.ForType <AmbiguousConstructors>().Export();
            ctx.ForType <ConstructorArgs>().ExportProperties((m) => m.Name == "IntArg");
            ctx.ForType <ConstructorArgs>().ExportProperties((m) => m.Name == "StringArg");

            var catalog = new TypeCatalog(Helpers.GetEnumerableOfTypes(
                                              typeof(AmbiguousConstructors),
                                              typeof(ConstructorArgs)),
                                          ctx);

            Assert.AreEqual(catalog.Parts.Count(), 2);
            var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);

            ExceptionAssert.Throws <CompositionException>(() =>
            {
                var item = container.GetExportedValue <AmbiguousConstructors>();
            });
        }
        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);
        }
        static void AssertHasDeclaredAttributesUnderConvention <TSource>(Expression <Func <TSource, object> > property, RegistrationBuilder convention)
        {
            var pi = GetPropertyFromAccessor(property);

            AssertHasAttributesUnderConvention <TSource>(property, convention, pi.GetCustomAttributes(true));
        }
        // Flattened so that we can be sure nothing funky is going on in the base type

        static void AssertHasDeclaredAttributesUnderConvention <TSource>(RegistrationBuilder convention)
        {
            AssertHasAttributesUnderConvention <TSource>(convention, typeof(TSource).GetCustomAttributes(true));
        }