コード例 #1
0
        public async Task ProcessDocument_LongDocumentParse_DoesNotUpdateAfterSuppress()
        {
            // Arrange
            var projectManager = new TestProjectSnapshotManager(Dispatcher, Workspace);

            projectManager.ProjectAdded(HostProject1);

            // We utilize a task completion source here so we can "fake" a document parse taking a significant amount of time
            var tcs        = new TaskCompletionSource <TextAndVersion>();
            var textLoader = new Mock <TextLoader>(MockBehavior.Strict);

            textLoader.Setup(loader => loader.LoadTextAndVersionAsync(It.IsAny <Workspace>(), It.IsAny <DocumentId>(), It.IsAny <CancellationToken>()))
            .Returns(tcs.Task);
            var hostDocument = Documents[0];

            var project = projectManager.GetLoadedProject(HostProject1.FilePath);
            var queue   = new BackgroundDocumentGenerator(Dispatcher, DynamicFileInfoProvider)
            {
                Delay = TimeSpan.FromMilliseconds(1),
                NotifyBackgroundWorkCompleted    = new ManualResetEventSlim(initialState: false),
                NotifyBackgroundCapturedWorkload = new ManualResetEventSlim(initialState: false),
            };

            queue.Initialize(projectManager);

            // We trigger enqueued notifications via adding/opening to the project manager
            projectManager.AllowNotifyListeners = true;

            // Act & Assert
            projectManager.DocumentAdded(HostProject1, hostDocument, textLoader.Object);

            queue.NotifyBackgroundCapturedWorkload.Wait();

            projectManager.DocumentOpened(HostProject1.FilePath, hostDocument.FilePath, SourceText.From(string.Empty));

            // Verify document was suppressed because it was opened
            Assert.Null(DynamicFileInfoProvider.DynamicDocuments[hostDocument.FilePath]);

            // Unblock document processing
            tcs.SetResult(TextAndVersion.Create(SourceText.From(string.Empty), VersionStamp.Default));

            await Task.Run(() => queue.NotifyBackgroundWorkCompleted.Wait(TimeSpan.FromSeconds(3)));

            // Validate that even though document parsing took a significant amount of time that the dynamic document wasn't "unsuppressed"
            Assert.Null(DynamicFileInfoProvider.DynamicDocuments[hostDocument.FilePath]);
        }