jcansdale / TestDriven.Net-Issues

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

Warn when a `Test With > In-Proc (VS SDK)` target method's [Import] isn't satisfied #127

Closed jcansdale closed 6 years ago

jcansdale commented 6 years ago

What is happening

For example, the following snippet should work because Visual Studio does export ICompositionService:

void Satisfy([Import] ICompositionService cs)
{
    cs.SatisfyImportsOnce(this);
}

The following snippet shouldn't work because Visual Studio doesn't export IComponentModel (but it does expose it as a service via SComponentModel):

void ShowComponentModel([Import] IComponentModel cm)
{
    Console.WriteLine(cm);
}

Previously TestDriven.Net was silently falling back to retrieving IComponentModel as a service by inferring its SComponentModel service type. This gave the misleading impression that IComponentModel as available as a MEF service.

What should happen

When a parameter attributed with [Import], the test should fail and expose any information about why the import couldn't be satisfied.

For example, attempting to execute this method using Test With > In-Proc (VS SDK):

void ShowComponentModel([Import] IComponentModel cm)
{
    Console.WriteLine(cm);
}

Should output the following:

1) No exports were found that match the constraint: 
    ContractName    Microsoft.VisualStudio.ComponentModelHost.IComponentModel
    RequiredTypeIdentity    Microsoft.VisualStudio.ComponentModelHost.IComponentModel

Without the [Import] it should output:

Microsoft.VisualStudio.ComponentModelHost.ComponentModel