1

This is maddening. I am trying to write a simple test using Moq (at the moment but I will use anything that works) that will verify that registerViewWithRegion was called but every freaking method in prism is a static extension method! I have searched the web looking for an example of this and haven't found anything... Hopefully someone can tell me how to go about this. Here is what I am trying to do.

var container = new UnityContainer();
var regionManagerMock = new Mock<IRegionManager>();
regionManagerMock.Setup(r => r.RegisterViewWithRegion("",  typeof(RibbonControlView)));
container.RegisterInstance(regionManagerMock.Object);

 RibbonControlModule ribbonControlModule = new RibbonControlModule(container);
 ribbonControlModule.Initialize();

 regionManagerMock.Verify(x => x.RegisterViewWithRegion("RibbonRegion", typeof(RibbonControlView)));

Of course that blows up cause RegisterViewWithRegion is a static extension method, every wanna be coding rockstar has written a howto about using tests but I can't find turd about about what to do when you run into something like this (static extension methods), I can't believe it's this hard... Or maybe I am just an idiot - that would be fine if someone could just explain how I go about doing this...

Just as a side note - I found this http://compositewpf.codeplex.com/discussions/68353?ProjectName=compositewpf - In that post they are using Rhino which I would use if it would work but it blows up as well... I don't know how that code in that post ever worked.

Thanks for any help!

mfloryan
  • 7,667
  • 4
  • 31
  • 44
Kenn
  • 2,709
  • 2
  • 29
  • 60
  • Perhaps this question will shed some light. http://stackoverflow.com/questions/562129/how-do-i-use-moq-to-mock-an-extension-method – mfloryan Mar 04 '11 at 12:10

1 Answers1

4

You can get an instance of the IRegionViewRegistry instead of IRegionManager. As the RegisterViewWithRegion method, which is used to perform View Discovery, is an instance member, you will be able to mock it as desired.

I hope this helps. Damian

Damian Schenkelman
  • 3,505
  • 1
  • 15
  • 19