I have the following test:
IUnityContainer unityContainer = MockRepository.GenerateStrictMock<IUnityContainer>();
unityContainer.Expect(c => c.IsRegistered<IServiceContainerRegistrar>()).Return(true).Repeat.Once();
As far as I know I'm creating a mock of the IUnityContainer and I'm telling him what to return when someone calls the IsRegistered
method.
I'm getting the following Exception:
Test method CommonInitializerTest.CommonInitializer_Initialize_WorksOnce threw exception:
System.InvalidOperationException: Previous method 'IEnumerator.MoveNext();' requires a return value or an exception to throw.
With the following stacktrace:
at System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source)
at Microsoft.Practices.Unity.UnityContainerExtensions.IsRegistered(IUnityContainer container, Type typeToCheck, String nameToCheck)
at Microsoft.Practices.Unity.UnityContainerExtensions.IsRegistered(IUnityContainer container, Type typeToCheck)
at Microsoft.Practices.Unity.UnityContainerExtensions.IsRegistered(IUnityContainer container)
at Drives.Services.Common.Tests.CommonInitializerTest.<CommonInitializer_Initialize_WorksOnce>b__0(IUnityContainer c) in CommonInitializerTest.cs: line 50
at Rhino.Mocks.RhinoMocksExtensions.Expect(T mock, Function`2 action)
So the Expect is calling the real code and as I've not mocked everything used by the Unity it's failing. Why does RhinoMock execute real code when registering the expectation?????