Skip to content

Commit

Permalink
Add test to ensure that a CompletionService can be acquired
Browse files Browse the repository at this point in the history
Issue dotnet#11841 found that, due to a MEF bug, the Features assemblies could not properly be included in a MEF composition. This was worked around by combining [ExtensionOrder] attributes where multiple attributes had been specified. This change adds a tests for C# and VB to ensure that a CompletionService can be acquired from an AdhocWorkspace that is created with MefHostServices that include the Features assemblies.

I verified that these tests fail without the workaound described above, and pass with the workaround in place.
  • Loading branch information
DustinCampbell committed Jun 24, 2016
1 parent 76aef21 commit 649f22c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<Compile Include="CodeActions\InvertIf\InvertIfTests.cs" />
<Compile Include="CodeActions\LambdaSimplifier\LambdaSimplifierTests.cs" />
<Compile Include="CodeActions\ReplacePropertyWithMethods\ReplacePropertyWithMethodsTests.cs" />
<Compile Include="Completion\CompletionServiceTests.cs" />
<Compile Include="Diagnostics\AddUsing\AddUsingTests_NuGet.cs" />
<Compile Include="Diagnostics\GenerateMethod\GenerateConversionTests.cs" />
<Compile Include="Diagnostics\MakeMethodSynchronous\MakeMethodSynchronousTests.cs" />
Expand Down
35 changes: 35 additions & 0 deletions src/EditorFeatures/CSharpTest/Completion/CompletionServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Linq;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp.Completion;
using Microsoft.CodeAnalysis.Host.Mef;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion
{
public class CompletionServiceTests
{
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public void AcquireCompletionService()
{
var hostServices = MefHostServices.Create(
MefHostServices.DefaultAssemblies.Concat(
new[]
{
typeof(CompletionService).Assembly,
typeof(CSharpCompletionService).Assembly
}));

var workspace = new AdhocWorkspace(hostServices);

var document = workspace
.AddProject("TestProject", LanguageNames.CSharp)
.AddDocument("TestDocument.cs", "");

var service = CompletionService.GetService(document);
Assert.NotNull(service);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<Compile Include="CodeActions\InvertIf\InvertIfTests.vb" />
<Compile Include="CodeActions\Preview\PreviewTests.vb" />
<Compile Include="CodeActions\ReplacePropertyWithMethods\ReplacePropertyWithMethodsTests.vb" />
<Compile Include="Completion\CompletionServiceTests.vb" />
<Compile Include="Diagnostics\AddImport\AddImportTests_NuGet.vb" />
<Compile Include="Diagnostics\ImplementAbstractClass\ImplementAbstractClassTests_FixAllTests.vb" />
<Compile Include="Diagnostics\ImplementInterface\ImplementInterfaceTests_FixAllTests.vb" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

Imports Microsoft.CodeAnalysis.Completion
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.VisualBasic.Completion

Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Completion
Public Class CompletionServiceTests
<Fact, Trait(Traits.Feature, Traits.Features.Completion)>
Public Sub AcquireCompletionService()
Dim hostServices = MefHostServices.Create(
MefHostServices.DefaultAssemblies.Concat({
GetType(CompletionService).Assembly,
GetType(VisualBasicCompletionService).Assembly}))

Dim workspace = New AdhocWorkspace(hostServices)

Dim document = workspace _
.AddProject("TestProject", LanguageNames.VisualBasic) _
.AddDocument("TestDocument.vb", String.Empty)

Dim service = CompletionService.GetService(document)
Assert.NotNull(service)
End Sub
End Class
End Namespace

0 comments on commit 649f22c

Please sign in to comment.