To check your presenters’ functionality you should not use Unity in your test. The way in which you are going to test your presenters will be creating an instance of it manually, using the new
keyword, and passing mock class instance as parameters. This mock classes have to implement the interfaces that the presenter’s constructor is waiting. For example: Your LookupFormPresenter is expecting three parameters that should implement the IEventAggregator,
IRegionManager and IUnityContainer interfaces respectively. So, you should create 3 mock classes that implement these interfaces and help you to isolate the presenter’s behavior.
Also notice that it is not a good practice to pass the IUnityContainer as a parameter if it will be used to locate a service or create 1 instance of another class. In this case, you should
inject the service or object directly instead of the container.
A scenario where passing the IUnityContainer would be valid, is if you will be using the container as a factory, to dynamically create several instances of a class.
I think a good reference for you could be the mock classes created on the UIComposition.Modules.Employee.Desktop.Tests test project, inside the ViewDiscovery Quickstart solution (Or in the ViewInjection
Quickstart solution). You can open this solution executing the BAT file called Desktop & Silverlight - Open QS - View Discovery QuickStart.bat inside the folder where you extracted the Composite Application Library (CAL).
There you will find mock classes that implement the IRegionManager interface (check the MockRegionManager class) and the IUnityContainer (MockUnityContainer class), using these as example you will
be able to create a mock class for the IEventAggregator interface quickly.
After you have all the mock classes implementing the required interfaces by the presenter’s constructor. You will be able to test your presenter in an isolated way instancing each of the mock class
and passing them to the presenter as parameter.
So the test would look something like this:
public void GetCustomerPresenterTest()
//here be magic and puff I get a valid container... how do I do this?
var events = new MockEventAggregator();
var regions = new MockRegionManager();
var container = new MockUnityContainer();
var presenter = new LookupFormPresenter(events, regions, container);
Assert.AreEqual(1, customers.Count, "Wrong number of customers returned");
Assert.AreEqual("the test client", customers.Surname, "Wrong customer");
Also, the EventAggregator QuickStart has an example on how to mock the EventAggregator in your unit tests.
Please, let me know if this helps.