Exemple #1
0
        public void RestoreWindowLocationAndSize()
        {
            MockPresentationService presentationService = (MockPresentationService)Container.GetExportedValue <IPresentationService>();

            presentationService.VirtualScreenWidth  = 1000;
            presentationService.VirtualScreenHeight = 700;

            SetSettingsValues(20, 10, 400, 300, true);

            ShellViewModel shellViewModel = Container.GetExportedValue <ShellViewModel>();
            MockShellView  shellView      = (MockShellView)Container.GetExportedValue <IShellView>();

            Assert.AreEqual(20, shellView.Left);
            Assert.AreEqual(10, shellView.Top);
            Assert.AreEqual(400, shellView.Width);
            Assert.AreEqual(300, shellView.Height);
            Assert.IsTrue(shellView.IsMaximized);

            shellView.Left        = 25;
            shellView.Top         = 15;
            shellView.Width       = 450;
            shellView.Height      = 350;
            shellView.IsMaximized = false;

            shellView.Close();
            AssertSettingsValues(25, 15, 450, 350, false);
        }
Exemple #2
0
        public void ModuleControllerLifecycleTest()
        {
            MockPresentationService presentationService = Container.GetExportedValue <MockPresentationService>();
            MockEntityController    entityController    = Container.GetExportedValue <MockEntityController>();
            ModuleController        moduleController    = Container.GetExportedValue <ModuleController>();

            Assert.IsTrue(presentationService.InitializeCulturesCalled);

            // Initialize
            Assert.IsFalse(entityController.InitializeCalled);
            moduleController.Initialize();
            Assert.IsTrue(entityController.InitializeCalled);

            // Run
            MockShellView shellView = Container.GetExportedValue <MockShellView>();

            Assert.IsFalse(shellView.IsVisible);
            moduleController.Run();
            Assert.IsTrue(shellView.IsVisible);

            // Exit the ShellView
            ShellViewModel shellViewModel = ViewHelper.GetViewModel <ShellViewModel>(shellView);

            shellViewModel.ExitCommand.Execute(null);
            Assert.IsFalse(shellView.IsVisible);

            // Shutdown
            Assert.IsFalse(entityController.ShutdownCalled);
            moduleController.Shutdown();
            Assert.IsTrue(entityController.ShutdownCalled);
        }
Exemple #3
0
        public void ShowAndClose()
        {
            MockMessageService messageService = Container.GetExportedValue <MockMessageService>();
            MockShellView      shellView      = (MockShellView)Container.GetExportedValue <IShellView>();
            ShellViewModel     shellViewModel = Container.GetExportedValue <ShellViewModel>();

            // Show the ShellView
            Assert.IsFalse(shellView.IsVisible);
            shellViewModel.Show();
            Assert.IsTrue(shellView.IsVisible);

            Assert.AreNotEqual("", shellViewModel.Title);

            // Try to close the ShellView but cancel this operation through the closing event
            bool cancelClosing = true;

            shellViewModel.Closing += (sender, e) =>
            {
                e.Cancel = cancelClosing;
            };
            shellViewModel.Close();
            Assert.IsTrue(shellView.IsVisible);

            // Close the ShellView via the ExitCommand
            cancelClosing = false;
            AssertHelper.PropertyChangedEvent(shellViewModel, x => x.ExitCommand, () =>
                                              shellViewModel.ExitCommand = new DelegateCommand(() => shellViewModel.Close()));
            shellViewModel.ExitCommand.Execute(null);
            Assert.IsFalse(shellView.IsVisible);
        }
