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(); } }
public void AddingDuplicateNamedViewThrows() { var control = new MockControl(); IRegion region = new RegionBase(control); IView myView = new MockView(); region.Add(myView, "MyView"); region.Add(myView, "MyView"); }
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); }
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); }
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); }
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); }
public void CanAddContentToRegion() { var control = new MockControl(); IRegion region = new RegionBase(control); region.Add(new MockView()); Assert.AreEqual(1, region.Views.Cast <object>().Count()); }
public void AddNamedViewWithNullOrEmptyStringNameThrows() { var control = new MockControl(); IRegion region = new RegionBase(control); IView myView = new MockView(); region.Add(myView, string.Empty); }
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()); }
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)); }
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")); }
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); }
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); }
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); }
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()); }
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)); }
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)); }