public void ModuleManagerRunCalled() { // Have to use a non-mocked container because of IsRegistered<> extension method, Registrations property,and ContainerRegistration var container = new UnityContainer(); var mockedModuleInitializer = new Mock<IModuleInitializer>(); var mockedModuleManager = new Mock<IModuleManager>(); var regionAdapterMappings = new RegionAdapterMappings(); var serviceLocatorAdapter = new UnityServiceLocatorAdapter(container); var regionBehaviorFactory = new RegionBehaviorFactory(serviceLocatorAdapter); container.RegisterInstance<IServiceLocator>(serviceLocatorAdapter); container.RegisterInstance<UnityBootstrapperExtension>(new UnityBootstrapperExtension()); container.RegisterInstance<IModuleCatalog>(new ModuleCatalog()); container.RegisterInstance<IModuleInitializer>(mockedModuleInitializer.Object); container.RegisterInstance<IModuleManager>(mockedModuleManager.Object); container.RegisterInstance<RegionAdapterMappings>(regionAdapterMappings); container.RegisterInstance<SelectorRegionAdapter>(new SelectorRegionAdapter(regionBehaviorFactory)); container.RegisterInstance<ItemsControlRegionAdapter>(new ItemsControlRegionAdapter(regionBehaviorFactory)); container.RegisterInstance<ContentControlRegionAdapter>(new ContentControlRegionAdapter(regionBehaviorFactory)); var bootstrapper = new MockedContainerBootstrapper(container); bootstrapper.Run(); mockedModuleManager.Verify(mm => mm.Run(), Times.Once()); }
public void NullControlThrows() { var regionAdapterMappings = new RegionAdapterMappings(); var regionAdapter = new MockRegionAdapter(); regionAdapterMappings.RegisterMapping(null, regionAdapter); }
public void RegisterAMappingThatAlreadyExistsThrows() { var regionAdapterMappings = new RegionAdapterMappings(); var regionAdapter = new MockRegionAdapter(); regionAdapterMappings.RegisterMapping(typeof(ItemsControl), regionAdapter); regionAdapterMappings.RegisterMapping(typeof(ItemsControl), regionAdapter); }
private DelayedRegionCreationBehavior GetBehavior(DependencyObject control, MockRegionManagerAccessor accessor, MockRegionAdapter adapter) { var mappings = new RegionAdapterMappings(); mappings.RegisterMapping(control.GetType(), adapter); var behavior = new DelayedRegionCreationBehavior(mappings); behavior.RegionManagerAccessor = accessor; behavior.TargetElement = control; return behavior; }
public void ShouldGetMappingForDerivedTypesThanTheRegisteredOnes() { var regionAdapterMappings = new RegionAdapterMappings(); var regionAdapter = new MockRegionAdapter(); regionAdapterMappings.RegisterMapping(typeof(ItemsControl), regionAdapter); var returnedAdapter = regionAdapterMappings.GetMapping(typeof(ItemsControlDescendant)); Assert.IsNotNull(returnedAdapter); Assert.AreSame(regionAdapter, returnedAdapter); }
public void ShouldGetRegisteredMapping() { var regionAdapterMappings = new RegionAdapterMappings(); Type registeredType = typeof(ItemsControl); var regionAdapter = new MockRegionAdapter(); regionAdapterMappings.RegisterMapping(registeredType, regionAdapter); var returnedAdapter = regionAdapterMappings.GetMapping(registeredType); Assert.IsNotNull(returnedAdapter); Assert.AreSame(regionAdapter, returnedAdapter); }
public void ShouldGetTheMostSpecializedMapping() { var regionAdapterMappings = new RegionAdapterMappings(); var genericAdapter = new MockRegionAdapter(); var specializedAdapter = new MockRegionAdapter(); regionAdapterMappings.RegisterMapping(typeof(ItemsControl), genericAdapter); regionAdapterMappings.RegisterMapping(typeof(ItemsControlDescendant), specializedAdapter); var returnedAdapter = regionAdapterMappings.GetMapping(typeof(ItemsControlDescendant)); Assert.IsNotNull(returnedAdapter); Assert.AreSame(specializedAdapter, returnedAdapter); }
protected override RegionAdapterMappings ConfigureRegionAdapterMappings() { this.MethodCalls.Add(MethodBase.GetCurrentMethod().Name); ConfigureRegionAdapterMappingsCalled = true; var regionAdapterMappings = base.ConfigureRegionAdapterMappings(); DefaultRegionAdapterMappings = regionAdapterMappings; return regionAdapterMappings; }
public MefDelayedRegionCreationBehavior(RegionAdapterMappings regionAdapterMappings) : base(regionAdapterMappings) { }
private static void SetupMockedContainerForVerificationTests(Mock<IUnityContainer> mockedContainer) { var mockedModuleInitializer = new Mock<IModuleInitializer>(); var mockedModuleManager = new Mock<IModuleManager>(); var regionAdapterMappings = new RegionAdapterMappings(); var serviceLocatorAdapter = new UnityServiceLocatorAdapter(mockedContainer.Object); var regionBehaviorFactory = new RegionBehaviorFactory(serviceLocatorAdapter); mockedContainer.Setup(c => c.Resolve(typeof(IServiceLocator), (string)null)).Returns(serviceLocatorAdapter); mockedContainer.Setup(c => c.RegisterInstance(It.IsAny<Type>(), It.IsAny<string>(), It.IsAny<object>(), It.IsAny<LifetimeManager>())); mockedContainer.Setup(c => c.Resolve(typeof(UnityBootstrapperExtension), (string)null)).Returns( new UnityBootstrapperExtension()); mockedContainer.Setup(c => c.Resolve(typeof(IModuleCatalog), (string)null)).Returns( new ModuleCatalog()); mockedContainer.Setup(c => c.Resolve(typeof(IModuleInitializer), (string)null)).Returns( mockedModuleInitializer.Object); mockedContainer.Setup(c => c.Resolve(typeof(IModuleManager), (string)null)).Returns( mockedModuleManager.Object); mockedContainer.Setup(c => c.Resolve(typeof(RegionAdapterMappings), (string)null)).Returns( regionAdapterMappings); mockedContainer.Setup(c => c.Resolve(typeof(SelectorRegionAdapter), (string)null)).Returns( new SelectorRegionAdapter(regionBehaviorFactory)); mockedContainer.Setup(c => c.Resolve(typeof(ItemsControlRegionAdapter), (string)null)).Returns( new ItemsControlRegionAdapter(regionBehaviorFactory)); mockedContainer.Setup(c => c.Resolve(typeof(ContentControlRegionAdapter), (string)null)).Returns( new ContentControlRegionAdapter(regionBehaviorFactory)); }
protected override RegionAdapterMappings ConfigureRegionAdapterMappings() { this.ConfigureRegionAdapterMappingsCalled = true; this.MethodCalls.Add(System.Reflection.MethodBase.GetCurrentMethod().Name); DefaultRegionAdapterMappings = base.ConfigureRegionAdapterMappings(); return DefaultRegionAdapterMappings; }
public void NullAdapterThrows() { var regionAdapterMappings = new RegionAdapterMappings(); regionAdapterMappings.RegisterMapping(typeof(ItemsControl), null); }
public void GetMappingOfUnregisteredTypeThrows() { var regionAdapterMappings = new RegionAdapterMappings(); regionAdapterMappings.GetMapping(typeof(object)); }