public void RegionDoesNotGetAddedTwiceWhenUpdatingRegions() { var regionManager = new MockRegionManager(); var control = new MockFrameworkElement(); var regionScopeControl = new ContentControl(); var accessor = new MockRegionManagerAccessor { GetRegionManager = d => d == regionScopeControl ? regionManager : null }; var behavior = new RegionManagerRegistrationBehavior() { RegionManagerAccessor = accessor, Region = new MockPresentationRegion() { Name = "myRegionName" }, HostControl = control }; behavior.Attach(); Assert.IsFalse(regionManager.MockRegionCollection.AddCalled); regionScopeControl.Content = control; accessor.UpdateRegions(); Assert.IsTrue(regionManager.MockRegionCollection.AddCalled); regionManager.MockRegionCollection.AddCalled = false; accessor.UpdateRegions(); Assert.IsFalse(regionManager.MockRegionCollection.AddCalled); }
public void BehaviorDoesNotPreventRegionManagerFromBeingGarbageCollected() { var control = new MockFrameworkElement(); var regionManager = new MockRegionManager(); var regionManagerWeakReference = new WeakReference(regionManager); var accessor = new MockRegionManagerAccessor { GetRegionName = d => "myRegionName", GetRegionManager = d => regionManager }; var behavior = new RegionManagerRegistrationBehavior() { RegionManagerAccessor = accessor, Region = new MockPresentationRegion(), HostControl = control }; behavior.Attach(); Assert.IsTrue(regionManagerWeakReference.IsAlive); GC.KeepAlive(regionManager); regionManager = null; GC.Collect(); Assert.IsFalse(regionManagerWeakReference.IsAlive); }
public void CanAttachBeforeSettingName() { var control = new ItemsControl(); var regionManager = new MockRegionManager(); var accessor = new MockRegionManagerAccessor { GetRegionManager = d => regionManager }; var region = new MockPresentationRegion() { Name = null }; var behavior = new RegionManagerRegistrationBehavior() { RegionManagerAccessor = accessor, Region = region, HostControl = control }; behavior.Attach(); Assert.IsFalse(regionManager.MockRegionCollection.AddCalled); region.Name = "myRegionName"; Assert.IsTrue(regionManager.MockRegionCollection.AddCalled); Assert.AreSame(region, regionManager.MockRegionCollection.AddArgument); }
public void RegionGetsRemovedFromRegionManagerWhenRemovedFromScope() { var regionManager = new MockRegionManager(); var control = new MockFrameworkElement(); var regionScopeControl = new ContentControl(); var accessor = new MockRegionManagerAccessor { GetRegionManager = d => d == regionScopeControl ? regionManager : null }; var region = new MockPresentationRegion() { Name = "myRegionName" }; var behavior = new RegionManagerRegistrationBehavior() { RegionManagerAccessor = accessor, Region = region, HostControl = control }; behavior.Attach(); regionScopeControl.Content = control; accessor.UpdateRegions(); Assert.IsTrue(regionManager.MockRegionCollection.AddCalled); Assert.AreSame(region, regionManager.MockRegionCollection.AddArgument); regionScopeControl.Content = null; accessor.UpdateRegions(); Assert.IsTrue(regionManager.MockRegionCollection.RemoveCalled); }
public void HostControlSetAfterAttachThrows() { var behavior = new RegionManagerRegistrationBehavior(); var hostControl1 = new MockDependencyObject(); var hostControl2 = new MockDependencyObject(); behavior.HostControl = hostControl1; behavior.Attach(); behavior.HostControl = hostControl2; }
public void HostControlSetAfterAttachThrows() { var ex = Assert.Throws <InvalidOperationException>(() => { var behavior = new RegionManagerRegistrationBehavior(); var hostControl1 = new MockDependencyObject(); var hostControl2 = new MockDependencyObject(); behavior.HostControl = hostControl1; behavior.Attach(); behavior.HostControl = hostControl2; }); }
public void DoesNotFailIfRegionManagerIsNotSet() { var control = new ItemsControl(); var accessor = new MockRegionManagerAccessor(); var behavior = new RegionManagerRegistrationBehavior() { RegionManagerAccessor = accessor, Region = new MockPresentationRegion() { Name = "myRegionWithoutManager" }, HostControl = control }; behavior.Attach(); }
public void ShouldRegisterRegionIfRegionManagerIsSet() { var control = new ItemsControl(); var regionManager = new MockRegionManager(); var accessor = new MockRegionManagerAccessor { GetRegionManager = d => regionManager }; var region = new MockPresentationRegion() { Name = "myRegionName" }; var behavior = new RegionManagerRegistrationBehavior() { RegionManagerAccessor = accessor, Region = region, HostControl = control }; behavior.Attach(); Assert.IsTrue(regionManager.MockRegionCollection.AddCalled); Assert.AreSame(region, regionManager.MockRegionCollection.AddArgument); }