コード例 #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>();
            });
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        static void AssertHasDeclaredAttributesUnderConvention <TSource>(Expression <Func <TSource, object> > property, RegistrationBuilder convention)
        {
            var pi = GetPropertyFromAccessor(property);

            AssertHasAttributesUnderConvention <TSource>(property, convention, pi.GetCustomAttributes(true));
        }
コード例 #4
0
        // 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));
        }