I believe this was addressed in the new version of DynamicProxy (which Rhino relies on). I don't have a ton of understanding of this particular issue but Krzysztof Kozmic and Tuna Toksoz are the two guys you need to be seeking out.
Tim On Mon, Sep 7, 2009 at 6:29 PM, bill richards <[email protected]>wrote: > > I found this article : > > http://www.neovolve.com/post/2009/08/07/Mocking-IUnityContainer-and-avoiding-BadImageFormatException.aspx > > which explains ... There is an issue with mocking IUnityContainer from > RhinoMocks. A BadImageFormatException is thrown when you attempt to > create a mock or a stub of IUnityContainer. > > There is a workaround, in which we can use > GenerateMock<UnityContainerBase> or GenerateMock<UnityContainer> > instead. > > However, this then gives me an altogether different error > > private const string MessageSent = "Services Module > Initialized"; > > [Test] > public void > WhenInstantiated_ShouldCallIStatusMessageServicePublishMessage() > { > var unity = MockRepository.GenerateStub<UnityContainer>(); > > var aggregator = > MockRepository.GenerateStub<IEventAggregator>(); > var service = > MockRepository.GenerateStub<IStatusMessageService>(); > var region = MockRepository.GenerateStub<IRegionManager> > (); > > unity.Stub(container => container.Resolve<IEventAggregator> > ()).Return(aggregator); > unity.Stub(container => > container.Resolve<IStatusMessageService>()).Return(service); > > new ServicesModule2(unity, region).Initialize(); > > unity.AssertWasCalled(container => > container.Resolve<IStatusMessageService>()); > unity.AssertWasCalled(container => > container.Resolve<IEventAggregator>()); > service.AssertWasCalled(messageService => > messageService.PublishStatusMessage(MessageSent)); > } > > > System.InvalidCastException: Unable to cast object of type > 'ObjectProxy4e0d754fae4247b5b42d4589f74e77b1' to type > 'Microsoft.Practices.Composite.Events.IEventAggregator'. > > Which is thrown from the following line of code: > > unity.Stub(container => container.Resolve<IEventAggregator> > ()).Return(aggregator); > > > -- Tim Barcz Microsoft ASPInsider http://timbarcz.devlicio.us http://www.twitter.com/timbarcz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en -~----------~----~----~----~------~----~------~--~---
