Exemplo n.º 1
0
        public void SetsIsActivePropertyOnIActiveAwareDataContexts()
        {
            var region   = new MockPresentationRegion();
            var behavior = new RegionActiveAwareBehavior {
                Region = region
            };

            behavior.Attach();
            var collection = region.MockActiveViews.Items;

            ActiveAwareObject activeAwareObject = new ActiveAwareObject();

            var frameworkElementMock = new Mock <FrameworkElement>();
            var frameworkElement     = frameworkElementMock.Object;

            frameworkElement.DataContext = activeAwareObject;

            Assert.IsFalse(activeAwareObject.IsActive);
            collection.Add(frameworkElement);

            Assert.IsTrue(activeAwareObject.IsActive);

            collection.Remove(frameworkElement);
            Assert.IsFalse(activeAwareObject.IsActive);
        }
        public void DetachStopsListeningForChanges()
        {
            var collection = new ObservableCollection<object>();
            var behavior = new CollectionActiveAwareBehavior(collection);
            behavior.Attach();
            behavior.Detach();
            ActiveAwareObject activeAwareObject = new ActiveAwareObject();

            collection.Add(activeAwareObject);

            Assert.IsFalse(activeAwareObject.IsActive);
        }
        public void DetachStopsListeningForChanges()
        {
            var region = new MockRegion();
            var behavior = new RegionActiveAwareBehavior { Region = region };
            var collection = region.MockActiveViews.Items;
            behavior.Attach();
            behavior.Detach();
            ActiveAwareObject activeAwareObject = new ActiveAwareObject();

            collection.Add(activeAwareObject);

            Assert.IsFalse(activeAwareObject.IsActive);
        }
        public void DetachStopsListeningForChanges()
        {
            var collection = new ObservableCollection <object>();
            var behavior   = new CollectionActiveAwareBehavior(collection);

            behavior.Attach();
            behavior.Detach();
            ActiveAwareObject activeAwareObject = new ActiveAwareObject();

            collection.Add(activeAwareObject);

            Assert.IsFalse(activeAwareObject.IsActive);
        }
Exemplo n.º 5
0
        public void DetachStopsListeningForChanges()
        {
            var region   = new MockRegion();
            var behavior = new RegionActiveAwareBehavior {
                Region = region
            };
            var collection = region.MockActiveViews.Items;

            behavior.Attach();
            behavior.Detach();
            ActiveAwareObject activeAwareObject = new ActiveAwareObject();

            collection.Add(activeAwareObject);

            Assert.IsFalse(activeAwareObject.IsActive);
        }
        public void SetsIsActivePropertyOnIActiveAwareObjects()
        {
            var collection = new ObservableCollection<object>();
            var behavior = new CollectionActiveAwareBehavior(collection);
            behavior.Attach();

            ActiveAwareObject activeAwareObject = new ActiveAwareObject();

            Assert.IsFalse(activeAwareObject.IsActive);
            collection.Add(activeAwareObject);

            Assert.IsTrue(activeAwareObject.IsActive);

            collection.Remove(activeAwareObject);
            Assert.IsFalse(activeAwareObject.IsActive);
        }
Exemplo n.º 7
0
        public void AttachesCollectionActiveAwareBehaviorToActiveViews()
        {
            var objectToAdapt     = new MockRegionTarget();
            var adapter           = new TestableRegionAdapterBase();
            var region            = (MockRegion)adapter.Initialize(objectToAdapt);
            var activeAwareObject = new ActiveAwareObject();

            Assert.IsFalse(activeAwareObject.IsActive);

            region.MockActiveViews.Items.Add(activeAwareObject);

            Assert.IsTrue(activeAwareObject.IsActive);

            region.MockActiveViews.Items.Remove(activeAwareObject);

            Assert.IsFalse(activeAwareObject.IsActive);
        }
        public void SetsIsActivePropertyOnIActiveAwareObjects()
        {
            var region = new MockRegion();
            var behavior = new RegionActiveAwareBehavior { Region = region };
            behavior.Attach();
            var collection = region.MockActiveViews.Items;

            ActiveAwareObject activeAwareObject = new ActiveAwareObject();

            Assert.IsFalse(activeAwareObject.IsActive);
            collection.Add(activeAwareObject);

            Assert.IsTrue(activeAwareObject.IsActive);

            collection.Remove(activeAwareObject);
            Assert.IsFalse(activeAwareObject.IsActive);
        }
        public void SetsIsActivePropertyOnIActiveAwareObjects()
        {
            var collection = new ObservableCollection <object>();
            var behavior   = new CollectionActiveAwareBehavior(collection);

            behavior.Attach();

            ActiveAwareObject activeAwareObject = new ActiveAwareObject();

            Assert.IsFalse(activeAwareObject.IsActive);
            collection.Add(activeAwareObject);

            Assert.IsTrue(activeAwareObject.IsActive);

            collection.Remove(activeAwareObject);
            Assert.IsFalse(activeAwareObject.IsActive);
        }
