我有以下测试:
IUnityContainer unityContainer = MockRepository.GenerateStrictMock<IUnityContainer>();
unityContainer.Expect(c => c.IsRegistered<IServiceContainerRegistrar>()).Return(true).Repeat.Once();
据我所知,我正在创建 IUnityContainer 的模拟,并告诉他当有人调用该IsRegistered
方法时要返回什么。
我收到以下异常:
Test method CommonInitializerTest.CommonInitializer_Initialize_WorksOnce threw exception:
System.InvalidOperationException: Previous method 'IEnumerator.MoveNext();' requires a return value or an exception to throw.
使用以下堆栈跟踪:
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)
所以 Expect 正在调用真正的代码,因为我没有嘲笑 Unity 使用的所有东西,所以它失败了。为什么 RhinoMock 在注册期望的时候会执行真实的代码??????