mono / monodevelop

MonoDevelop is a cross platform .NET IDE
http://www.monodevelop.com
2.82k stars 1.01k forks source link

Introduce a special CompositionManager service for the test suite #7422

Open Therzok opened 5 years ago

Therzok commented 5 years ago

Currently, there is no way to define a class in unit tests that allows for MEF composition.

Introduce a special CompositionManager implementation which also adds the current test assembly and its dependencies into the MEF graph.

Need to design how to switch between the IDE and the Test catalogs.

VS bug #856034

Therzok commented 5 years ago

Have tried multiple ways to fix this, but I'm hitting some roadblocks.

There are scenarios where we want to either use the IDE type or a type defined in a test assembly. In those cases, we cannot solve both - we have 2 exports for one given type.

I'm trying to figure out if we can somehow integrate DelegatingExportProvider, where we use bait-and-switch depending on what the test fixture is annotated with, but not sure it's the right approach.

@alanmcgovern @redth @abock how do you imagine MEF 'just working' in unit tests? There's a plethora of cases to cover - mocked exports, real IDE exports, mixed ones. I'd like to understand the requests better before I try and overengineer a solution for this.

Therzok commented 5 years ago

I.e. Roslyn has a few cached ExportProviders, but doesn't allow registering arbitrary assemblies: http://source.roslyn.io/#Roslyn.Services.Test.Utilities/TestExportProvider.cs,19

Therzok commented 5 years ago

Ignore my previous comment.

Found an interesting bit here: http://source.roslyn.io/#Microsoft.VisualStudio.LanguageServices.CSharp.UnitTests/EventHookup/EventHookupTestState.cs,39

Which then goes to ExportProviderCache.

But nothing is automated, in the terms of creating the composition itself: http://source.roslyn.io/#Microsoft.VisualStudio.LanguageServices.CSharp.UnitTests/CodeModel/VisualStudioTestExportProvider.cs,16

So the whole idea is to have different export providers which just add your parts.