public void MefCtor_CheckExports()
        {
            var batch = new CompositionBatch();

            var stores = new[]
            {
                new Mock <IIssuesStore>(),
                new Mock <IIssuesStore>(),
                new Mock <IIssuesStore>()
            };

            foreach (var issuesStore in stores)
            {
                issuesStore.SetupAdd(x => x.IssuesChanged += null);
                batch.AddExport(MefTestHelpers.CreateExport <IIssuesStore>(issuesStore.Object));
            }

            var locationStoreImport = new SingleObjectImporter <IIssueLocationStore>();

            batch.AddPart(locationStoreImport);

            using var catalog   = new TypeCatalog(typeof(AggregatingIssueLocationStoreAdapter));
            using var container = new CompositionContainer(catalog);
            container.Compose(batch);

            locationStoreImport.Import.Should().NotBeNull();

            // Verify that the stores are used
            foreach (var issuesStore in stores)
            {
                issuesStore.VerifyAdd(x => x.IssuesChanged += It.IsAny <EventHandler <IssuesStore.IssuesChangedEventArgs> >(), Times.Once);
            }
        }
Ejemplo n.º 2
0
        public void MefCtor_CheckExports()
        {
            var batch = new CompositionBatch();

            batch.AddExport(MefTestHelpers.CreateExport <IIssueLocationStore>(Mock.Of <IIssueLocationStore>()));
            batch.AddExport(MefTestHelpers.CreateExport <IIssueLocationStore>(Mock.Of <IIssueLocationStore>()));
            batch.AddExport(MefTestHelpers.CreateExport <IIssueLocationStore>(Mock.Of <IIssueLocationStore>()));

            var issueLocationStoreAggregatorImporter = new SingleObjectImporter <IIssueLocationStoreAggregator>();

            batch.AddPart(issueLocationStoreAggregatorImporter);

            using var catalog   = new TypeCatalog(typeof(IssueLocationStoreAggregator));
            using var container = new CompositionContainer(catalog);
            container.Compose(batch);

            issueLocationStoreAggregatorImporter.Import.Should().NotBeNull();
        }
        public void MefCtor_CheckExports()
        {
            var batch = new CompositionBatch();

            var storeImport       = new SingleObjectImporter <IHotspotsStore>();
            var issuesStoreImport = new SingleObjectImporter <IIssuesStore>();

            batch.AddPart(storeImport);
            batch.AddPart(issuesStoreImport);

            var catalog = new TypeCatalog(typeof(HotspotsStore));

            using var container = new CompositionContainer(catalog);
            container.Compose(batch);

            storeImport.Import.Should().NotBeNull();
            issuesStoreImport.Import.Should().NotBeNull();

            storeImport.Import.Should().BeSameAs(issuesStoreImport.Import);
        }
        public void MefCtor_CheckExports()
        {
            CompositionBatch batch = new CompositionBatch();

            // Set up the exports required by the test subject
            var fileRenamesEventSourceExport = MefTestHelpers.CreateExport <IFileRenamesEventSource>(Mock.Of <IFileRenamesEventSource>());

            batch.AddExport(fileRenamesEventSourceExport);

            var tableManagerExport = MefTestHelpers.CreateExport <ITableManagerProvider>(mockTableManagerProvider.Object);

            batch.AddExport(tableManagerExport);

            var selectionServiceExport = MefTestHelpers.CreateExport <IIssueSelectionService>(Mock.Of <IIssueSelectionService>());

            batch.AddExport(selectionServiceExport);

            // Set up importers for each of the interfaces exported by the test subject
            var errorDataSourceImporter    = new SingleObjectImporter <ISonarErrorListDataSource>();
            var issueLocationStoreImporter = new SingleObjectImporter <IIssueLocationStore>();

            batch.AddPart(errorDataSourceImporter);
            batch.AddPart(issueLocationStoreImporter);

            // Specify the source types that can be used to satify any import requests
            TypeCatalog catalog = new TypeCatalog(typeof(SonarErrorListDataSource));

            using (CompositionContainer container = new CompositionContainer(catalog))
            {
                container.Compose(batch);

                // Both imports should be satisfied...
                errorDataSourceImporter.Import.Should().NotBeNull();
                issueLocationStoreImporter.Import.Should().NotBeNull();

                // ... and the the export should be a singleton, so the both importers should
                // get the same instance
                errorDataSourceImporter.Import.Should().BeSameAs(issueLocationStoreImporter.Import);
            }
        }