Exemple #4
0
        public void ModuleControllerIsInvalidTest()
        {
            MockMessageService   messageService   = Container.GetExportedValue <MockMessageService>();
            MockEntityController entityController = Container.GetExportedValue <MockEntityController>();
            ModuleController     moduleController = Container.GetExportedValue <ModuleController>();

            moduleController.Initialize();
            moduleController.Run();

            MockShellView  shellView      = Container.GetExportedValue <MockShellView>();
            ShellViewModel shellViewModel = ViewHelper.GetViewModel <ShellViewModel>(shellView);


            // Exit the application although we have unsaved changes.
            entityController.HasChangesResult = true;
            // Simulate UI errors.
            entityController.CanSaveResult = false;
            // When the question box asks us to loose our changes we say "No" => false.
            messageService.ShowYesNoQuestionAction = (message) =>
            {
                Assert.AreEqual(Resources.LoseChangesQuestion, message);
                return(false);
            };
            shellViewModel.ExitCommand.Execute(null);
            // We expect the ShellView to stay open.
            Assert.IsTrue(shellView.IsVisible);


            // Exit the application again but this time we agree to loose our changes.
            messageService.ShowYesNoQuestionAction = (message) => true;
            shellViewModel.ExitCommand.Execute(null);
            Assert.IsFalse(shellView.IsVisible);
        }
Exemple #5
0
        public void ShellViewModelBasicTest()
        {
            MockShellView      shellView      = Container.GetExportedValue <MockShellView>();
            MockMessageService messageService = Container.GetExportedValue <MockMessageService>();
            IShellService      shellService   = Container.GetExportedValue <IShellService>();
            ShellViewModel     shellViewModel = Container.GetExportedValue <ShellViewModel>();

            // The title isn't available in the unit test environment.
            Assert.AreEqual("", shellViewModel.Title);

            Assert.AreEqual(shellService, shellViewModel.ShellService);

            // Show the ShellView
            shellViewModel.Show();
            Assert.IsTrue(shellView.IsVisible);

            // Show the about message box
            messageService.Clear();
            shellViewModel.AboutCommand.Execute(null);
            Assert.IsFalse(string.IsNullOrEmpty(messageService.Message));
            Assert.AreEqual(MessageType.Message, messageService.MessageType);

            // Close the ShellView
            bool closingEventRaised = false;

            shellViewModel.Closing += (sender, e) =>
            {
                closingEventRaised = true;
            };
            shellViewModel.Close();
            Assert.IsFalse(shellView.IsVisible);
            Assert.IsTrue(closingEventRaised);
        }
