Esempio n. 1
0
        public void RequestClose_StopsAfterFirstChildReturnsFalse()
        {
            ScreenConductor conductor = CreateScreenConductor();
            var             first     = new ScreenMock(Aggregator)
            {
                RequestCloseResult = true
            };
            var second = new ScreenMock(Aggregator)
            {
                RequestCloseResult = false
            };
            var third = new ScreenMock(Aggregator)
            {
                RequestCloseResult = true
            };

            OpenScreen(conductor, first);
            OpenScreen(conductor, second);
            OpenScreen(conductor, third);

            bool result = new ScreenLifecycleOperations(Aggregator, conductor)
                          .RequestClose();

            Assert.IsFalse(result, "RequestClose should return false.");
            Assert.IsTrue(first.WasCloseRequested);
            Assert.IsTrue(second.WasCloseRequested);
            Assert.IsFalse(third.WasCloseRequested);
        }
Esempio n. 2
0
        public void OpenScreen_WhenDeactivateThrowsException_AddsScreenAndUpdatesActiveScreen()
        {
            ScreenConductor conductor   = CreateScreenConductor();
            ScreenMock      alreadyOpen = OpenNewScreen(conductor);

            ScreenMock oldScreen = new ScreenMock(Aggregator)
            {
                ThrowOnDeactivate = true
            };

            OpenScreen(conductor, oldScreen);

            PropertyChangedCounter pc = CreateActiveScreenChangedListener(conductor);

            ScreenMock newScreen = new ScreenMock(Aggregator);

            OpenScreen(conductor, newScreen);

            Assert.IsTrue(newScreen.WasInitialized);
            Assert.IsTrue(newScreen.WasActivated);
            Assert.IsTrue(conductor.Screens.Contains(newScreen));
            Assert.AreEqual(newScreen, conductor.ActiveScreen);

            Assert.IsFalse(conductor.Screens.Contains(oldScreen));

            pc.AssertOneRaise();
        }
Esempio n. 3
0
        private ScreenMock OpenNewScreen(ScreenConductor conductor)
        {
            ScreenMock screen = new ScreenMock(Aggregator);

            OpenScreen(conductor, screen);
            return(screen);
        }
Esempio n. 4
0
        public void CloseScreen_WhenActivateOfPreviouslyActiveThrowsException_RemovesPreviouslyActiveAndSetsActiveScreenToNull()
        {
            ScreenConductor conductor = CreateScreenConductor();

            OpenNewScreen(conductor);

            ScreenMock previouslyActive = new ScreenMock(Aggregator);

            OpenScreen(conductor, previouslyActive);

            ScreenMock newScreen = new ScreenMock(Aggregator);

            OpenScreen(conductor, newScreen);

            PropertyChangedCounter pc = CreateActiveScreenChangedListener(conductor);

            previouslyActive.ThrowOnActivate = true;

            CloseScreen(conductor, newScreen, false);

            Assert.IsFalse(conductor.Screens.Contains(newScreen));
            Assert.IsFalse(conductor.Screens.Contains(previouslyActive));
            Assert.IsNull(conductor.ActiveScreen);
            pc.AssertOneRaise();
        }
Esempio n. 5
0
        public void ShowDialogWithCertainScreenInstance_ScreenLifecycleDoesntContainDialogLifecycleAfterShowDialog()
        {
            WindowService.ShowRealWindow = false;

            var screen = new ScreenMock(Aggregator);

            DialogSerivce.ShowDialog(ScreenFactory.For(screen));
            Assert.IsFalse(screen.Children.OfType <DialogLifecycle>().Any());
        }
Esempio n. 6
0
        public void CloseScreen_WhenScreenIsNotContained_ThrowsArgumentException()
        {
            ScreenConductor condcutor         = CreateScreenConductor();
            ScreenMock      uncontainedScreen = new ScreenMock(Aggregator);

            AssertHelper.Throws <ArgumentException>(() =>
                                                    condcutor.CloseScreen(uncontainedScreen, requestClose: true)
                                                    );
        }
Esempio n. 7
0
        public void CloseScreen_SetsParentToNull()
        {
            ScreenConductor conductor = CreateScreenConductor();
            ScreenMock      s         = new ScreenMock(Aggregator);

            OpenScreen(conductor, s);
            Assert.AreEqual(conductor, s.Parent);

            CloseScreen(conductor, s, false);
            Assert.IsNull(s.Parent);
        }
Esempio n. 8
0
        public void ShowDialog_WhenViewInitializationThrowsException_DoesNotShowWindow()
        {
            WindowService.ThrowViewInitializationException = true;

            var screen = new ScreenMock(Aggregator);

            AssertHelper.Throws <ScreenMockException>(() =>
                                                      ShowDialog(screen)
                                                      );

            Assert.IsFalse(WindowService.WasShown);

            Assert.IsTrue(screen.WasDeactivated);
            Assert.IsTrue(screen.WasClosed);
        }
Esempio n. 9
0
        public void Close_WithtRequestClose_CallsRequestClose()
        {
            WindowService.ShowRealWindow = true;

            var screen = new ScreenMock(Aggregator);

            WindowService.WindowLoaded += delegate {
                ScreenHelper.Close(screen, new DialogScreenResult(false), requestClose: true);
            };

            ShowDialog(screen);

            Assert.IsTrue(screen.WasClosed);
            Assert.IsTrue(screen.WasCloseRequested);
        }
