예제 #1
0
        [ActiveIssue(25498, TestPlatforms.AnyUnix)] // System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
        public void GetExports()
        {
            var catalog = new TypeCatalog(Assembly.GetExecutingAssembly().GetTypes());
            Expression <Func <ExportDefinition, bool> > constraint = (ExportDefinition exportDefinition) => exportDefinition.ContractName == AttributedModelServices.GetContractName(typeof(MyExport));
            IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > matchingExports = catalog.GetExports(constraint);

            Assert.NotNull(matchingExports);
            Assert.True(matchingExports.Count() >= 0);

            IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > expectedMatchingExports = catalog.Parts
                                                                                                        .SelectMany(part => part.ExportDefinitions, (part, export) => new Tuple <ComposablePartDefinition, ExportDefinition>(part, export))
                                                                                                        .Where(partAndExport => partAndExport.Item2.ContractName == AttributedModelServices.GetContractName(typeof(MyExport)));

            Assert.True(matchingExports.SequenceEqual(expectedMatchingExports));
        }
예제 #2
0
 private static string NameForType <T>()
 {
     return(AttributedModelServices.GetContractName(typeof(T)));
 }
예제 #3
0
        [ActiveIssue(25498, TestPlatforms.AnyUnix)] // System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
        public void ICompositionElementDisplayName_ShouldIncludeDerivedCatalogTypeNameAndTypeFullNames()
        {
            var expectations = Expectations.GetAttributedTypes();

            foreach (var e in expectations)
            {
                var catalog = (ICompositionElement) new DerivedTypeCatalog(e);

                string expected = string.Format(SR.TypeCatalog_DisplayNameFormat, typeof(DerivedTypeCatalog).Name, AttributedModelServices.GetTypeIdentity(e));

                Assert.Equal(expected, catalog.DisplayName);
            }
        }
예제 #4
0
 private static ImportDefinition CreateImportDefinition(Type type, string metadataKey)
 {
     return(new ContractBasedImportDefinition(AttributedModelServices.GetContractName(typeof(IMyExporter)), null, new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>(metadataKey, typeof(object)) }, ImportCardinality.ZeroOrMore, true, true, CreationPolicy.Any));
 }
예제 #5
0
 private Export GetSingleLazy <T>(ComposablePart part)
 {
     return(this.GetSingleExport(part, AttributedModelServices.GetContractName(typeof(T))));
 }
예제 #6
0
 public MicroExport(Type contractType, IDictionary <string, object> metadata, params object[] exportedValues)
     : this(AttributedModelServices.GetContractName(contractType), exportedValues[0].GetType(), metadata, exportedValues)
 {
 }
예제 #7
0
        public MicroExport(string contractName, Type contractType, IDictionary <string, object> metadata, params object[] exportedValues)
        {
            this.ContractName   = contractName;
            this.ExportedValues = exportedValues;

            if (contractType != null)
            {
                string typeIdentity = AttributedModelServices.GetTypeIdentity(contractType);

                if (metadata == null)
                {
                    metadata = new Dictionary <string, object>();
                }

                object val;
                if (!metadata.TryGetValue(CompositionConstants.ExportTypeIdentityMetadataName, out val))
                {
                    metadata.Add(CompositionConstants.ExportTypeIdentityMetadataName, AttributedModelServices.GetTypeIdentity(contractType));
                }
            }
            this.Metadata = metadata;
        }
예제 #8
0
        public static string GetContractName(Type type)
        {
            Requires.NotNull(type, nameof(type));

            return(AttributedModelServices.GetTypeIdentity(type));
        }
예제 #9
0
 public MicroExport(Type contractType, params object[] exportedValues)
     : this(AttributedModelServices.GetContractName(contractType), contractType, (IDictionary <string, object>)null, exportedValues)
 {
 }
예제 #10
0
        public void GetExports()
        {
            var catalog = new AggregateCatalog();
            Expression <Func <ExportDefinition, bool> > constraint = (ExportDefinition exportDefinition) => exportDefinition.ContractName == AttributedModelServices.GetContractName(typeof(MyExport));
            IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > matchingExports = null;

            matchingExports = catalog.GetExports(constraint);
            Assert.NotNull(matchingExports);
            Assert.True(matchingExports.Count() == 0);

            var testsDirectoryCatalog = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory());

            catalog.Catalogs.Add(testsDirectoryCatalog);
            matchingExports = catalog.GetExports(constraint);

            Assert.NotNull(matchingExports);
            Assert.True(matchingExports.Count() >= 0);

            IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > expectedMatchingExports = catalog.Parts
                                                                                                        .SelectMany(part => part.ExportDefinitions, (part, export) => new Tuple <ComposablePartDefinition, ExportDefinition>(part, export))
                                                                                                        .Where(partAndExport => partAndExport.Item2.ContractName == AttributedModelServices.GetContractName(typeof(MyExport)));

            Assert.True(matchingExports.SequenceEqual(expectedMatchingExports));

            catalog.Catalogs.Remove(testsDirectoryCatalog);
            matchingExports = catalog.GetExports(constraint);
            Assert.NotNull(matchingExports);
            Assert.True(matchingExports.Count() == 0);
        }
예제 #11
0
        public static ComposablePartDefinition CreatePartDefinition(Type type, ICompositionElement?origin)
        {
            Requires.NotNull(type, nameof(type));

            return(AttributedModelServices.CreatePartDefinition(type, origin, false));
        }
예제 #12
0
 private static string[] GetContractNames(IEnumerable <Type> types)
 {
     return(GetContractNames(types.Select(t => AttributedModelServices.CreatePartDefinition(t, null)).SelectMany(p => p.ExportDefinitions)));
 }
예제 #13
0
        private static object CreateStronglyTypedExportFactoryOfTM <T, M>(Export export, ConstructorInfo constructor)
        {
            Func <Tuple <T, Action> > exportLifetimeContextCreator = () => ExportServices.GetExportLifetimeContextFromExport <T>(export);

            return(constructor.Invoke(new object[] { exportLifetimeContextCreator, AttributedModelServices.GetMetadataView <M>(export.Metadata) }));
        }
예제 #14
0
        public static CompositionScopeDefinition AsScopeWithPublicSurface <T>(this ComposablePartCatalog catalog, params CompositionScopeDefinition[] children)
        {
            IEnumerable <ExportDefinition> definitions = catalog.Parts.SelectMany((p) => p.ExportDefinitions.Where((e) => e.ContractName == AttributedModelServices.GetContractName(typeof(T))));

            return(new CompositionScopeDefinition(catalog, children, definitions));
        }
 public static string GetContractName(Type type)
 {
     return(AttributedModelServices.GetTypeIdentity(type));
 }
예제 #16
0
        public void ICompositionElementDisplayName_SingleTypeAsTypesArgument_ShouldIncludeCatalogTypeNameAndTypeFullName()
        {
            var expectations = Expectations.GetAttributedTypes();

            foreach (var e in expectations)
            {
                var catalog = (ICompositionElement)CreateTypeCatalog(e);

                string expected = string.Format(Strings.TypeCatalog_DisplayNameFormat, typeof(TypeCatalog).Name, AttributedModelServices.GetTypeIdentity(e));

                Assert.AreEqual(expected, catalog.DisplayName);
            }
        }