/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Testing/TestDiscoverer.DiscoveryHandler.cs
75 строк
3 KB
Cyrus Najmabadi
Make sealed
26 мар 2025, 22:21
26 мар 2025, 22:21
d99b771
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Collections.Concurrent; using System.Collections.Immutable; using Microsoft.CodeAnalysis.LanguageServer.Handler; using Microsoft.CodeAnalysis.LanguageServer.Handler.Testing; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; namespace Microsoft.CodeAnalysis.LanguageServer.Testing; internal sealed partial class TestDiscoverer { /// <summary> /// Implementation of <see cref="ITestDiscoveryEventsHandler"/> /// Calls to implementation methods will be synchronous. /// </summary> private sealed class DiscoveryHandler(BufferedProgress<RunTestsPartialResult> progress) : ITestDiscoveryEventsHandler { private readonly BufferedProgress<RunTestsPartialResult> _progress = progress; private readonly ConcurrentBag<TestCase> _testCases = []; private bool _isComplete; private bool _isAborted; public void HandleDiscoveredTests(IEnumerable<TestCase>? discoveredTestCases) => AddTests(discoveredTestCases); public void HandleDiscoveryComplete(long totalTests, IEnumerable<TestCase>? lastChunk, bool isAborted) { AddTests(lastChunk); _isComplete = true; _isAborted = isAborted; } public void HandleLogMessage(TestMessageLevel level, string? message) { if (message != null) { _progress.Report(new RunTestsPartialResult(LanguageServerResources.Discovering_tests, message, Progress: null)); } } public void HandleRawMessage(string rawMessage) { // No need to do anything with raw messages. return; } public ImmutableArray<TestCase> GetTestCases() { Contract.ThrowIfFalse(_isComplete, "Tried to get test cases before discovery completed"); return [.. _testCases]; } public bool IsAborted() { Contract.ThrowIfFalse(_isComplete, "Tried to get discovery status before completion"); return _isAborted; } private void AddTests(IEnumerable<TestCase>? testCases) { if (testCases != null) { foreach (var test in testCases) { _testCases.Add(test); } } } } }