From c65ce85ea66cd0ccc68323d22010478b3d2ae4f8 Mon Sep 17 00:00:00 2001 From: Kevin Pilch Date: Tue, 18 Jul 2017 17:30:27 -0700 Subject: [PATCH] Dispose of VisualStudioAnalyzer --- .../VisualStudioSnapshotSerializationTests.cs | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/VisualStudio/Core/Test.Next/Services/VisualStudioSnapshotSerializationTests.cs b/src/VisualStudio/Core/Test.Next/Services/VisualStudioSnapshotSerializationTests.cs index 1b7610eb8876f..430dd4d5c5e2d 100644 --- a/src/VisualStudio/Core/Test.Next/Services/VisualStudioSnapshotSerializationTests.cs +++ b/src/VisualStudio/Core/Test.Next/Services/VisualStudioSnapshotSerializationTests.cs @@ -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(); - 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(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(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); + } } } }