I am having trouble setting up the configuration of Spring.Net so that I can use Rhino Mocks to generate a mock object. I realise that GenerateMock is a static method and so I need to use the factory-method in the config, but I just can't get it to work. This is the configuration I am using:
<object id="exampleObject"
type="Rhino.Mocks.MockRepository, Rhino.Mocks"
factory-method="GenerateMock&lt;MyAssembly.MyInterface>" />
Then in my code (which is a unit test) I use:
using (IApplicationContext ctx = ContextRegistry.GetContext()) {....}
but I get the following error message:
System.Configuration.ConfigurationErrorsException: Error creating context 'spring.root': Could not load type from string value 'MyAssembly.MyInterface'. ---> System.TypeLoadException: Could not load type from string value 'MyAssembly.MyInterface'..
Any ideas why I might be getting the error?
Actually you only specify the typename but not the assembly name in the generics argument. It should better read
factory-method="GenerateMock<[MyNamespace.MyInterface, MyAssembly]>"
Note the square brackets to quote the full qualified typename and you need to grab a recent nightly build.
The full qualified name allows the CLR to locate the assembly containing your type. Otherwise Spring scans already loaded assemblies for that typename. If your assembly wasn't loaded yet, you experience the errormessage you face.