Yes, it does help, but there a couple of issues with it. Firstly, it's extremely verbose and a little ugly. The following code prevents spurious calls to IRegionManager.RegisterViewWithRegion - but only for the overload for (string regionName, Type viewType).
Isolate.WhenCalled(() => RegionManagerExtensions.RegisterViewWithRegion(regionManager, "RegionName", typeof(object))).DoInstead(
callContext =>
{
var providedRegionManager = callContext.Parameters[0] as IRegionManager;
var providedRegionName = callContext.Parameters[1] as string;
var providedViewType = callContext.Parameters[2] as Type;
if(providedRegionManager != regionManager ||
(providedRegionName != "OutlookBarRegion" || providedRegionName != "RibbonRegion") ||
(providedViewType != typeof(TOutlookSection) || providedViewType != typeof(TRibbonContextualTabGroup)))
{
throw new InvalidOperationException(string.Format("RegisterViewWithRegion called with wrong arguments: regionName = `{0}`, viewType = `{1}`", providedRegionName, providedViewType.Name));
}
return regionManager;
}
);
Quite verbose really. Also, the next example I have is for registering a type with the IUnityContainer:
unitContainer.RegisterType<object, TDocumentPane>(moduleDocumentPaneName);
Trying to disallow all other permutations of calls using the example you gave is not realistic: in the Action or Func<> provided to WhenCalled(), I need to specify concrete types for the generic arguments, not just placeholders that I can then query using callContext.
I suppose this is one case where expect/record/replay semantics are actually useful.