/// <summary> /// Returns the export definitions that match the constraint defined by the specified definition. /// </summary> /// <param name="definition"> /// The <see cref="ImportDefinition"/> that defines the conditions of the /// <see cref="ExportDefinition"/> objects to return. /// </param> /// <returns> /// An <see cref="IEnumerable{T}"/> of <see cref="Tuple{T1, T2}"/> containing the /// <see cref="ExportDefinition"/> objects and their associated /// <see cref="ComposablePartDefinition"/> for objects that match the constraint defined /// by <paramref name="definition"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="definition"/> is <see langword="null"/>. /// </exception> /// <exception cref="ObjectDisposedException"> /// The <see cref="DirectoryCatalog"/> has been disposed of. /// </exception> public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition) { ThrowIfDisposed(); Requires.NotNull(definition, "definition"); return(InnerCatalog.GetExports(definition)); }
public void GetExports() { using (var directory = CreateTemporaryDirectory()) { var catalog = new AggregateCatalog(); Expression<Func<ExportDefinition, bool>> constraint = (ExportDefinition exportDefinition) => exportDefinition.ContractName == AttributedModelServices.GetContractName(typeof(MyExport)); IEnumerable<Tuple2<ComposablePartDefinition, ExportDefinition>> matchingExports = null; matchingExports = catalog.GetExports(constraint); Assert.IsNotNull(matchingExports); Assert.IsTrue(matchingExports.Count() == 0); var testsDirectoryCatalog = new DirectoryCatalog(directory.DirectoryPath); catalog.Catalogs.Add(testsDirectoryCatalog); matchingExports = catalog.GetExports(constraint); Assert.IsNotNull(matchingExports); Assert.IsTrue(matchingExports.Count() >= 0); IEnumerable<Tuple2<ComposablePartDefinition, ExportDefinition>> expectedMatchingExports = catalog.Parts .SelectMany(part => part.ExportDefinitions, (part, export) => new Tuple2<ComposablePartDefinition, ExportDefinition>(part, export)) .Where(partAndExport => partAndExport.Item2.ContractName == AttributedModelServices.GetContractName(typeof(MyExport))); Assert.IsTrue(matchingExports.SequenceEqual(expectedMatchingExports)); catalog.Catalogs.Remove(testsDirectoryCatalog); matchingExports = catalog.GetExports(constraint); Assert.IsNotNull(matchingExports); Assert.IsTrue(matchingExports.Count() == 0); } }