Exemple #1
0
            public void PrioritizeVisibleLines()
            {
                CreateWithView("dog", "cat", "dog", "bear");
                _mockFactory.SetVisibleLineRange(_mockTextView, _textBuffer.GetLineRange(2));
                _asyncTagger.GetTags(_textBuffer.GetLineRange(0).Extent);
                _asyncTagger.AsyncBackgroundRequestData.Value.Task.Wait();

                // The visible lines will finish first and post.  Let only this one go through
                TestableSynchronizationContext.RunOne();
                var tags = _asyncTagger.GetTags(_textBuffer.GetExtent());

                Assert.Equal(
                    new[] { _textBuffer.GetLineSpan(2, 3) },
                    tags.Select(x => x.Span));
            }
Exemple #2
0
 public EditorHostTest()
 {
     try
     {
         _editorHost = GetOrCreateEditorHost();
     }
     catch (ReflectionTypeLoadException e)
     {
         // When this fails in AppVeyor the error message is useless.  Need to construct a more actionable
         // error message here.
         var builder = new StringBuilder();
         builder.AppendLine(e.Message);
         foreach (var item in e.LoaderExceptions)
         {
             builder.AppendLine(item.Message);
         }
         throw new Exception(builder.ToString(), e);
     }
     _synchronizationContext = new TestableSynchronizationContext();
     _synchronizationContext.Install();
 }
Exemple #3
0
            public void BackgroundCompleted()
            {
                Create("dog", "cat", "fish", "dog");
                _asyncTaggerSource.SetBackgroundFunc(span => TestUtils.GetDogTags(span));
                _asyncTagger.GetTags(_textBuffer.GetLineRange(0).Extent);
                _asyncTagger.AsyncBackgroundRequestData.Value.Task.Wait();

                // The background request is now complete and it's posted to the UI thread.  Create a
                // new request on a new snapshot.  This will supercede the existing request
                _textBuffer.Replace(new Span(0, 0), "big ");
                _asyncTagger.GetTags(_textBuffer.GetLineRange(0).Extent);
                Assert.True(_asyncTagger.AsyncBackgroundRequestData.HasValue);
                var tokenSource = _asyncTagger.AsyncBackgroundRequestData.Value.CancellationTokenSource;

                // The background will try to post twice (once for progress and the other for complete)
                for (int i = 0; i < 2; i++)
                {
                    TestableSynchronizationContext.RunOne();
                    Assert.True(_asyncTagger.AsyncBackgroundRequestData.HasValue);
                    Assert.Equal(tokenSource, _asyncTagger.AsyncBackgroundRequestData.Value.CancellationTokenSource);
                }
            }
Exemple #4
0
            public void GetTags()
            {
                Create("dog", "cat", "fish", "dog");
                _asyncTaggerSource.SetBackgroundFunc(span => TestUtils.GetDogTags(span));
                _asyncTagger.GetTags(_textBuffer.GetLineRange(0).Extent);
                Assert.True(_asyncTagger.AsyncBackgroundRequestData.HasValue);

                // Background is done.  Because we control the synchronization context though the foreground
                // thread still sees it as active and hence will continue to queue data on it
                _asyncTagger.AsyncBackgroundRequestData.Value.Task.Wait();
                Assert.True(_asyncTagger.AsyncBackgroundRequestData.HasValue);
                _asyncTagger.GetTags(_textBuffer.GetLineRange(3).Extent);

                // Clear the queue, the missing work will be seen and immedieatly requeued
                TestableSynchronizationContext.RunAll();
                Assert.True(_asyncTagger.AsyncBackgroundRequestData.HasValue);
                WaitForBackgroundToComplete();

                var tags = _asyncTagger.GetTags(_textBuffer.GetExtent());

                Assert.Equal(
                    new[] { _textBuffer.GetLineSpan(0, 3), _textBuffer.GetLineSpan(3, 3) },
                    tags.Select(x => x.Span));
            }
Exemple #5
0
 public EditorHostTest()
 {
     _editorHost             = GetOrCreateEditorHost();
     _synchronizationContext = new TestableSynchronizationContext();
     _synchronizationContext.Install();
 }
Exemple #6
0
 internal static void WaitForBackgroundToComplete <TData, TTag>(this AsyncTagger <TData, TTag> asyncTagger, TestableSynchronizationContext synchronizationContext)
     where TTag : ITag
 {
     while (asyncTagger.AsyncBackgroundRequestData.HasValue)
     {
         synchronizationContext.RunAll();
         Thread.Yield();
     }
 }
Exemple #7
0
 public TaggerCommonTest()
 {
     _synchronizationContext = new TestableSynchronizationContext();
     _synchronizationContext.Install();
 }