This class is responsible for maintaining a collection of regions and attaching regions to controls.
This class supplies the attached properties that can be used for simple region creation from XAML.
Inheritance: IRegionManager
        public void WhenContactIsSelected_ThenEmailContactCommandIsEnabledAndNotifiesChange()
        {
            var contactsServiceMock = new Mock<IContactsService>();
            AsyncCallback callback = null;
            var resultMock = new Mock<IAsyncResult>();
            contactsServiceMock
                .Setup(svc => svc.BeginGetContacts(It.IsAny<AsyncCallback>(), null))
                .Callback<AsyncCallback, object>((cb, s) => callback = cb)
                .Returns(resultMock.Object);
            var contacts = new[] { new Contact { }, new Contact { } };
            contactsServiceMock
                .Setup(svc => svc.EndGetContacts(resultMock.Object))
                .Returns(contacts);

            var regionManager = new RegionManager();

            var viewModel = new TestContactsViewModel(contactsServiceMock.Object, regionManager, contacts);

            var notified = false;
            viewModel.EmailContactCommand.CanExecuteChanged += (s, o) => notified = true;
            Assert.IsFalse(viewModel.EmailContactCommand.CanExecute(null));
            viewModel.Contacts.MoveCurrentToFirst();
            Assert.IsTrue(viewModel.EmailContactCommand.CanExecute(null));
            Assert.IsTrue(notified);
        }
        public void WhenReceivesContacts_ThenAddsContactsToTheCollection()
        {
            var contactsServiceMock = new Mock<IContactsService>();
            AsyncCallback callback = null;
            var resultMock = new Mock<IAsyncResult>();
            contactsServiceMock
                .Setup(svc => svc.BeginGetContacts(It.IsAny<AsyncCallback>(), null))
                .Callback<AsyncCallback, object>((cb, s) => callback = cb)
                .Returns(resultMock.Object);
            var contacts = new[] { new Contact { }, new Contact { } };
            contactsServiceMock
                .Setup(svc => svc.EndGetContacts(resultMock.Object))
                .Returns(contacts);

            var regionManager = new RegionManager();

            var viewModel = new ContactsViewModel(contactsServiceMock.Object, regionManager);

            this.EnqueueConditional(() => callback != null);

            this.EnqueueCallback(() => callback(resultMock.Object));

            this.EnqueueCallback(
                () =>
                {
                    CollectionAssert.AreEqual(contacts, new List<Contact>(viewModel.Contacts.Cast<Contact>()));
                });

            this.EnqueueTestComplete();
        }
        public void WhenNavigatingWithQueryString_ViewIsActivated()
        {
            // Prepare
            object view = new object();
            Uri viewUri = new Uri(view.GetType().Name + "?MyQuery=true", UriKind.Relative);

            IRegion region = new Region();
            region.Add(view);

            string regionName = "RegionName";
            RegionManager regionManager = new RegionManager();
            regionManager.Regions.Add(regionName, region);

            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRegionNavigationJournalEntry>()).Returns(new RegionNavigationJournalEntry());

            IServiceLocator serviceLocator = serviceLocatorMock.Object;
            RegionNavigationContentLoader contentLoader = new RegionNavigationContentLoader(serviceLocator);
            IRegionNavigationJournal journal = new Mock<IRegionNavigationJournal>().Object;

            RegionNavigationService target = new RegionNavigationService(serviceLocator, contentLoader, journal);
            target.Region = region;

            // Act
            bool isNavigationSuccessful = false;
            target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true);

            // Verify
            Assert.IsTrue(isNavigationSuccessful);
            bool isViewActive = region.ActiveViews.Contains(view);
            Assert.IsTrue(isViewActive);
        }
