Skip to content

Commit 75a501c

Browse files
committed
Update tests to access the original source text
1 parent d2335c2 commit 75a501c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/EditorFeatures/CSharpTest/PdbSourceDocument/AbstractPdbSourceDocumentTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ protected static async Task GenerateFileAndVerifyAsync(
155155

156156
var masWorkspace = service.TryGetWorkspace();
157157

158+
using var fileStream = File.OpenRead(file.FilePath);
159+
var sourceText = SourceText.From(fileStream);
160+
var text = SourceText.From(File.ReadAllText(file.FilePath));
161+
162+
var pdbService = (PdbSourceDocumentMetadataAsSourceFileProvider)workspace.ExportProvider.GetExportedValues<IMetadataAsSourceFileProvider>().Single(s => s is PdbSourceDocumentMetadataAsSourceFileProvider);
163+
164+
var documentInfo = pdbService.GetTestAccessor().Documents[file.FilePath];
165+
masWorkspace!.OnDocumentAdded(documentInfo.DocumentInfo);
158166
var document = masWorkspace!.CurrentSolution.Projects.First().Documents.First(d => d.FilePath == file.FilePath);
159167

160168
// Mapping the project from the generated document should map back to the original project
@@ -330,4 +338,15 @@ protected static string GetPdbPath(string path)
330338
{
331339
return Path.Combine(path, "reference.pdb");
332340
}
341+
342+
private class StaticSourceTextContainer(SourceText sourceText) : SourceTextContainer
343+
{
344+
public override SourceText CurrentText => sourceText;
345+
346+
public override event EventHandler<TextChangeEventArgs> TextChanged
347+
{
348+
add { }
349+
remove { }
350+
}
351+
}
333352
}

src/Features/Core/Portable/PdbSourceDocument/PdbSourceDocumentMetadataAsSourceFileProvider.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,23 @@ public void CleanupGeneratedFiles(MetadataAsSourceWorkspace workspace)
429429
_sourceLinkEnabledProjects.Clear();
430430
_implementationAssemblyLookupService.Clear();
431431
}
432+
433+
internal TestAccessor GetTestAccessor()
434+
{
435+
return new TestAccessor(this);
436+
}
437+
438+
internal readonly struct TestAccessor
439+
{
440+
private readonly PdbSourceDocumentMetadataAsSourceFileProvider _instance;
441+
442+
internal TestAccessor(PdbSourceDocumentMetadataAsSourceFileProvider instance)
443+
{
444+
_instance = instance;
445+
}
446+
447+
public ImmutableDictionary<string, SourceDocumentInfo> Documents => _instance._fileToDocumentInfoMap.ToImmutableDictionary();
448+
}
432449
}
433450

434451
internal sealed record SourceDocument(string FilePath, SourceHashAlgorithm ChecksumAlgorithm, ImmutableArray<byte> Checksum, byte[]? EmbeddedTextBytes, string? SourceLinkUrl);

0 commit comments

Comments
 (0)