示例#1
0
        public void AddingSameViewTwiceThrows()
        {
            var     regionManager = new MockRegionManager();
            var     control       = new MockControl();
            IRegion region        = new RegionBase(control);

            region.RegionManager = regionManager;
            IView myView = new MockView();

            region.Add(myView);

            try
            {
                region.Add(myView);
                Assert.Fail();
            }
            catch (InvalidOperationException ex)
            {
                Assert.AreEqual("View already exists in region.", ex.Message);
            }
            catch
            {
                Assert.Fail();
            }
        }
示例#2
0
        public void AddingDuplicateNamedViewThrows()
        {
            var     control = new MockControl();
            IRegion region  = new RegionBase(control);
            IView   myView  = new MockView();

            region.Add(myView, "MyView");
            region.Add(myView, "MyView");
        }
示例#3
0
        public void ViewRemovedEventPassesTheViewRemovedInTheEventArgs()
        {
            object removedView = null;

            var     regionManager = new MockRegionManager();
            var     control       = new MockControl();
            IRegion region        = new RegionBase(control);

            region.RegionManager = regionManager;
            IView myView = new MockView();

            region.Views.CollectionChanged += (sender, e) =>
            {
                if (e.Action == NotifyCollectionChangedAction.Remove)
                {
                    removedView = e.OldItems[0];
                }
            };
            region.Add(myView);
            Assert.IsNull(removedView);

            region.Remove(myView);

            Assert.AreSame(myView, removedView);
        }
示例#4
0
        public void ShowViewFiresViewShowedEvent()
        {
            bool viewActivated = false;

            var     regionManager = new MockRegionManager();
            var     control       = new MockControl();
            IRegion region        = new RegionBase(control);

            region.RegionManager = regionManager;
            IView myView = new MockView();

            region.ActiveViews.CollectionChanged += (o, e) =>
            {
                if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems.Contains(myView))
                {
                    viewActivated = true;
                }
            };
            region.Add(myView);
            Assert.IsFalse(viewActivated);

            region.Activate(myView);

            Assert.IsTrue(viewActivated);
        }
示例#5
0
        public void AddViewRaisesCollectionViewEvent()
        {
            bool viewAddedCalled = false;

            var     regionManager = new MockRegionManager();
            var     control       = new MockControl();
            IRegion region        = new RegionBase(control);

            region.RegionManager = regionManager;
            IView myView = new MockView();

            region.Views.CollectionChanged += (sender, e) =>
            {
                if (e.Action == NotifyCollectionChangedAction.Add)
                {
                    viewAddedCalled = true;
                }
            };

            object model = new object();

            Assert.IsFalse(viewAddedCalled);
            region.Add(myView);

            Assert.IsTrue(viewAddedCalled);
        }
示例#6
0
        public void RemoveViewFiresViewRemovedEvent()
        {
            bool viewRemoved = false;

            var     regionManager = new MockRegionManager();
            var     control       = new MockControl();
            IRegion region        = new RegionBase(control);

            region.RegionManager = regionManager;
            IView myView = new MockView();

            region.Views.CollectionChanged += (sender, e) =>
            {
                if (e.Action == NotifyCollectionChangedAction.Remove)
                {
                    viewRemoved = true;
                }
            };

            region.Add(myView);
            Assert.IsFalse(viewRemoved);

            region.Remove(myView);

            Assert.IsTrue(viewRemoved);
        }
示例#7
0
        public void CanAddContentToRegion()
        {
            var     control = new MockControl();
            IRegion region  = new RegionBase(control);

            region.Add(new MockView());
            Assert.AreEqual(1, region.Views.Cast <object>().Count());
        }
示例#8
0
        public void AddNamedViewWithNullOrEmptyStringNameThrows()
        {
            var     control = new MockControl();
            IRegion region  = new RegionBase(control);
            IView   myView  = new MockView();

            region.Add(myView, string.Empty);
        }
示例#9
0
        public void CanRemoveContentFromRegion()
        {
            var     control = new MockControl();
            IRegion region  = new RegionBase(control);
            IView   view    = new MockView();

            region.Add(view);
            region.Remove(view);
            Assert.AreEqual(0, region.Views.Cast <object>().Count());
        }
示例#10
0
        public void AddNamedViewIsAlsoListedInViewsCollection()
        {
            var     control = new MockControl();
            IRegion region  = new RegionBase(control);
            IView   myView  = new MockView();

            region.Add(myView, "MyView");

            Assert.AreEqual(1, region.Views.Cast <object>().Count());
            Assert.AreSame(myView, region.Views.Cast <object>().ElementAt(0));
        }
示例#11
0
        public void GetViewReturnsNullAfterRemovingViewFromRegion()
        {
            var     control = new MockControl();
            IRegion region  = new RegionBase(control);
            IView   myView  = new MockView();

            region.Add(myView, "MyView");
            region.Remove(myView);

            Assert.IsNull(region.GetView("MyView"));
        }
示例#12
0
        public void CanAddAndRetrieveNamedViewInstance()
        {
            var     control = new MockControl();
            IRegion region  = new RegionBase(control);
            IView   myView  = new MockView();

            region.Add(myView, "MyView");
            object returnedView = region.GetView("MyView");

            Assert.IsNotNull(returnedView);
            Assert.AreSame(returnedView, myView);
        }
示例#13
0
        public void CreatingNewScopesAsksTheRegionManagerForNewInstance()
        {
            var     regionManager = new MockRegionManager();
            var     control       = new MockControl();
            IRegion region        = new RegionBase(control);

            region.RegionManager = regionManager;
            var myView = new MockView();

            region.Add(myView, "MyView", true);

            Assert.IsTrue(regionManager.CreateRegionManagerCalled);
        }
示例#14
0
        public void AddViewReturnsNewRegionManager()
        {
            var     regionManager = new MockRegionManager();
            var     control       = new MockControl();
            IRegion region        = new RegionBase(control);

            region.RegionManager = regionManager;
            var myView = new MockView();

            var returnedRegionManager = region.Add(myView, "MyView", true);

            Assert.AreNotSame(regionManager, returnedRegionManager);
        }
示例#15
0
        public void AddingNonDependencyObjectToRegionDoesNotThrow()
        {
            var     regionManager = new MockRegionManager();
            var     control       = new MockControl();
            IRegion region        = new RegionBase(control);

            region.RegionManager = regionManager;
            var myView = new MockView();

            region.Add(myView);

            Assert.AreEqual(1, region.Views.Cast <object>().Count());
        }
示例#16
0
        public void RegionExposesCollectionOfContainedViews()
        {
            var     control = new MockControl();
            IRegion region  = new RegionBase(control);
            IView   view    = new MockView();

            region.Add(view);

            var views = region.Views;

            Assert.IsNotNull(views);
            Assert.AreEqual(1, views.Cast <object>().Count());
            Assert.AreSame(view, views.Cast <object>().ElementAt(0));
        }
示例#17
0
        public void RemovingViewAlsoRemovesItFromActiveViews()
        {
            var     regionManager = new MockRegionManager();
            var     control       = new MockControl();
            IRegion region        = new RegionBase(control);

            region.RegionManager = regionManager;
            IView myView = new MockView();

            region.Add(myView);
            region.Activate(myView);
            Assert.IsTrue(region.ActiveViews.Contains(myView));

            region.Remove(myView);

            Assert.IsFalse(region.ActiveViews.Contains(myView));
        }