示例#4
0
        public App()
        {
            try
            {
                IUnityContainer unityContainer = new UnityContainer();

                var connectionString = System.Configuration.ConfigurationSettings.AppSettings.Get("webService");
                IWebservice webService = new Webservice(connectionString);

                EventAggregator eventAggregator = new EventAggregator();
                unityContainer.RegisterInstance<IEventAggregator>(eventAggregator);
                unityContainer.RegisterInstance<IWebservice>(webService);

                IMessaging emailMessenger = new EmailMessaging();
                unityContainer.RegisterInstance<IMessaging>(emailMessenger);

                var regionManager = new RegionManager();
                regionManager.Regions.Add(new Region() { Name = "MainContentRegion" });
                unityContainer.RegisterInstance<IRegionManager>(regionManager);

                ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(unityContainer));

            }
            catch (Exception ex)
            {
                logger.Error("Error in app constructor", ex);
            }
        }
 public void CreateRegionManagerCreatesANewInstance()
 {
     var regionManager = new RegionManager();
     var createdRegionManager = regionManager.CreateRegionManager();
     Assert.IsNotNull(createdRegionManager);
     Assert.IsInstanceOfType(createdRegionManager, typeof(RegionManager));
     Assert.AreNotSame(regionManager, createdRegionManager);
 }
        public void AddPassesItselfAsTheRegionManagerOfTheRegion()
        {
            var regionManager = new RegionManager();
            var region = new MockPresentationRegion() { Name = "region" };
            regionManager.Regions.Add(region);

            Assert.AreSame(regionManager, region.RegionManager);
        }
        public void WhenCreated_ThenRequestsContacts()
        {
            var contactsServiceMock = new Mock<IContactsService>();
            var regionManager = new RegionManager();

            var viewModel = new ContactsViewModel(contactsServiceMock.Object, regionManager);

            contactsServiceMock.Verify(svc => svc.BeginGetContacts(It.IsAny<AsyncCallback>(), null));
            Assert.IsTrue(viewModel.Contacts.IsEmpty);
        }
        public void CanAddRegion()
        {
            IRegion region1 = new MockPresentationRegion() { Name = "MainRegion" };

            RegionManager regionManager = new RegionManager();
            regionManager.Regions.Add(region1);

            IRegion region2 = regionManager.Regions["MainRegion"];
            Assert.AreSame(region1, region2);
        }
        public void CanRemoveRegion()
        {
            var regionManager = new RegionManager();
            IRegion region = new MockPresentationRegion();
            region.Name = "TestRegion";
            regionManager.Regions.Add(region);

            regionManager.Regions.Remove("TestRegion");

            Assert.IsFalse(regionManager.Regions.ContainsRegionWithName("TestRegion"));
        }
        public void CanCheckTheExistenceOfARegion()
        {
            RegionManager regionManager = new RegionManager();
            bool result = regionManager.Regions.ContainsRegionWithName("noRegion");

            Assert.IsFalse(result);

            IRegion region = new MockPresentationRegion() { Name = "noRegion" };
            regionManager.Regions.Add(region);

            result = regionManager.Regions.ContainsRegionWithName("noRegion");

            Assert.IsTrue(result);
        }
 public MainStationViewModel()
 {
     RegionManager = new RegionManager();
 }
 public ToolBoxModule(RegionManager regMan)
 {
     regionManager = regMan;
 }
示例#13
0
 public void ShouldFailIfRegionDoesntExists()
 {
     RegionManager regionManager = new RegionManager();
     IRegion region = regionManager.Regions["nonExistentRegion"];
 }
示例#14
0
        public void WhenRemovingRegions_ThenRegionsCollectionNotifiesUpdate()
        {
            var regionManager = new RegionManager();

            var region1 = new Region { Name = "region1" };
            var region2 = new Region { Name = "region2" };

            regionManager.Regions.Add(region1);
            regionManager.Regions.Add(region2);

            NotifyCollectionChangedEventArgs args = null;
            regionManager.Regions.CollectionChanged += (s, e) => args = e;

            regionManager.Regions.Remove("region2");

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, args.Action);
            CollectionAssert.AreEqual(new object[] { region2 }, args.OldItems);
            Assert.AreEqual(0, args.OldStartingIndex);
            Assert.IsNull(args.NewItems);
            Assert.AreEqual(-1, args.NewStartingIndex);

            regionManager.Regions.Remove("region1");

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, args.Action);
            CollectionAssert.AreEqual(new object[] { region1 }, args.OldItems);
            Assert.AreEqual(0, args.OldStartingIndex);
            Assert.IsNull(args.NewItems);
            Assert.AreEqual(-1, args.NewStartingIndex);
        }
