本文整理汇总了C#中Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace类的典型用法代码示例。如果您正苦于以下问题:C# TestWorkspace类的具体用法?C# TestWorkspace怎么用?C# TestWorkspace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestWorkspace类属于Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces命名空间,在下文中一共展示了TestWorkspace类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetErrorsFromUpdateSource
internal static IList<ITagSpan<IErrorTag>> GetErrorsFromUpdateSource(TestWorkspace workspace, TestHostDocument document, DiagnosticsUpdatedArgs updateArgs)
{
var source = new TestDiagnosticUpdateSource();
var diagnosticWaiter = new DiagnosticServiceWaiter();
var diagnosticListeners = SpecializedCollections.SingletonEnumerable(new Lazy<IAsynchronousOperationListener, FeatureMetadata>(
() => diagnosticWaiter, new FeatureMetadata(new Dictionary<string, object>() { { "FeatureName", FeatureAttribute.DiagnosticService } })));
var optionsService = workspace.Services.GetService<IOptionService>();
var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable<IDiagnosticUpdateSource>(source), diagnosticListeners);
var squiggleWaiter = new ErrorSquiggleWaiter();
var foregroundService = new TestForegroundNotificationService();
var buffer = document.GetTextBuffer();
var taggerSource = new DiagnosticsSquiggleTaggerProvider.TagSource(buffer, foregroundService, diagnosticService, optionsService, squiggleWaiter);
source.RaiseDiagnosticsUpdated(updateArgs);
diagnosticWaiter.CreateWaitTask().PumpingWait();
squiggleWaiter.CreateWaitTask().PumpingWait();
var snapshot = buffer.CurrentSnapshot;
var intervalTree = taggerSource.GetTagIntervalTreeForBuffer(buffer);
var spans = intervalTree.GetIntersectingSpans(new SnapshotSpan(snapshot, 0, snapshot.Length));
taggerSource.TestOnly_Dispose();
return spans;
}
开发者ID:GloryChou,项目名称:roslyn,代码行数:30,代码来源:AbstractSquiggleProducerTests.cs
示例2: GetErrorsFromUpdateSource
internal static IList<ITagSpan<IErrorTag>> GetErrorsFromUpdateSource(TestWorkspace workspace, TestHostDocument document, DiagnosticsUpdatedArgs updateArgs)
{
var source = new TestDiagnosticUpdateSource();
var listener = new AsynchronousOperationListener();
var listeners = AsynchronousOperationListener.CreateListeners(
ValueTuple.Create(FeatureAttribute.DiagnosticService, listener),
ValueTuple.Create(FeatureAttribute.ErrorSquiggles, listener));
var optionsService = workspace.Services.GetService<IOptionService>();
var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable<IDiagnosticUpdateSource>(source), listeners);
var foregroundService = workspace.GetService<IForegroundNotificationService>(); //new TestForegroundNotificationService();
var buffer = document.GetTextBuffer();
var provider = new DiagnosticsSquiggleTaggerProvider(optionsService, diagnosticService, foregroundService, listeners);
var tagger = provider.CreateTagger<IErrorTag>(buffer);
source.RaiseDiagnosticsUpdated(updateArgs);
listener.CreateWaitTask().PumpingWait();
var snapshot = buffer.CurrentSnapshot;
var spans = tagger.GetTags(new NormalizedSnapshotSpanCollection(new SnapshotSpan(snapshot, 0, snapshot.Length))).ToImmutableArray();
((IDisposable)tagger).Dispose();
return spans;
}
开发者ID:nevinclement,项目名称:roslyn,代码行数:29,代码来源:AbstractSquiggleProducerTests.cs
示例3: DiagnosticTaggerWrapper
private DiagnosticTaggerWrapper(TestWorkspace workspace, DiagnosticAnalyzerService analyzerService, IDiagnosticUpdateSource updateSource)
{
if (updateSource == null)
{
updateSource = analyzerService;
}
this.workspace = workspace;
this.registrationService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>();
registrationService.Register(workspace);
this.asyncListener = new AsynchronousOperationListener();
var listeners = AsynchronousOperationListener.CreateListeners(
ValueTuple.Create(FeatureAttribute.DiagnosticService, asyncListener),
ValueTuple.Create(FeatureAttribute.ErrorSquiggles, asyncListener));
this.analyzerService = analyzerService;
var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable(updateSource), listeners);
this.TaggerProvider = new DiagnosticsSquiggleTaggerProvider(
workspace.Services.GetService<IOptionService>(), diagnosticService,
workspace.GetService<IForegroundNotificationService>(), listeners);
if (analyzerService != null)
{
this.incrementalAnalyzers = ImmutableArray.Create(analyzerService.CreateIncrementalAnalyzer(workspace));
this.solutionCrawlerService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService;
}
}
开发者ID:noahfalk,项目名称:roslyn,代码行数:30,代码来源:DiagnosticsSquiggleTaggerProviderTests.cs
示例4: TestActionsOnLinkedFiles
protected async Task TestActionsOnLinkedFiles(
TestWorkspace workspace,
string expectedText,
int index,
IList<CodeAction> actions,
string expectedPreviewContents = null,
bool compareTokens = true)
{
var operations = await VerifyInputsAndGetOperationsAsync(index, actions);
await VerifyPreviewContents(workspace, expectedPreviewContents, operations);
var applyChangesOperation = operations.OfType<ApplyChangesOperation>().First();
applyChangesOperation.Apply(workspace, new ProgressTracker(), CancellationToken.None);
foreach (var document in workspace.Documents)
{
var fixedRoot = await workspace.CurrentSolution.GetDocument(document.Id).GetSyntaxRootAsync();
var actualText = compareTokens ? fixedRoot.ToString() : fixedRoot.ToFullString();
if (compareTokens)
{
TokenUtilities.AssertTokensEqual(expectedText, actualText, GetLanguage());
}
else
{
Assert.Equal(expectedText, actualText);
}
}
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:30,代码来源:AbstractCodeActionTest.cs
示例5: GetDiagnosticAndFixesAsync
internal override async Task<IEnumerable<Tuple<Diagnostic, CodeFixCollection>>> GetDiagnosticAndFixesAsync(
TestWorkspace workspace, string fixAllActionId, object fixProviderData)
{
var providerAndFixer = GetOrCreateDiagnosticProviderAndFixer(workspace, fixProviderData);
var provider = providerAndFixer.Item1;
Document document;
TextSpan span;
string annotation = null;
if (!TryGetDocumentAndSelectSpan(workspace, out document, out span))
{
document = GetDocumentAndAnnotatedSpan(workspace, out annotation, out span);
}
using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider))
{
var diagnostics = await testDriver.GetAllDiagnosticsAsync(provider, document, span);
AssertNoAnalyzerExceptionDiagnostics(diagnostics);
var fixer = providerAndFixer.Item2;
var ids = new HashSet<string>(fixer.FixableDiagnosticIds);
var dxs = diagnostics.Where(d => ids.Contains(d.Id)).ToList();
return await GetDiagnosticAndFixesAsync(dxs, provider, fixer, testDriver, document, span, annotation, fixAllActionId);
}
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:25,代码来源:AbstractDiagnosticProviderBasedUserDiagnosticTest.cs
示例6: AdornmentManagerTester
public AdornmentManagerTester()
{
_subjectBuffer = EditorFactory.CreateBuffer(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, "Hi There");
_textView = new Mock<IWpfTextView>();
var aggregatorService = new Mock<IViewTagAggregatorFactoryService>();
_adornmentLayer = new Mock<IAdornmentLayer>();
_aggregator = new Mock<ITagAggregator<Tag>>();
var layerName = "LayerName";
_textView.Setup(tv => tv.GetAdornmentLayer(layerName)).Returns(_adornmentLayer.Object);
_textView.SetupGet(tv => tv.VisualElement).Returns(new FrameworkElement());
aggregatorService.Setup(a => a.CreateTagAggregator<Tag>(_textView.Object)).Returns(_aggregator.Object);
var textViewModel = new Mock<ITextViewModel>();
textViewModel.Setup(tvm => tvm.VisualBuffer).Returns(_subjectBuffer);
_textView.Setup(tv => tv.TextViewModel).Returns(textViewModel.Object);
var workspace = new TestWorkspace();
var listener = new AggregateAsynchronousOperationListener(
Enumerable.Empty<Lazy<IAsynchronousOperationListener, FeatureMetadata>>(),
FeatureAttribute.LineSeparators);
Manager = AdornmentManager<Tag>.Create(_textView.Object,
aggregatorService.Object,
listener,
adornmentLayerName: layerName);
}
开发者ID:natidea,项目名称:roslyn,代码行数:30,代码来源:AdornmentManagerTests.cs
示例7: TestGetDiagnostics1
public void TestGetDiagnostics1()
{
using (var workspace = new TestWorkspace(TestExportProvider.ExportProviderWithCSharpAndVisualBasic))
{
var set = new ManualResetEvent(false);
var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", string.Empty);
var source = new TestDiagnosticUpdateSource(false, null);
var diagnosticService = new DiagnosticService(AggregateAsynchronousOperationListener.EmptyListeners);
diagnosticService.Register(source);
diagnosticService.DiagnosticsUpdated += (s, o) => { set.Set(); };
var id = Tuple.Create(workspace, document);
var diagnostic = RaiseDiagnosticEvent(set, source, workspace, document.Project.Id, document.Id, id);
var data1 = diagnosticService.GetDiagnostics(workspace, null, null, null, false, CancellationToken.None);
Assert.Equal(diagnostic, data1.Single());
var data2 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, null, null, false, CancellationToken.None);
Assert.Equal(diagnostic, data2.Single());
var data3 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, document.Id, null, false, CancellationToken.None);
Assert.Equal(diagnostic, data3.Single());
var data4 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, document.Id, id, false, CancellationToken.None);
Assert.Equal(diagnostic, data4.Single());
}
}
开发者ID:uwe-baumann,项目名称:roslyn,代码行数:29,代码来源:DiagnosticServiceTests.cs
示例8: WaitForWorkspaceOperationsToComplete
private static void WaitForWorkspaceOperationsToComplete(TestWorkspace workspace)
{
var workspasceWaiter = workspace.ExportProvider
.GetExports<IAsynchronousOperationListener, FeatureMetadata>()
.First(l => l.Metadata.FeatureName == FeatureAttribute.Workspace).Value as IAsynchronousOperationWaiter;
workspasceWaiter.CreateWaitTask().PumpingWait();
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:7,代码来源:WorkspaceTests.cs
示例9: GetDiagnosticAndFixesAsync
internal override async Task<IEnumerable<Tuple<Diagnostic, CodeFixCollection>>> GetDiagnosticAndFixesAsync(
TestWorkspace workspace, string fixAllActionId, object fixProviderData)
{
var providerAndFixer = CreateDiagnosticProviderAndFixer(workspace);
var provider = providerAndFixer.Item1;
Document document;
TextSpan span;
string annotation = null;
if (!TryGetDocumentAndSelectSpan(workspace, out document, out span))
{
document = GetDocumentAndAnnotatedSpan(workspace, out annotation, out span);
}
using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider, includeSuppressedDiagnostics: IncludeSuppressedDiagnostics))
{
var fixer = providerAndFixer.Item2;
var diagnostics = (await testDriver.GetAllDiagnosticsAsync(provider, document, span))
.Where(d => fixer.CanBeSuppressedOrUnsuppressed(d));
var filteredDiagnostics = FilterDiagnostics(diagnostics);
var wrapperCodeFixer = new WrapperCodeFixProvider(fixer, filteredDiagnostics.Select(d => d.Id));
return await GetDiagnosticAndFixesAsync(filteredDiagnostics, provider, wrapperCodeFixer, testDriver, document, span, annotation, fixAllActionId);
}
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:26,代码来源:AbstractSuppressionDiagnosticTest.cs
示例10: DiagnosticTaggerWrapper
public DiagnosticTaggerWrapper(
TestWorkspace workspace,
IDiagnosticUpdateSource updateSource,
bool createTaggerProvider = true)
: this(workspace, null, updateSource, createTaggerProvider)
{
}
开发者ID:nbsoftwarecsjava,项目名称:roslyn,代码行数:7,代码来源:DiagnosticsSquiggleTaggerProviderTests.cs
示例11: GetDiagnosticAndFixes
internal override IEnumerable<Tuple<Diagnostic, CodeFixCollection>> GetDiagnosticAndFixes(TestWorkspace workspace, string fixAllActionId)
{
var providerAndFixer = CreateDiagnosticProviderAndFixer(workspace);
var provider = providerAndFixer.Item1;
Document document;
TextSpan span;
string annotation = null;
if (!TryGetDocumentAndSelectSpan(workspace, out document, out span))
{
document = GetDocumentAndAnnotatedSpan(workspace, out annotation, out span);
}
using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider, includeSuppressedDiagnostics: IncludeSuppressedDiagnostics))
{
var fixer = providerAndFixer.Item2;
var diagnostics = testDriver.GetAllDiagnostics(provider, document, span)
.Where(d => fixer.CanBeSuppressedOrUnsuppressed(d))
.ToImmutableArray();
if (!IncludeUnsuppressedDiagnostics)
{
diagnostics = diagnostics.WhereAsArray(d => d.IsSuppressed);
}
var wrapperCodeFixer = new WrapperCodeFixProvider(fixer, diagnostics);
return GetDiagnosticAndFixes(diagnostics, provider, wrapperCodeFixer, testDriver, document, span, annotation, fixAllActionId);
}
}
开发者ID:nemec,项目名称:roslyn,代码行数:29,代码来源:AbstractSuppressionDiagnosticTest.cs
示例12: WaitForWorkspaceOperationsToComplete
private static async Task WaitForWorkspaceOperationsToComplete(TestWorkspace workspace)
{
var workspaceWaiter = workspace.ExportProvider
.GetExports<IAsynchronousOperationListener, FeatureMetadata>()
.First(l => l.Metadata.FeatureName == FeatureAttribute.Workspace).Value as IAsynchronousOperationWaiter;
await workspaceWaiter.CreateWaitTask().ConfigureAwait(true);
}
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:7,代码来源:WorkspaceTests.cs
示例13: TestWithOptionsAsync
private async Task TestWithOptionsAsync(TestWorkspace workspace, params Action<object>[] expectedResults)
{
var testDocument = workspace.DocumentWithCursor;
var position = testDocument.CursorPosition.GetValueOrDefault();
var documentId = workspace.GetDocumentId(testDocument);
var document = workspace.CurrentSolution.GetDocument(documentId);
var provider = new SemanticQuickInfoProvider(
workspace.GetService<IProjectionBufferFactoryService>(),
workspace.GetService<IEditorOptionsFactoryService>(),
workspace.GetService<ITextEditorFactoryService>(),
workspace.GetService<IGlyphService>(),
workspace.GetService<ClassificationTypeMap>());
await TestWithOptionsAsync(document, provider, position, expectedResults);
// speculative semantic model
if (await CanUseSpeculativeSemanticModelAsync(document, position))
{
var buffer = testDocument.TextBuffer;
using (var edit = buffer.CreateEdit())
{
var currentSnapshot = buffer.CurrentSnapshot;
edit.Replace(0, currentSnapshot.Length, currentSnapshot.GetText());
edit.Apply();
}
await TestWithOptionsAsync(document, provider, position, expectedResults);
}
}
开发者ID:jkotas,项目名称:roslyn,代码行数:30,代码来源:SemanticQuickInfoSourceTests.cs
示例14: AssertNoContent
protected override void AssertNoContent(
TestWorkspace workspace,
Document document,
int position)
{
var provider = CreateProvider(workspace);
Assert.Null(provider.GetItemAsync(document, position, CancellationToken.None).Result);
}
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:8,代码来源:SyntacticQuickInfoSourceTests.cs
示例15: GetDocumentAndAnnotatedSpan
protected Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, out string annotation, out TextSpan span)
{
var hostDocument = workspace.Documents.Single(d => d.AnnotatedSpans.Any());
var annotatedSpan = hostDocument.AnnotatedSpans.Single();
annotation = annotatedSpan.Key;
span = annotatedSpan.Value.Single();
return workspace.CurrentSolution.GetDocument(hostDocument.Id);
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:8,代码来源:AbstractUserDiagnosticTest.cs
示例16: GetDiagnostics
internal override IEnumerable<Diagnostic> GetDiagnostics(TestWorkspace workspace)
{
var providerAndFixer = CreateDiagnosticProviderAndFixer(workspace);
var provider = providerAndFixer.Item1;
TextSpan span;
var document = GetDocumentAndSelectSpan(workspace, out span);
return DiagnosticProviderTestUtilities.GetAllDiagnostics(provider, document, span);
}
开发者ID:nemec,项目名称:roslyn,代码行数:9,代码来源:AbstractSuppressionDiagnosticTest.cs
示例17: AssertResetInteractive
private async void AssertResetInteractive(
TestWorkspace workspace,
Project project,
bool buildSucceeds,
List<string> expectedReferences = null,
List<string> expectedUsings = null)
{
expectedReferences = expectedReferences ?? new List<string>();
expectedUsings = expectedUsings ?? new List<string>();
InteractiveWindowTestHost testHost = new InteractiveWindowTestHost();
List<string> executedSubmissionCalls = new List<string>();
EventHandler<string> ExecuteSubmission = (_, code) => { executedSubmissionCalls.Add(code); };
testHost.Evaluator.OnExecute += ExecuteSubmission;
IWaitIndicator waitIndicator = workspace.GetService<IWaitIndicator>();
IEditorOptionsFactoryService editorOptionsFactoryService = workspace.GetService<IEditorOptionsFactoryService>();
var editorOptions = editorOptionsFactoryService.GetOptions(testHost.Window.CurrentLanguageBuffer);
var newLineCharacter = editorOptions.GetNewLineCharacter();
TestResetInteractive resetInteractive = new TestResetInteractive(
waitIndicator,
editorOptionsFactoryService,
CreateReplReferenceCommand,
CreateImport,
buildSucceeds: buildSucceeds)
{
References = ImmutableArray.CreateRange(GetProjectReferences(workspace, project)),
ReferenceSearchPaths = ImmutableArray.Create("rsp1", "rsp2"),
SourceSearchPaths = ImmutableArray.Create("ssp1", "ssp2"),
ProjectNamespaces = ImmutableArray.Create("System", "ResetInteractiveTestsDocument", "VisualBasicResetInteractiveTestsDocument"),
NamespacesToImport = ImmutableArray.Create("System", "ResetInteractiveTestsDocument"),
ProjectDirectory = "pj",
};
await resetInteractive.Execute(testHost.Window, "Interactive C#");
// Validate that the project was rebuilt.
Assert.Equal(1, resetInteractive.BuildProjectCount);
Assert.Equal(0, resetInteractive.CancelBuildProjectCount);
var expectedSubmissions = new List<string>();
if (expectedReferences.Any())
{
expectedSubmissions.AddRange(expectedReferences.Select(r => r + newLineCharacter));
}
if (expectedUsings.Any())
{
expectedSubmissions.Add(string.Join(newLineCharacter, expectedUsings) + newLineCharacter);
}
AssertEx.Equal(expectedSubmissions, executedSubmissionCalls);
testHost.Evaluator.OnExecute -= ExecuteSubmission;
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:56,代码来源:ResetInteractiveTests.cs
示例18: GetDiagnosticsAsync
internal override async Task<IEnumerable<Diagnostic>> GetDiagnosticsAsync(TestWorkspace workspace)
{
var providerAndFixer = CreateDiagnosticProviderAndFixer(workspace);
var provider = providerAndFixer.Item1;
TextSpan span;
var document = GetDocumentAndSelectSpan(workspace, out span);
var diagnostics = await DiagnosticProviderTestUtilities.GetAllDiagnosticsAsync(provider, document, span);
return FilterDiagnostics(diagnostics);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:10,代码来源:AbstractSuppressionDiagnosticTest.cs
示例19: SolutionAdded_Complex
public void SolutionAdded_Complex()
{
using (var workspace = new TestWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solution = GetInitialSolutionInfo(workspace);
var worker = ExecuteOperation(workspace, w => w.OnSolutionAdded(solution));
Assert.Equal(10, worker.SyntaxDocumentIds.Count);
}
}
开发者ID:nemec,项目名称:roslyn,代码行数:10,代码来源:WorkCoordinatorTests.cs
示例20: EncapsulateFieldTestState
public EncapsulateFieldTestState(TestWorkspace workspace)
{
Workspace = workspace;
_testDocument = Workspace.Documents.Single(d => d.CursorPosition.HasValue || d.SelectedSpans.Any());
TargetDocument = Workspace.CurrentSolution.GetDocument(_testDocument.Id);
var notificationService = Workspace.Services.GetService<INotificationService>() as INotificationServiceCallback;
var callback = new Action<string, string, NotificationSeverity>((message, title, severity) => NotificationMessage = message);
notificationService.NotificationCallback = callback;
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:10,代码来源:EncapsulateFieldTestState.cs
注:本文中的Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论