private static void SetupMockedContainerForVerificationTests(Mock <IContainer> mockedContainer) { var mockedModuleInitializer = new Mock <IModuleInitializer>(); var mockedModuleManager = new Mock <IModuleManager>(); var regionAdapterMappings = new RegionAdapterMappings(); var containerExtension = new DryIocContainerExtension(mockedContainer.Object); var regionBehaviorFactory = new RegionBehaviorFactory(containerExtension); mockedContainer.Setup(c => c.Register(It.IsAny <Factory>(), It.IsAny <Type>(), It.IsAny <string>(), It.IsAny <IfAlreadyRegistered?>(), It.IsAny <bool>())); mockedContainer.Setup(c => c.Resolve(typeof(IModuleCatalog), IfUnresolved.Throw)).Returns( new ModuleCatalog()); mockedContainer.Setup(c => c.Resolve(typeof(IModuleInitializer), IfUnresolved.Throw)).Returns( mockedModuleInitializer.Object); mockedContainer.Setup(c => c.Resolve(typeof(IModuleManager), IfUnresolved.Throw)).Returns( mockedModuleManager.Object); mockedContainer.Setup(c => c.Resolve(typeof(RegionAdapterMappings), IfUnresolved.Throw)).Returns( regionAdapterMappings); mockedContainer.Setup(c => c.Resolve(typeof(SelectorRegionAdapter), IfUnresolved.Throw)).Returns( new SelectorRegionAdapter(regionBehaviorFactory)); mockedContainer.Setup(c => c.Resolve(typeof(ItemsControlRegionAdapter), IfUnresolved.Throw)).Returns( new ItemsControlRegionAdapter(regionBehaviorFactory)); mockedContainer.Setup(c => c.Resolve(typeof(ContentControlRegionAdapter), IfUnresolved.Throw)).Returns( new ContentControlRegionAdapter(regionBehaviorFactory)); }
private static void SetupMockedContainerForVerificationTests(Mock <IContainer> mockedContainer) { var mockedModuleInitializer = new Mock <IModuleInitializer>(); var mockedModuleManager = new Mock <IModuleManager>(); var regionAdapterMappings = new RegionAdapterMappings(); var containerExtension = new DryIocContainerExtension(mockedContainer.Object); var regionBehaviorFactory = new RegionBehaviorFactory(containerExtension); mockedContainer.Setup(c => c.Register(It.IsAny <Factory>(), It.IsAny <Type>(), It.IsAny <string>(), It.IsAny <IfAlreadyRegistered?>(), It.IsAny <bool>())); // NOTE: The actual method called by Prism's DryIocContainerExtension is off over the IResolver not IContainer mockedContainer.As <IResolver>().Setup(r => r.Resolve(typeof(IModuleCatalog), It.IsAny <object>(), IfUnresolved.Throw, It.IsAny <Type>(), It.IsAny <Request>(), It.IsAny <object[]>())).Returns( new ModuleCatalog()); mockedContainer.As <IResolver>().Setup(c => c.Resolve(typeof(IModuleInitializer), It.IsAny <object>(), IfUnresolved.Throw, It.IsAny <Type>(), It.IsAny <Request>(), It.IsAny <object[]>())).Returns( mockedModuleInitializer.Object); mockedContainer.As <IResolver>().Setup(c => c.Resolve(typeof(IModuleManager), It.IsAny <object>(), IfUnresolved.Throw, It.IsAny <Type>(), It.IsAny <Request>(), It.IsAny <object[]>())).Returns( mockedModuleManager.Object); mockedContainer.As <IResolver>().Setup(c => c.Resolve(typeof(RegionAdapterMappings), It.IsAny <object>(), IfUnresolved.Throw, It.IsAny <Type>(), It.IsAny <Request>(), It.IsAny <object[]>())).Returns( regionAdapterMappings); mockedContainer.As <IResolver>().Setup(c => c.Resolve(typeof(SelectorRegionAdapter), It.IsAny <object>(), IfUnresolved.Throw, It.IsAny <Type>(), It.IsAny <Request>(), It.IsAny <object[]>())).Returns( new SelectorRegionAdapter(regionBehaviorFactory)); mockedContainer.As <IResolver>().Setup(c => c.Resolve(typeof(ItemsControlRegionAdapter), It.IsAny <object>(), IfUnresolved.Throw, It.IsAny <Type>(), It.IsAny <Request>(), It.IsAny <object[]>())).Returns( new ItemsControlRegionAdapter(regionBehaviorFactory)); mockedContainer.As <IResolver>().Setup(c => c.Resolve(typeof(ContentControlRegionAdapter), It.IsAny <object>(), IfUnresolved.Throw, It.IsAny <Type>(), It.IsAny <Request>(), It.IsAny <object[]>())).Returns( new ContentControlRegionAdapter(regionBehaviorFactory)); }
public void ShouldForwardResolveToInnerContainer() { var mockContainer = new Mock <IContainer>(); Assert.Empty(mockContainer.Invocations); var containerExtension = new DryIocContainerExtension(mockContainer.Object); // We register the IContainerExtension and IContainerProvider directly with the container in the ctor. Assert.Equal(2, mockContainer.Invocations.Count); ContainerLocator.ResetContainer(); ContainerLocator.SetContainerExtension(() => containerExtension); var resolved = ContainerLocator.Container.Resolve(typeof(object)); Assert.Equal(3, mockContainer.Invocations.Count); }
public void ShouldForwardResolveToInnerContainer() { object myInstance = new object(); var mockContainer = new Mock <IContainer>(); mockContainer.Setup(c => c.Resolve(typeof(object), IfUnresolved.Throw)).Returns(myInstance); var containerExtension = new DryIocContainerExtension(mockContainer.Object); ContainerLocator.ResetContainer(); ContainerLocator.SetContainerExtension(() => containerExtension); var resolved = ContainerLocator.Container.Resolve(typeof(object)); mockContainer.Verify(c => c.Resolve(typeof(object), IfUnresolved.Throw)); Assert.Same(myInstance, resolved); }