示例#15
0
        public void ShouldRemoveRegionManagerWhenRemoving()
        {
            var regionManager = new RegionManager();
            var region = new MockPresentationRegion();
            region.Name = "TestRegion";
            regionManager.Regions.Add(region);

            regionManager.Regions.Remove("TestRegion");

            Assert.IsNull(region.RegionManager);
        }
        public void WhenParentViewWithoutScopedRegionGetsActivatedOrDeactivated_ThenSyncedChildViewIsNotUpdated()
        {
            var commonRegionManager = new RegionManager();
            var nonScopedRegion = new Region { Name="MyRegion", RegionManager = commonRegionManager };
            commonRegionManager.Regions.Add(nonScopedRegion);
            var behaviorForScopedRegion = new RegionActiveAwareBehavior { Region = nonScopedRegion };
            behaviorForScopedRegion.Attach();
            var childActiveAwareView = new SyncedActiveAwareObject();

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

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

            nonScopedRegion.Add(childActiveAwareView);
            nonScopedRegion.Activate(childActiveAwareView);

            Assert.IsTrue(childActiveAwareView.IsActive);

            region.Deactivate(view);

            Assert.IsTrue(childActiveAwareView.IsActive);
        }
        public void WhenParentViewGetsActivatedOrDeactivated_ThenSyncedChildViewNotInActiveViewsIsNotUpdated()
        {
            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 SyncedActiveAwareObject();

            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.Deactivate(childActiveAwareView);

            Assert.IsFalse(childActiveAwareView.IsActive);

            region.Deactivate(view);

            Assert.IsFalse(childActiveAwareView.IsActive);

            region.Activate(view);

            Assert.IsFalse(childActiveAwareView.IsActive);
        }
 public void ShouldFailIfRegionDoesntExists()
 {
     RegionManager regionManager = new RegionManager();
     Assert.ThrowsException<KeyNotFoundException>(() => { IRegion region = regionManager.Regions["nonExistentRegion"]; });
 }
示例#19
0
        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 WhenNavigating_NavigationIsRecordedInJournal()
        {
            // Prepare
            object view = new object();
            Uri viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();
            region.Add(view);

            string regionName = "RegionName";
            RegionManager regionManager = new RegionManager();
            regionManager.Regions.Add(regionName, region);

            IRegionNavigationJournalEntry journalEntry = new RegionNavigationJournalEntry();

            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRegionNavigationJournalEntry>())
                .Returns(journalEntry);

            IServiceLocator serviceLocator = serviceLocatorMock.Object;
            RegionNavigationContentLoader contentLoader = new RegionNavigationContentLoader(serviceLocator);

            var journalMock = new Mock<IRegionNavigationJournal>();
            journalMock.Setup(x => x.RecordNavigation(journalEntry)).Verifiable();

            IRegionNavigationJournal journal = journalMock.Object;


            RegionNavigationService target = new RegionNavigationService(serviceLocator, contentLoader, journal);
            target.Region = region;

            // Act
            target.RequestNavigate(viewUri, nr => { });

            // Verify
            Assert.IsNotNull(journalEntry);
            Assert.AreEqual(viewUri, journalEntry.Uri);
            journalMock.VerifyAll();
        }
示例#21
0
        public void WhenRemovingNonExistingRegion_ThenRegionsCollectionDoesNotNotifyUpdate()
        {
            var regionManager = new RegionManager();

            var region1 = new Region { Name = "region1" };

            regionManager.Regions.Add(region1);

            NotifyCollectionChangedEventArgs args = null;
            regionManager.Regions.CollectionChanged += (s, e) => args = e;

            regionManager.Regions.Remove("region2");

            Assert.IsNull(args);
        }
        public void WhenNavigationSucceeds_NavigatedIsRaised()
        {
            // Prepare
            object view = new object();
            Uri viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();
            region.Add(view);

            string regionName = "RegionName";
            RegionManager regionManager = new RegionManager();
            regionManager.Regions.Add(regionName, region);

            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRegionNavigationJournalEntry>()).Returns(new RegionNavigationJournalEntry());

            IServiceLocator serviceLocator = serviceLocatorMock.Object;
            RegionNavigationContentLoader contentLoader = new RegionNavigationContentLoader(serviceLocator);
            IRegionNavigationJournal journal = new Mock<IRegionNavigationJournal>().Object;

            RegionNavigationService target = new RegionNavigationService(serviceLocator, contentLoader, journal);
            target.Region = region;

            bool isNavigatedRaised = false;
            target.Navigated += delegate(object sender, RegionNavigationEventArgs e)
            {
                if (sender == target)
                {
                    isNavigatedRaised = true;
                }
            };


            // Act
            bool isNavigationSuccessful = false;
            target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true);

            // Verify
            Assert.IsTrue(isNavigationSuccessful);
            Assert.IsTrue(isNavigatedRaised);

        }
示例#23
0
 public void AddingMultipleRegionsWithSameNameThrowsArgumentException()
 {
     var regionManager = new RegionManager();
     regionManager.Regions.Add(new MockPresentationRegion { Name = "region name" });
     regionManager.Regions.Add(new MockPresentationRegion { Name = "region name" });
 }
 public PropertiesModule(UnityContainer cont, RegionManager regMan)
 {
     regionManager = regMan;
     container = cont;
 }
示例#25
0
 public ImportAdUsersView(RegionManager regionManager)
 {
     InitializeComponent();
     _regionManager = regionManager;
 }
示例#26
0
 public InternalErrorsView(RegionManager regionManager)
 {
     InitializeComponent();
     _regionManager = regionManager;
 }