Esempio n. 10
0
        public void GetAssociatedWindow_ReturnsWindow()
        {
            WindowService.ShowRealWindow = false;

            WindowView window = new WindowView(false);
            ScreenMock screen = new ScreenMock(Aggregator);

            DialogSerivce.Show(
                window,
                ScreenFactory.For(screen),
                modal: false
                );

            Assert.AreEqual(window, DialogSerivce.GetAssociatedWindow(screen));
        }
Esempio n. 11
0
        public void ShowDialog_WhenActivateThrowsException_DoesNotShowDialog()
        {
            var screen = new ScreenMock(Aggregator)
            {
                ThrowOnActivate = true
            };

            ShowDialogAndExpectException(screen);

            Assert.IsFalse(WindowService.WasShown);

            Assert.IsFalse(screen.WasCloseRequested);
            Assert.IsTrue(screen.WasDeactivated);
            Assert.IsTrue(screen.WasClosed);
        }
Esempio n. 12
0
        public void Show_AttachesAppropriateChildren()
        {
            WindowService.ShowRealWindow = false;

            var screen = new ScreenMock(Aggregator);

            DialogSerivce.Show(
                new WindowView(false),
                ScreenFactory.For(screen),
                modal: false
                );

            Assert.IsTrue(screen.Children.OfType <WindowLifecycle>().Any());
            Assert.IsTrue(screen.Children.OfType <ScreenCloseHandler>().Any());
            Assert.IsFalse(screen.Children.OfType <DialogLifecycle>().Any());
        }
Esempio n. 13
0
        public void CloseDialog_WhenOnCloseThrowsException_ClosesDialogAndOnlyShowDialogThrowsException()
        {
            var screen = new ScreenMock(Aggregator)
            {
                ThrowOnClose = true
            };

            WindowService.WindowLoaded += (Window win) => {
                Assert.IsTrue(win.IsVisible);
                CloseDialog(screen);
            };

            ShowDialogAndExpectException(screen);

            Assert.IsFalse(WindowService.LastWindow.IsVisible);
        }
Esempio n. 14
0
        public void OpenScreen_WhenInitializeThrowsException_DoesNotAddScreenAndDoesNotChangeActiveScreen()
        {
            ScreenConductor condcutor   = CreateScreenConductor();
            ScreenMock      alreadyOpen = OpenNewScreen(condcutor);

            PropertyChangedCounter pc = CreateActiveScreenChangedListener(condcutor);

            ScreenMock newScreen = new ScreenMock(Aggregator)
            {
                ThrowOnInitialize = true
            };

            OpenScreen(condcutor, newScreen);

            Assert.IsFalse(newScreen.WasActivated);
            Assert.IsFalse(condcutor.Screens.Contains(newScreen));
            Assert.AreEqual(alreadyOpen, condcutor.ActiveScreen);
            pc.AssertNoRaise();
        }
Esempio n. 15
0
        public void CloseScreen_WhenCloseThrowsException_RemovesScreen()
        {
            ScreenConductor condcutor   = CreateScreenConductor();
            ScreenMock      alreadyOpen = OpenNewScreen(condcutor);

            ScreenMock newScreen = new ScreenMock(Aggregator)
            {
                ThrowOnClose = true
            };

            OpenScreen(condcutor, newScreen);

            PropertyChangedCounter pc = CreateActiveScreenChangedListener(condcutor);

            CloseScreen(condcutor, newScreen, false);

            Assert.IsFalse(condcutor.Screens.Contains(newScreen));
            Assert.AreEqual(alreadyOpen, condcutor.ActiveScreen);
            pc.AssertOneRaise();
        }
Esempio n. 16
0
        public void OpenScreen_WhenActivateThrowsException_DoesNotAddScreenAndSetsActivateScreenToNull()
        {
            ScreenConductor conductor   = CreateScreenConductor();
            ScreenMock      alreadyOpen = OpenNewScreen(conductor);

            PropertyChangedCounter pc = CreateActiveScreenChangedListener(conductor);

            ScreenMock newScreen = new ScreenMock(Aggregator)
            {
                ThrowOnActivate = true
            };

            OpenScreen(conductor, newScreen);

            Assert.IsTrue(newScreen.WasInitialized);
            Assert.IsTrue(newScreen.WasActivated);
            Assert.IsFalse(conductor.Screens.Contains(newScreen));
            Assert.IsNull(conductor.ActiveScreen);
            pc.AssertOneRaise();
        }
Esempio n. 17
0
        public void ShowDialog_WhenExceptionOccursInShownView_ClosesDialog()
        {
            var screen = new ScreenMock(Aggregator);

            WindowService.WindowLoaded += win => {
                win.Dispatcher.BeginInvoke(
                    new Action(() => {
                    throw new ScreenMockException();
                }),
                    DispatcherPriority.Background
                    );
            };

            AssertHelper.Throws <ScreenMockException>(() =>
                                                      ShowDialog(screen)
                                                      );

            Assert.IsFalse(WindowService.LastWindow.IsVisible);
            Assert.IsTrue(screen.WasDeactivated);
            Assert.IsTrue(screen.WasClosed);
        }