Exemplo n.º 10
0
        public void SetsIsActivePropertyOnIActiveAwareObjects()
        {
            var region   = new MockRegion();
            var behavior = new RegionActiveAwareBehavior {
                Region = region
            };

            behavior.Attach();
            var collection = region.MockActiveViews.Items;

            ActiveAwareObject activeAwareObject = new ActiveAwareObject();

            Assert.IsFalse(activeAwareObject.IsActive);
            collection.Add(activeAwareObject);

            Assert.IsTrue(activeAwareObject.IsActive);

            collection.Remove(activeAwareObject);
            Assert.IsFalse(activeAwareObject.IsActive);
        }
        public void SetsIsActivePropertyOnIActiveAwareDataContexts()
        {
            var region = new MockPresentationRegion();
            var behavior = new RegionActiveAwareBehavior { Region = region };
            behavior.Attach();
            var collection = region.MockActiveViews.Items;

            ActiveAwareObject activeAwareObject = new ActiveAwareObject();

            var frameworkElementMock = new Mock<FrameworkElement>();
            var frameworkElement = frameworkElementMock.Object;
            frameworkElement.DataContext = activeAwareObject;

            Assert.IsFalse(activeAwareObject.IsActive);
            collection.Add(frameworkElement);

            Assert.IsTrue(activeAwareObject.IsActive);

            collection.Remove(frameworkElement);
            Assert.IsFalse(activeAwareObject.IsActive);
        }
Exemplo n.º 12
0
        public void WhenParentViewGetsActivatedOrDeactivated_ThenSyncedChildViewModelThatIsNotAFrameworkElementIsNotUpdated()
        {
            var scopedRegionManager = new RegionManager();
            var scopedRegion        = new Region {
                Name = "MyScopedRegion", RegionManager = scopedRegionManager
            };

            scopedRegionManager.Regions.Add(scopedRegion);
            var behaviorForScopedRegion = new RegionActiveAwareBehavior {
                Region = scopedRegion
            };

            behaviorForScopedRegion.Attach();
            var childActiveAwareView = new ActiveAwareObject();

            var region   = new MockPresentationRegion();
            var behavior = new RegionActiveAwareBehavior {
                Region = region
            };

            behavior.Attach();

            var view = new MockFrameworkElement();

            region.Add(view);
            RegionManager.SetRegionManager(view, scopedRegionManager);
            region.Activate(view);

            scopedRegion.Add(childActiveAwareView);
            scopedRegion.Activate(childActiveAwareView);

            Assert.IsTrue(childActiveAwareView.IsActive);

            region.Deactivate(view);

            Assert.IsTrue(childActiveAwareView.IsActive);
        }
        public void WhenParentViewGetsActivatedOrDeactivated_ThenSyncedChildViewModelThatIsNotAFrameworkElementIsNotUpdated()
        {
            var scopedRegionManager = new RegionManager();
            var scopedRegion = new Region { Name = "MyScopedRegion", RegionManager = scopedRegionManager };
            scopedRegionManager.Regions.Add(scopedRegion);
            var behaviorForScopedRegion = new RegionActiveAwareBehavior { Region = scopedRegion };
            behaviorForScopedRegion.Attach();
            var childActiveAwareView = new ActiveAwareObject();            

            var region = new MockPresentationRegion();
            var behavior = new RegionActiveAwareBehavior { Region = region };
            behavior.Attach();

            var view = new MockFrameworkElement();
            region.Add(view);
            RegionManager.SetRegionManager(view, scopedRegionManager);
            region.Activate(view);

            scopedRegion.Add(childActiveAwareView);
            scopedRegion.Activate(childActiveAwareView);

            Assert.IsTrue(childActiveAwareView.IsActive);

            region.Deactivate(view);

            Assert.IsTrue(childActiveAwareView.IsActive);
        }