public void UpdatingRegionsGetsCalledWhenAccessingRegionMembers() { var listener = new MySubscriberClass(); try { RegionManager.UpdatingRegions += listener.OnUpdatingRegions; RegionManager regionManager = new RegionManager(); regionManager.Regions.ContainsRegionWithName("TestRegion"); Assert.IsTrue(listener.OnUpdatingRegionsCalled); listener.OnUpdatingRegionsCalled = false; regionManager.Regions.Add(new MockPresentationRegion() { Name = "TestRegion" }); Assert.IsTrue(listener.OnUpdatingRegionsCalled); listener.OnUpdatingRegionsCalled = false; var region = regionManager.Regions["TestRegion"]; Assert.IsTrue(listener.OnUpdatingRegionsCalled); listener.OnUpdatingRegionsCalled = false; regionManager.Regions.Remove("TestRegion"); Assert.IsTrue(listener.OnUpdatingRegionsCalled); listener.OnUpdatingRegionsCalled = false; regionManager.Regions.GetEnumerator(); Assert.IsTrue(listener.OnUpdatingRegionsCalled); } finally { RegionManager.UpdatingRegions -= listener.OnUpdatingRegions; } }
public void ShouldNotPreventSubscribersFromBeingGarbageCollected() { var registry = new RegionViewRegistry(null); var subscriber = new MySubscriberClass(); registry.ContentRegistered += subscriber.OnContentRegistered; WeakReference subscriberWeakReference = new WeakReference(subscriber); subscriber = null; GC.Collect(); Assert.IsFalse(subscriberWeakReference.IsAlive); }
public void ShouldNotPreventSubscribersToStaticEventFromBeingGarbageCollected() { var subscriber = new MySubscriberClass(); RegionManager.UpdatingRegions += subscriber.OnUpdatingRegions; RegionManager.UpdateRegions(); Assert.IsTrue(subscriber.OnUpdatingRegionsCalled); WeakReference subscriberWeakReference = new WeakReference(subscriber); subscriber = null; GC.Collect(); Assert.IsFalse(subscriberWeakReference.IsAlive); }
public void ShouldNotPreventSubscribersFromBeingGarbageCollected() { var registry = new RegionViewRegistry(null); var subscriber = new MySubscriberClass(); registry.ContentRegistered += subscriber.OnContentRegistered; WeakReference subscriberWeakReference = new WeakReference(subscriber); subscriber = null; GC.Collect(); Assert.False(subscriberWeakReference.IsAlive); }
public async Task ShouldNotPreventSubscribersToStaticEventFromBeingGarbageCollected() { var subscriber = new MySubscriberClass(); Prism.Regions.Xaml.RegionManager.UpdatingRegions += subscriber.OnUpdatingRegions; Prism.Regions.Xaml.RegionManager.UpdateRegions(); Assert.True(subscriber.OnUpdatingRegionsCalled); var subscriberWeakReference = new WeakReference(subscriber); subscriber = null; await Task.Delay(100); GC.Collect(); Assert.False(subscriberWeakReference.IsAlive); }
public void ShouldRaiseEventWhenAddingContent() { MockServiceLocator locator = GetServiceLocator(new[] { "MyRegion" }); var listener = new MySubscriberClass(); var registry = (IRegionViewRegistry)locator.GetInstance(typeof(IRegionViewRegistry)); registry.ViewRegistered += listener.OnViewRegistered; registry.RegisterViewWithRegion("MyRegion", typeof(MockView)); Assert.IsNotNull(listener.onViewRegisteredArguments); Assert.IsNotNull(listener.onViewRegisteredArguments.RegisteredView); var result = listener.onViewRegisteredArguments.Region; Assert.IsNotNull(result); }
public void ShouldRaiseEventWhenAddingContent() { var listener = new MySubscriberClass(); MockServiceLocator locator = new MockServiceLocator(); locator.GetInstance = (type) => new MockContentObject(); var registry = new RegionViewRegistry(locator); registry.ContentRegistered += listener.OnContentRegistered; registry.RegisterViewWithRegion("MyRegion", typeof(MockContentObject)); Assert.IsNotNull(listener.onViewRegisteredArguments); Assert.IsNotNull(listener.onViewRegisteredArguments.GetView); var result = listener.onViewRegisteredArguments.GetView(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(MockContentObject)); }
public void ShouldRaiseEventWhenAddingContent() { var listener = new MySubscriberClass(); var containerMock = new Mock <IContainerExtension>(); containerMock.Setup(c => c.Resolve(typeof(MockContentObject))).Returns(new MockContentObject()); var registry = new RegionViewRegistry(containerMock.Object); registry.ContentRegistered += listener.OnContentRegistered; registry.RegisterViewWithRegion("MyRegion", typeof(MockContentObject)); Assert.NotNull(listener.onViewRegisteredArguments); Assert.NotNull(listener.onViewRegisteredArguments.GetView); var result = listener.onViewRegisteredArguments.GetView(); Assert.NotNull(result); Assert.IsType <MockContentObject>(result); }
public void UpdatingRegionsGetsCalledWhenAccessingRegionMembers() { var listener = new MySubscriberClass(); try { RegionManager.UpdatingRegions += listener.OnUpdatingRegions; RegionManager regionManager = new RegionManager(); regionManager.Regions.ContainsRegionWithName("TestRegion"); Assert.IsTrue(listener.OnUpdatingRegionsCalled); listener.OnUpdatingRegionsCalled = false; regionManager.Regions.Add(new MockRegion() { Name = "TestRegion" }); Assert.IsTrue(listener.OnUpdatingRegionsCalled); listener.OnUpdatingRegionsCalled = false; var region = regionManager.Regions["TestRegion"]; Assert.IsTrue(listener.OnUpdatingRegionsCalled); listener.OnUpdatingRegionsCalled = false; regionManager.Regions.Remove("TestRegion"); Assert.IsTrue(listener.OnUpdatingRegionsCalled); listener.OnUpdatingRegionsCalled = false; regionManager.Regions.GetEnumerator(); Assert.IsTrue(listener.OnUpdatingRegionsCalled); } finally { RegionManager.UpdatingRegions -= listener.OnUpdatingRegions; } }