Skip to content

Commit

Permalink
Dispose of VisualStudioAnalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
Pilchie committed Jul 19, 2017
1 parent d8c72ac commit c65ce85
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,45 @@ public async Task TestUnresolvedAnalyzerReference()
var workspace = new AdhocWorkspace();
var project = workspace.CurrentSolution.AddProject("empty", "empty", LanguageNames.CSharp);
var mockFileChangeService = new Mock<IVsFileChangeEx>();
var analyzer = new VisualStudioAnalyzer(
using (var analyzer = new VisualStudioAnalyzer(
@"PathToAnalyzer",
fileChangeService: mockFileChangeService.Object,
hostDiagnosticUpdateSource: null,
projectId: project.Id,
workspace: workspace,
loader: null,
language: project.Language);
var analyzerReference = analyzer.GetReference();
project = project.WithAnalyzerReferences(new AnalyzerReference[]
language: project.Language))
{
var analyzerReference = analyzer.GetReference();
project = project.WithAnalyzerReferences(new AnalyzerReference[]
{
analyzerReference,
});

var checksum = await project.State.GetChecksumAsync(CancellationToken.None).ConfigureAwait(false);
Assert.NotNull(checksum);
});

var assetBuilder = new CustomAssetBuilder(workspace);
var serializer = new Serializer(workspace);
var checksum = await project.State.GetChecksumAsync(CancellationToken.None).ConfigureAwait(false);
Assert.NotNull(checksum);

var asset = assetBuilder.Build(analyzerReference, CancellationToken.None);
var assetBuilder = new CustomAssetBuilder(workspace);
var serializer = new Serializer(workspace);

using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new ObjectWriter(stream))
{
await asset.WriteObjectToAsync(writer, CancellationToken.None).ConfigureAwait(false);
var asset = assetBuilder.Build(analyzerReference, CancellationToken.None);

stream.Position = 0;
using (var reader = ObjectReader.TryGetReader(stream))
using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new ObjectWriter(stream))
{
var recovered = serializer.Deserialize<AnalyzerReference>(asset.Kind, reader, CancellationToken.None);
var assetFromStorage = assetBuilder.Build(recovered, CancellationToken.None);
await asset.WriteObjectToAsync(writer, CancellationToken.None).ConfigureAwait(false);

stream.Position = 0;
using (var reader = ObjectReader.TryGetReader(stream))
{
var recovered = serializer.Deserialize<AnalyzerReference>(asset.Kind, reader, CancellationToken.None);
var assetFromStorage = assetBuilder.Build(recovered, CancellationToken.None);

Assert.Equal(asset.Checksum, assetFromStorage.Checksum);
Assert.Equal(asset.Checksum, assetFromStorage.Checksum);

// This won't round trip, but we should get an UnresolvedAnalyzerReference, with the same path
Assert.Equal(analyzerReference.FullPath, recovered.FullPath);
// This won't round trip, but we should get an UnresolvedAnalyzerReference, with the same path
Assert.Equal(analyzerReference.FullPath, recovered.FullPath);
}
}
}
}
Expand Down

0 comments on commit c65ce85

Please sign in to comment.