c# - How can I use Rhino Mocks to mock a MEF export? -
In terms of the managed extensibility framework (MEF), I am trying to work on how to clean up with simulated tests
I have an export component in which three private is imported Each imported object (field) should be junked. Considering that the compass container uses fancy reflection strategies to set up imported private areas of compostable parts, even in unit tests, I will also need to use the container to set those field values.
How do I tell the container at runtime? To accept a dynamic object that I created with Rhino Mox as a legitimate export, so that I can be used to complete the import in the component which I am testing?
My question has been answered.
Hi Nathan
There are many different options here.
-
Using a batch, you can call AddExportedObject method to add fake examples in the container. AddExportedObject allows you to specify the contract for that frequency that you are adding. I.e. batch Ad-Exposed Object (Mock logger, typef (Illogger));
-
You can also create a custom export provider so that you can add fake examples. If you follow this link, here are some uses I use. . With FakeExportDefinitions you will find a FakeExportProvider. Take a func for example FakeExportDefinitions This means that you can give it an example, or even make fake directly.
The sample code for example is used.
Protected Override Zero Reference () {MockKach = Mock Repository. Generate Stub & lt; ICache & gt; (); Var metadata = new dictionary & lt; String, Object & gt; () Var Cache Definition = New FakeInstanceExportDefinition (Typef (ICc), Mockcat, Metadata); FakeProvider = new FakeExportProvider (f => (FakeInstanceExportDefinition) f) .instance); FakeProvider.AddExportDefinitions (cacheDefinition); Cachexport = fakeprovire Gate Exports & lt; ICache & gt; (); } Now from top I am directly questioning the export provider. However, we allow entry into an export provider in the construction of our container. You can do it ...
var container = new composition container (empty, phakprovaider).
H.H. Glenn
Comments
Post a Comment