Exemple #6
0
        public void ModuleControllerHasChangesTest()
        {
            MockMessageService   messageService   = Container.GetExportedValue <MockMessageService>();
            MockEntityController entityController = Container.GetExportedValue <MockEntityController>();
            ModuleController     moduleController = Container.GetExportedValue <ModuleController>();

            moduleController.Initialize();
            moduleController.Run();

            MockShellView  shellView      = Container.GetExportedValue <MockShellView>();
            ShellViewModel shellViewModel = ViewHelper.GetViewModel <ShellViewModel>(shellView);


            // Exit the application although we have unsaved changes.
            entityController.HasChangesResult = true;
            // When the question box asks us to save the changes we say "Yes" => true.
            messageService.ShowQuestionAction = (message) =>
            {
                Assert.AreEqual(Resources.SaveChangesQuestion, message);
                return(true);
            };
            // Then we simulate that the EntityController wasn't able to save the changes.
            entityController.SaveResult = false;
            shellViewModel.ExitCommand.Execute(null);
            // The Save method must be called. Because the save operation failed the expect the ShellView to be
            // still visible.
            Assert.IsTrue(entityController.SaveCalled);
            Assert.IsTrue(shellView.IsVisible);


            // Exit the application although we have unsaved changes.
            entityController.HasChangesResult = true;
            entityController.SaveCalled       = false;
            // When the question box asks us to save the changes we say "Cancel" => null.
            messageService.ShowQuestionAction = (message) => null;
            // This time the Save method must not be called. Because we have chosen "Cancel" the ShellView must still
            // be visible.
            shellViewModel.ExitCommand.Execute(null);
            Assert.IsFalse(entityController.SaveCalled);
            Assert.IsTrue(shellView.IsVisible);


            // Exit the application although we have unsaved changes.
            entityController.HasChangesResult = true;
            entityController.SaveCalled       = false;
            // When the question box asks us to save the changes we say "No" => false.
            messageService.ShowQuestionAction = (message) => false;
            // This time the Save method must not be called. Because we have chosen "No" the ShellView must still
            // be closed.
            shellViewModel.ExitCommand.Execute(null);
            Assert.IsFalse(entityController.SaveCalled);
            Assert.IsFalse(shellView.IsVisible);
        }
        public void SaveChangesTest()
        {
            var controller = Container.GetExportedValue <ModuleController>();

            controller.Initialize();
            controller.Run();

            ShellViewModel shellViewModel = Container.GetExportedValue <ShellViewModel>();

            shellViewModel.FileService.NewCommand.Execute(null);

            MainViewModel     mainViewModel     = Container.GetExportedValue <MainViewModel>();
            RichTextViewModel richTextViewModel = ViewHelper.GetViewModel <RichTextViewModel>((IView)mainViewModel.ActiveDocumentView);

            richTextViewModel.Document.Modified = true;

            bool showDialogCalled = false;

            MockSaveChangesView.ShowDialogAction = view =>
            {
                showDialogCalled = true;
                Assert.IsTrue(ViewHelper.GetViewModel <SaveChangesViewModel>(view).Documents.SequenceEqual(
                                  new[] { richTextViewModel.Document }));
                view.Close();
            };

            // When we try to close the ShellView then the ApplicationController shows the SaveChangesView because the
            // modified document wasn't saved.
            shellViewModel.ExitCommand.Execute(null);
            Assert.IsTrue(showDialogCalled);
            MockShellView shellView = (MockShellView)Container.GetExportedValue <IShellView>();

            Assert.IsTrue(shellView.IsVisible);

            showDialogCalled = false;
            MockSaveChangesView.ShowDialogAction = view =>
            {
                showDialogCalled = true;
                view.ViewModel.YesCommand.Execute(null);
            };

            MockFileDialogService fileDialogService = (MockFileDialogService)Container.GetExportedValue <IFileDialogService>();

            fileDialogService.Result = new FileDialogResult();

            // This time we let the SaveChangesView to save the modified document
            shellViewModel.ExitCommand.Execute(null);
            Assert.IsTrue(showDialogCalled);
            Assert.AreEqual(FileDialogType.SaveFileDialog, fileDialogService.FileDialogType);
            Assert.IsFalse(shellView.IsVisible);

            MockSaveChangesView.ShowDialogAction = null;
        }
Exemple #8
0
        public void ControllerLifecycle()
        {
            IApplicationController applicationController = Container.GetExportedValue <IApplicationController>();

            applicationController.Initialize();
            ShellViewModel shellViewModel = Container.GetExportedValue <ShellViewModel>();

            Assert.IsNotNull(shellViewModel.AboutCommand);
            Assert.IsNotNull(shellViewModel.SettingCommand);
            Assert.IsNotNull(shellViewModel.ExitCommand);

            applicationController.Run();
            MockShellView shellView = (MockShellView)Container.GetExportedValue <IShellView>();

            Assert.IsTrue(shellView.IsVisible);

            shellViewModel.ExitCommand.Execute(null);
            Assert.IsFalse(shellView.IsVisible);

            applicationController.Shutdown();
        }
