Skip to content

Commit

Permalink
Don't require services from the VS layer that aren't present on VS Mac (
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier authored Feb 2, 2022
1 parent 14a604b commit 72f98f8
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Immutable;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.MoveStaticMembers;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities.MoveStaticMembers;
Expand Down Expand Up @@ -2566,16 +2567,32 @@ public class Class1
}
#endregion

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveStaticMembers)]
public async Task NoOptionsService_NoAction()
{
var initialMarkup = @"
namespace TestNs1
{
public class Class1
{
public static int TestField = 1;[||]
}
}";
await TestNoRefactoringAsync(initialMarkup, hostServices: FeaturesTestCompositions.Features.GetHostServices()).ConfigureAwait(false);
}

private class Test : VerifyCS.Test
{
public Test(
string destinationType,
ImmutableArray<string> selection,
string destinationName = "a.cs")
string destinationName = "a.cs",
HostServices? hostServices = null)
{
_destinationType = destinationType;
_selection = selection;
_destinationName = destinationName;
_hostServices = hostServices;
}

private readonly string _destinationType;
Expand All @@ -2584,15 +2601,20 @@ public Test(

private readonly string _destinationName;

private readonly HostServices? _hostServices;

protected override Workspace CreateWorkspaceImpl()
{
var hostServices = s_testServices.GetHostServices();
var hostServices = _hostServices ?? s_testServices.GetHostServices();

var workspace = new AdhocWorkspace(hostServices);
var testOptionsService = (TestMoveStaticMembersService)workspace.Services.GetRequiredService<IMoveStaticMembersOptionsService>();
testOptionsService.DestinationType = _destinationType;
testOptionsService.SelectedMembers = _selection;
testOptionsService.Filename = _destinationName;
var testOptionsService = workspace.Services.GetService<IMoveStaticMembersOptionsService>() as TestMoveStaticMembersService;
if (testOptionsService is not null)
{
testOptionsService.DestinationType = _destinationType;
testOptionsService.SelectedMembers = _selection;
testOptionsService.Filename = _destinationName;
}

return workspace;
}
Expand All @@ -2618,9 +2640,9 @@ private static async Task TestMovementNewFileAsync(
},
}.RunAsync().ConfigureAwait(false);

private static async Task TestNoRefactoringAsync(string initialMarkup)
private static async Task TestNoRefactoringAsync(string initialMarkup, HostServices? hostServices = null)
{
await new Test("", ImmutableArray<string>.Empty)
await new Test("", ImmutableArray<string>.Empty, hostServices: hostServices)
{
TestCode = initialMarkup,
FixedCode = initialMarkup,
Expand Down
Loading

0 comments on commit 72f98f8

Please sign in to comment.