public async Task ReturnsSourceFileFromSourceLink() { var source = @" public class C { public event System.EventHandler [|E|] { add { } remove { } } }"; await RunTestAsync(async path => { MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan); var(project, symbol) = await CompileAndFindSymbolAsync(path, Location.OnDisk, Location.OnDisk, metadataSource, c => c.GetMember("C.E")); // Move the source file to a path that only our fake debugger service knows about var sourceFilePath = Path.Combine(path, "SourceLink.cs"); File.Move(GetSourceFilePath(path), sourceFilePath); var sourceLinkService = new Lazy <ISourceLinkService?>(() => new TestSourceLinkService(sourceFilePath: sourceFilePath)); var service = new PdbSourceDocumentLoaderService(sourceLinkService, logger: null); using var hash = SHA256.Create(); var fileHash = hash.ComputeHash(File.ReadAllBytes(sourceFilePath)); var sourceDocument = new SourceDocument("goo.cs", Text.SourceHashAlgorithm.Sha256, fileHash.ToImmutableArray(), null, "https://sourcelink"); var result = await service.LoadSourceDocumentAsync(path, sourceDocument, Encoding.UTF8, new TelemetryMessage(CancellationToken.None), CancellationToken.None); Assert.NotNull(result); Assert.Equal(sourceFilePath, result !.FilePath); }); }
public async Task NoUrlFoundReturnsNull() { var source = @" public class C { public event System.EventHandler [|E|] { add { } remove { } } }"; await RunTestAsync(async path => { MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan); var(project, symbol) = await CompileAndFindSymbolAsync(path, Location.OnDisk, Location.OnDisk, metadataSource, c => c.GetMember("C.E")); // Move the source file to a path that only our fake debugger service knows about var sourceFilePath = Path.Combine(path, "SourceLink.cs"); File.Move(GetSourceFilePath(path), sourceFilePath); var sourceLinkService = new Lazy <ISourceLinkService?>(() => new TestSourceLinkService(sourceFilePath: sourceFilePath)); var service = new PdbSourceDocumentLoaderService(sourceLinkService, logger: null); var sourceDocument = new SourceDocument("goo.cs", Text.SourceHashAlgorithm.None, default, null, SourceLinkUrl: null);