Exemple #9
0
        public void ShowAndClose()
        {
            MockMessageService messageService = Container.GetExportedValue <MockMessageService>();
            MockShellView      shellView      = Container.GetExportedValue <MockShellView>();
            ShellViewModel     shellViewModel = Container.GetExportedValue <ShellViewModel>();

            // Show the ShellView
            Assert.IsFalse(shellView.IsVisible);
            shellViewModel.Show();
            Assert.IsTrue(shellView.IsVisible);

            // In this case it tries to get the title of the unit test framework which is ""
            Assert.AreEqual("", shellViewModel.Title);

            Assert.AreEqual(1d, shellViewModel.ShellService.ActiveZoomCommands.Zoom);

            // Show the About Dialog
            Assert.IsNull(messageService.Message);
            shellViewModel.AboutCommand.Execute(null);
            Assert.AreEqual(MessageType.Message, messageService.MessageType);
            Assert.IsNotNull(messageService.Message);

            // Try to close the ShellView but cancel this operation through the closing event
            bool cancelClosing = true;

            shellViewModel.Closing += (sender, e) =>
            {
                e.Cancel = cancelClosing;
            };
            shellViewModel.Close();
            Assert.IsTrue(shellView.IsVisible);

            // Close the ShellView via the ExitCommand
            cancelClosing = false;
            AssertHelper.PropertyChangedEvent(shellViewModel, x => x.ExitCommand, () =>
                                              shellViewModel.ExitCommand = new DelegateCommand(() => shellViewModel.Close()));
            shellViewModel.ExitCommand.Execute(null);
            Assert.IsFalse(shellView.IsVisible);
        }
Exemple #10
0
        public void RestoreWindowLocationAndSizeSpecial()
        {
            DataService             dataService         = new DataService();
            MockPresentationService presentationService = (MockPresentationService)Container.GetExportedValue <IPresentationService>();

            presentationService.VirtualScreenWidth  = 1000;
            presentationService.VirtualScreenHeight = 700;

            MockShellView   shellView      = (MockShellView)Container.GetExportedValue <IShellView>();
            IShellService   shellService   = Container.GetExportedValue <IShellService>();
            IMessageService messageService = Container.GetExportedValue <IMessageService>();

            shellView.SetNAForLocationAndSize();

            SetSettingsValues();
            new ShellViewModel(shellView, dataService, presentationService, shellService, messageService).Close();
            AssertSettingsValues(double.NaN, double.NaN, double.NaN, double.NaN, false);

            // Height is 0 => don't apply the Settings values
            SetSettingsValues(0, 0, 1, 0);
            new ShellViewModel(shellView, dataService, presentationService, shellService, messageService).Close();
            AssertSettingsValues(double.NaN, double.NaN, double.NaN, double.NaN, false);

            // Left = 100 + Width = 901 > VirtualScreenWidth = 1000 => don't apply the Settings values
            SetSettingsValues(100, 100, 901, 100);
            new ShellViewModel(shellView, dataService, presentationService, shellService, messageService).Close();
            AssertSettingsValues(double.NaN, double.NaN, double.NaN, double.NaN, false);

            // Top = 100 + Height = 601 > VirtualScreenWidth = 600 => don't apply the Settings values
            SetSettingsValues(100, 100, 100, 601);
            new ShellViewModel(shellView, dataService, presentationService, shellService, messageService).Close();
            AssertSettingsValues(double.NaN, double.NaN, double.NaN, double.NaN, false);

            // Use the limit values => apply the Settings values
            SetSettingsValues(0, 0, 1000, 700);
            new ShellViewModel(shellView, dataService, presentationService, shellService, messageService).Close();
            AssertSettingsValues(0, 0, 1000, 700, false);
        }
        public void ControllerLifecycle()
        {
            var controller = Container.GetExportedValue <ModuleController>();

            controller.Initialize();

            MockShellView  shellView      = (MockShellView)Container.GetExportedValue <IShellView>();
            ShellViewModel shellViewModel = ViewHelper.GetViewModel <ShellViewModel>(shellView);

            Assert.IsNotNull(shellViewModel.ExitCommand);

            controller.Run();

            Assert.IsTrue(shellView.IsVisible);
            MainViewModel mainViewModel = Container.GetExportedValue <MainViewModel>();

            Assert.AreEqual(mainViewModel.View, shellViewModel.ContentView);

            shellViewModel.ExitCommand.Execute(null);
            Assert.IsFalse(shellView.IsVisible);

            controller.Shutdown();
        }