I'm having some issue setting up unit tests that will work using TFS 2012 and .net 4. Due to IT restrictions of the target users, I can't build against 4.5 until they permit it.
The application in question is a Prism application composed with MEF. It's a plug in application in that we load modules that compose the application via a configuration file. We have certain modules that export themselves to the MEF catalog as an IContent interface that exposes some base behavior that all modules in the application are expected to exhibit.
Each IContent interface implements an Import delegate command and an observable collection of Errors within the module. The errors collection is bound to the UI so it must be updated on the UI thread.
I've created a test class that creates and runs the MEF bootstrapper and loads all of the modules in the application in the ClassInitialize of the test class. The test class can then use the MEF catalog to get all instances of IContent and run the same base unit tests on each module to ensure they pass. As new modules are added to our solution/application, they would automatically be picked up and vetted through the same unit tests.
To further the example, the IContent command has an import Delegate Command as part of its interface. The command executes on a background thread that will load some data add some errors to the errors collection. Since the errors collection is bound to the UI, the updates are done using a checkaccess and begininvoke as needed to ensure that the errors collection is done on the correct thread. At the end of it all, the module will send out an aggregated event to indicate to the shell that the module has done its work.
Everything works fine when running in the context of the WPF application. When running the unit tests, the errors collections are never updated. I believe that the cause is that the main thread which the boot strapper is runs on, creates the observable collections - and since this thread is always running a unit test, its dispatcher never gets to process the additions to the errors collection, so the test will fail. I've verified this as if I change the CheckAccess/BeginInvoke to just invoke to run in line, it will hang at the invoke to update the errors collection. It appears that the execution of a unit test always locks the main thread.
So to sum up: Is there a way to set up the boot strapper so it runs and processes on a thread different than the main TFS test manager thread? Can I have the Main thread run, process a test method on a background thread, respond to the necessary events that its dispatcher needs to respond to, then complete my unit tests?
Thanks in advance for any help.