Skip to content

Commit

Permalink
Merge pull request dotnet#64799 from Cosifne/dev/shech/FixMEFErrorInI…
Browse files Browse the repository at this point in the history
…ntegrationTest

Export correct type for VisualStudioWorkpacePartialSolutionsTestHook.cs
  • Loading branch information
Cosifne authored Oct 19, 2022
2 parents 10cfffd + 9c0f460 commit 795612c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 43 deletions.
12 changes: 5 additions & 7 deletions src/EditorFeatures/TestUtilities/Workspaces/TestWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ internal TestWorkspace(
bool disablePartialSolutions = true,
bool ignoreUnchangeableDocumentsWhenApplyingChanges = true,
WorkspaceConfigurationOptions? configurationOptions = null)
: base(GetHostServices(ref composition, configurationOptions != null, disablePartialSolutions), workspaceKind ?? WorkspaceKind.Host)
: base(GetHostServices(ref composition, configurationOptions != null), workspaceKind ?? WorkspaceKind.Host)
{
this.Composition = composition;
this.ExportProvider = composition.ExportProviderFactory.CreateExportProvider();

var partialSolutionsTestHook = Services.GetRequiredService<IWorkpacePartialSolutionsTestHook>();
partialSolutionsTestHook.IsPartialSolutionDisabled = disablePartialSolutions;

// configure workspace before creating any solutions:
if (configurationOptions != null)
{
Expand Down Expand Up @@ -119,7 +122,7 @@ internal TestWorkspace(
_metadataAsSourceFileService = ExportProvider.GetExportedValues<IMetadataAsSourceFileService>().FirstOrDefault();
}

private static HostServices GetHostServices([NotNull] ref TestComposition? composition, bool hasWorkspaceConfigurationOptions, bool disablePartialSolutions)
private static HostServices GetHostServices([NotNull] ref TestComposition? composition, bool hasWorkspaceConfigurationOptions)
{
composition ??= EditorTestCompositions.EditorFeatures;

Expand All @@ -128,11 +131,6 @@ private static HostServices GetHostServices([NotNull] ref TestComposition? compo
composition = composition.AddParts(typeof(TestWorkspaceConfigurationService));
}

if (disablePartialSolutions)
{
composition = composition.AddParts(typeof(WorkpacePartialSolutionsTestHook));
}

return composition.GetHostServices();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void CleanUpWorkspace()
{
LoadRoslynPackage();

var hook = (VisualStudioWorkpacePartialSolutionsTestHook)_visualStudioWorkspace.Services.GetRequiredService<IWorkpacePartialSolutionsTestHook>();
var hook = _visualStudioWorkspace.Services.GetRequiredService<IWorkpacePartialSolutionsTestHook>();
hook.IsPartialSolutionDisabled = true;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace Microsoft.CodeAnalysis.Host;

internal interface IWorkpacePartialSolutionsTestHook : IWorkspaceService
{
bool IsPartialSolutionDisabled { get; }
bool IsPartialSolutionDisabled { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
using System.Composition;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Xunit.Abstractions;
using Xunit;

namespace Microsoft.CodeAnalysis.UnitTests;

[ExportWorkspaceService(typeof(IWorkpacePartialSolutionsTestHook), ServiceLayer.Host), Shared, PartNotDiscoverable]
[ExportWorkspaceService(typeof(IWorkpacePartialSolutionsTestHook), ServiceLayer.Host), Shared]
internal class WorkpacePartialSolutionsTestHook : IWorkpacePartialSolutionsTestHook
{
public bool IsPartialSolutionDisabled { get; set; } = true;
public bool IsPartialSolutionDisabled { get; set; }

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
Expand Down

0 comments on commit 795612c

Please sign in to comment.