Exemplo n.º 1
0
        public void SupportsManyProviders()
        {
            var providerA         = MockFor <INavigateToItemProvider>();
            var itemFromProviderA = MockFor <INavigateToItem>();

            providerA.Setup(_ => _.Search("")).Returns(ObservableX.Return(itemFromProviderA.Object));

            var providerB         = MockFor <INavigateToItemProvider>();
            var itemFromProviderB = MockFor <INavigateToItem>();

            providerB.Setup(_ => _.Search("")).Returns(ObservableX.Return(itemFromProviderB.Object));

            var aggregator = new NavigateToItemProviderAggregator {
                Providers = new[] { providerA.Object, providerB.Object }
            };
            var aggregatorItems = aggregator.Search("").ToList().FirstOrDefault();

            CollectionAssert.AreEquivalent(new[] { itemFromProviderA.Object, itemFromProviderB.Object }, aggregatorItems);
        }
        public void IndexAllFilesAutomaticallyUponStartup()
        {
            var sourceFile             = MockFor <IFile>().Object;
            var sourceFileNotification = MockFor <IFileNotification>();

            sourceFileNotification
            .SetupGet(_ => _.File)
            .Returns(sourceFile);

            var sourceFilesProvider = MockFor <ISourceFilesProvider>();

            sourceFilesProvider
            .SetupGet(_ => _.SourceFiles)
            .Returns(ObservableX.Return(sourceFileNotification.Object));

            var providerSelector = MockFor <ISourceSymbolProviderSelector>();
            var parseWaitEvent   = new AutoResetEvent(false);
            var symbol           = MockFor <ISourceSymbol>();

            providerSelector
            .Setup(_ => _.SourceSymbolsFor(sourceFile))
            .Callback(() => parseWaitEvent.Set())
            .Returns(new[] { symbol.Object });

            var container = new CompositionContainer(typeof(ISourceSymbolIndexProvider).Assembly);

            container.AddExportedValue(sourceFilesProvider.Object);
            container.AddExportedValue(providerSelector.Object);
            container.AddExportedValue <ILogger>(new StandardLogger());

            var subject = container.GetExportedValue <ISourceSymbolIndexProvider>();

            Assert.IsNotNull(subject.Index);

            // TODO: replace by injecting immediate scheduler
            parseWaitEvent.WaitOne(TimeSpan.FromSeconds(1));

            VerifyAllMocks();
        }