public void Recomposition_PartDefWithNonRecomposableImportIsRemoved_ExportsMatchingImportChanged_ShouldNotBeRejected() { string dependencyContractName = "dependency"; var exportValue = new object(); var exporterPart = PartFactory.CreateExporter(dependencyContractName, exportValue); var importerPart = PartFactory.CreateImporter(dependencyContractName, false); var exporterCatalog = CatalogFactory.Create(exporterPart); var importerCatalog = CatalogFactory.Create(importerPart); var aggregateCatalog = CatalogFactory.CreateAggregateCatalog(importerCatalog, exporterCatalog); var provider = new CatalogExportProvider(aggregateCatalog); provider.SourceProvider = provider; var exports = provider.GetExports(importerPart.ImportDefinitions.Single()); Assert.AreEqual(exportValue, importerPart.Value, "Importer was not composed"); aggregateCatalog.Catalogs.Remove(importerCatalog); aggregateCatalog.Catalogs.Remove(exporterCatalog); Assert.AreEqual(exportValue, importerPart.Value, "Importer was unexpectedly recomposed"); }
public void Dispose_CanBeCalledMultipleTimes() { var catalog = CatalogFactory.Create(); catalog.Dispose(); catalog.Dispose(); catalog.Dispose(); }
public void GetExports_NullAsConstraintArgument_ShouldThrowArgumentNull() { var catalog = CatalogFactory.Create(); Assert.Throws <ArgumentNullException>("definition", () => { catalog.GetExports((ImportDefinition)null); }); }
private static CompositionContainer GetContainer(Dependency partADependency, Dependency partBDependency) { var partA = CreatePartA(partADependency); var partB = CreatePartB(partBDependency); var catalog = CatalogFactory.Create(partA, partB); return(ContainerFactory.Create(catalog)); }
public void GetExports_WhenDisposed_ShouldThrowObjectDisposed() { var catalog = CatalogFactory.Create(); catalog.Dispose(); var definition = ImportDefinitionFactory.Create(); ExceptionAssert.ThrowsDisposed(catalog, () => { catalog.GetExports(definition); }); }
/// <summary> /// Merge the set of PDF documents. /// </summary> public static byte[] Merge(IReadOnlyList <byte[]> files, IReadOnlyList <IReadOnlyList <int> > pagesBundle = null) { if (files == null) { throw new ArgumentNullException(nameof(files)); } const bool isLenientParsing = false; var documentBuilder = new DocumentMerger(); foreach (var fileIndex in Enumerable.Range(0, files.Count)) { var file = files[fileIndex]; IReadOnlyList <int> pages = null; if (pagesBundle != null && fileIndex < pagesBundle.Count) { pages = pagesBundle[fileIndex]; } var inputBytes = new ByteArrayInputBytes(file); var coreScanner = new CoreTokenScanner(inputBytes); var version = FileHeaderParser.Parse(coreScanner, isLenientParsing, Log); var crossReferenceParser = new CrossReferenceParser(Log, new XrefOffsetValidator(Log), new Parser.Parts.CrossReference.CrossReferenceStreamParser(FilterProvider)); CrossReferenceTable crossReference = null; // ReSharper disable once AccessToModifiedClosure var locationProvider = new ObjectLocationProvider(() => crossReference, inputBytes); var pdfScanner = new PdfTokenScanner(inputBytes, locationProvider, FilterProvider, NoOpEncryptionHandler.Instance); var crossReferenceOffset = FileTrailerParser.GetFirstCrossReferenceOffset(inputBytes, coreScanner, isLenientParsing); crossReference = crossReferenceParser.Parse(inputBytes, isLenientParsing, crossReferenceOffset, version.OffsetInFile, pdfScanner, coreScanner); var catalogDictionaryToken = ParseCatalog(crossReference, pdfScanner, out var encryptionDictionary); if (encryptionDictionary != null) { throw new PdfDocumentEncryptedException("Unable to merge document with password"); } var documentCatalog = CatalogFactory.Create(crossReference.Trailer.Root, catalogDictionaryToken, pdfScanner, isLenientParsing); documentBuilder.AppendDocument(documentCatalog, version.Version, pdfScanner, pages); } return(documentBuilder.Build()); }
public static IEnumerable <ComposablePartCatalog> GetCatalogs() { yield return(CatalogFactory.Create()); yield return(CatalogFactory.CreateDefaultAttributed()); }
public void Dispose_ShouldNotThrow() { var catalog = CatalogFactory.Create(); catalog.Dispose(); }
private static CatalogExportProvider CreateCatalogExportProvider(params ComposablePart[] parts) { return(CreateCatalogExportProvider(CatalogFactory.Create(parts))); }
private static CatalogExportProvider CreateCatalogExportProvider(params ComposablePartDefinition[] definitions) { return(CreateCatalogExportProvider(CatalogFactory.Create(definitions))); }
private static CatalogExportProvider CreateCatalogExportProvider() { return(CreateCatalogExportProvider(CatalogFactory.Create())); }