Apr 26, 2012 at 3:33 AM
Edited Apr 26, 2012 at 3:35 AM
I am currently using Unity with MOQ to do my unit testing for WCF. In the application's code, I have the following:
private void MyMethod()
_proxy = new UnityContainer().LoadConfiguration().Resolve<IMyInterface>();
In the application's app.config, I have the following:
<register type="IMyInterface" mapTo="MyActualObject" />
In the unit test's app.config, I replace that with my mock object implementation of the proxy.
<register type="IMyInterface" mapTo="MyMockObject" />
That is all working fine. But what I would like to do further is, for certain tests, I would like to replace MyMockObject with a different mock object implementation.
Is it possible to change the registered type at runtime? I have tried doing the following in my unit test but fails cause the configuration file is readonly.
((UnityConfigurationSection)ConfigurationManager.GetSection("unity")).Containers.Registrations.MapToName = "AnotherMockObject"