jcansdale / TestDriven.Net-Issues

Issue tracking for TestDriven.Net
https://github.com/jcansdale/TestDriven.Net-Issues/issues
24 stars 2 forks source link

Add support for executing ad-hoc methods inside VS extension MEF components #123

Closed jcansdale closed 6 years ago

jcansdale commented 6 years ago

When executing ad-hoc methods using Test With > In-Proc (VS SDK), methods with MEF and VS service parameters are supported.

For example you could write the following method that takes a MEF parameter:

void Go([Import(typeof(SVsServiceProvider))] IServiceProvider sp)
{
    var dte = (DTE)sp.GetService(typeof(DTE));
    Console.WriteLine(dte.FileName);
}

You could also do the same by accepting a VS service interface directly:

void Go(DTE dte)
{
    Console.WriteLine(dte.FileName);
}

I'd like to add support for MEF components that use importing constructors.

For example, I'd like to be able to target the Go method here:

[Export]
class MyComponent
{
    IServiceProvider sp;

    [ImportingConstructor]
    MyComponent([Import(typeof(SVsServiceProvider))] IServiceProvider sp)
    {
        this.sp = sp;
    }

    void Go()
    {
        Console.WriteLine(dte.FileName);
    }
}

That way I could try things on my MEF components with very few changes. 😄

NOTE, my use of [Import(typeof(SVsServiceProvider))] IServiceProvider sp is simply an example MEF parameter and not at all recommended!