This project has moved and is read-only. For the latest updates, please go here.

Verifying the member an Import-/ExportDefinition wraps

Jan 7, 2010 at 7:06 AM


Is there another way to check what member a given ImportDefinition is defined for other than calling IsConstraintSatisfiedBy? It does not expose the Member property (it appears to be hidden in an internal class) and as far as I can tell the only way to verify this is by manufacturing an ExportDefinition and then call IsConstraintSatisfiedBy on the ImportDefinition.

I have a method that takes a set of parameters, makes some decisions and then returns an ImportDefinition (internally it uses the ReflectionModelServices, but that's just an implementation detail). I now want to write a unit test to verify that the method returned an ImportDefinition for the right member on the part. My preference would be to just directly check the MemberInfo, but that appears to be out of the question.

Creating the ExportDefinition works, it's a bit more unnecessary work since I need to pay attention to the contract and metadata, which is not the concern of the unit test to care about...

Just want to make sure I'm not missing some other obvious way :-)

Jan 9, 2010 at 10:39 AM

Finally coming back to this "issue" the aswer was pretty obvious. Import-/ExportDefinitions are model agnostic and does not necessarily have to point to

a type. The import has a condition that it checks to see if it's been statisfied and that condition *is* model specific. In the case of the default model in MEF

it's base on types and internally uses a set of Reflection** classes which derives from the primitives such as Import-/ExportDefinition. I plan on blogging a

bit about things like this within the next couple of weeks.

Jan 10, 2010 at 9:22 PM

Actually ignore both my previous posts. The first one was poorly written and the second one was a false positive. Here's the deal, imagine the following scenario

in an application.


1) You have a method that takes an arbitrary number of parameters, and returns an ImportDefinition (same would apply for ExportDefinition)

2) The method takes the parameters, applies to rules and figures out the values it should use when it calles


3) It decides that for the importingMember (of type LazyMemberInfo) it passes in the Foo property on the Bar type

4) It then returns the ImportDefinition


Alright. How do you write a test that verifies that the correct "importingMember" was provided for the ImportDefinition for the parameter

values that was passed into the method in 1) ??? What I want to test is that the logic for deciding which member to use for the import is

correct and in order to do this I kind of would need to get access to ImportingLazyMember on ReflectionMemberImportDefinition, but

since that's an internal class that's out of the question.


Are the any other way to assert the above? Just to clarify, I'm not looking to verify the behavior of the RMS, but the logic in the method

mentioned above and to do so I need to check what importing member was selected by the method.