示例#1
0
        public void ExportFrom_NoExporterAvailable_GivesMessageBoxAndLogsMessage(object source)
        {
            // Setup
            var mockRepository = new MockRepository();
            var mainWindow     = mockRepository.Stub <IMainWindow>();

            mockRepository.ReplayAll();

            string messageBoxText  = null;
            string messageBoxTitle = null;

            DialogBoxHandler = (name, wnd) =>
            {
                var messageBox = new MessageBoxTester(wnd);

                messageBoxText  = messageBox.Text;
                messageBoxTitle = messageBox.Title;

                messageBox.ClickOk();
            };

            var exportHandler = new GuiExportHandler(mainWindow, new List <ExportInfo>());

            // Call
            Action call = () => exportHandler.ExportFrom(source);

            // Assert
            string sourceTypeName = source == null ? "null" : source.GetType().FullName;

            TestHelper.AssertLogMessageIsGenerated(call, $"Het is niet mogelijk om de huidige selectie ({sourceTypeName}) te exporteren.");
            Assert.AreEqual("Fout", messageBoxTitle);
            Assert.AreEqual("Het is niet mogelijk om de huidige selectie te exporteren.", messageBoxText);
            mockRepository.VerifyAll();
        }
示例#2
0
        public void ExportFrom_SupportedExporterAvailableAndFilePathGivenAndExporterFails_CallsExportAndLogsMessages()
        {
            // Setup
            var mockRepository = new MockRepository();
            var mainWindow     = mockRepository.Stub <IMainWindow>();
            var exporter       = mockRepository.StrictMock <IFileExporter>();

            exporter.Stub(e => e.Export()).Return(false);
            mockRepository.ReplayAll();

            string targetExportFileName = Path.GetFullPath("exportFile.txt");

            const string exportInfoName = "Random data";
            var          exportHandler  = new GuiExportHandler(mainWindow, new List <ExportInfo>
            {
                new ExportInfo <int>
                {
                    Name = i => exportInfoName,
                    CreateFileExporter = (data, filePath) => exporter,
                    GetExportPath      = () => targetExportFileName
                }
            });

            // Call
            Action call = () => exportHandler.ExportFrom(1234);

            // Assert
            TestHelper.AssertLogMessagesAreGenerated(call, new[]
            {
                $"Exporteren van '{exportInfoName}' is gestart.",
                $"Exporteren van '{exportInfoName}' is mislukt."
            });
            mockRepository.VerifyAll();
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GuiCore"/> class.
        /// </summary>
        /// <param name="mainWindow">The main window.</param>
        /// <param name="projectStore">The project store.</param>
        /// <param name="projectMigrator">The project migrator.</param>
        /// <param name="projectFactory">The project factory.</param>
        /// <param name="fixedSettings">The fixed settings.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public GuiCore(IMainWindow mainWindow, IStoreProject projectStore, IMigrateProject projectMigrator, IProjectFactory projectFactory, GuiCoreSettings fixedSettings)
        {
            if (mainWindow == null)
            {
                throw new ArgumentNullException(nameof(mainWindow));
            }

            if (projectStore == null)
            {
                throw new ArgumentNullException(nameof(projectStore));
            }

            if (projectMigrator == null)
            {
                throw new ArgumentNullException(nameof(projectMigrator));
            }

            if (projectFactory == null)
            {
                throw new ArgumentNullException(nameof(projectFactory));
            }

            if (fixedSettings == null)
            {
                throw new ArgumentNullException(nameof(fixedSettings));
            }

            ProjectStore  = projectStore;
            FixedSettings = fixedSettings;
            MainWindow    = mainWindow;

            Plugins = new List <PluginBase>();

            viewCommandHandler = new ViewCommandHandler(this, this, this);

            StorageCommands = new StorageCommandHandler(projectStore, projectMigrator, projectFactory,
                                                        this, dialogBasedInquiryHelper, this);

            importCommandHandler = new GuiImportHandler(MainWindow, Plugins.SelectMany(p => p.GetImportInfos())
                                                        .Concat(MapImportInfoFactory.Create()),
                                                        dialogBasedInquiryHelper);
            exportCommandHandler = new GuiExportHandler(MainWindow, Plugins.SelectMany(p => p.GetExportInfos()));
            updateCommandHandler = new GuiUpdateHandler(MainWindow, Plugins.SelectMany(p => p.GetUpdateInfos()), dialogBasedInquiryHelper);

            WindowsApplication.EnableVisualStyles();
            ViewPropertyEditor.ViewCommands = ViewCommands;

            ProjectOpened       += ApplicationProjectOpened;
            BeforeProjectOpened += ApplicationBeforeProjectOpened;
            projectObserver      = new Observer(UpdateProjectData);

            applicationTitle = string.Format(CultureInfo.CurrentCulture, "{0} {1}",
                                             FixedSettings.ApplicationName,
                                             SettingsHelper.Instance.ApplicationVersion);

            SetTitle();
        }
示例#4
0
        public void ExportFrom_MultipleSupportedExportersAvailableWithDefaultSelectionDialogStyling_GivesExpectedSelectionDialog()
        {
            // Setup
            var mockRepository = new MockRepository();
            var mainWindow     = mockRepository.Stub <IMainWindow>();

            mockRepository.ReplayAll();

            var dialogText = "";

            TestListViewItem[] listViewItems = null;

            ModalFormHandler = (name, wnd, form) =>
            {
                var dialog    = new FormTester(name);
                var imageList = TypeUtils.GetField <ImageList>(dialog.TheObject, "imageList");
                var listView  = (ListView) new ControlTester("listViewItemTypes").TheObject;

                dialogText    = dialog.Text;
                listViewItems = listView.Items
                                .OfType <ListViewItem>()
                                .Select(lvi => new TestListViewItem(lvi.Name, lvi.Group.Name, imageList.Images[lvi.ImageIndex]))
                                .ToArray();

                dialog.Close();
            };

            var exportHandler = new GuiExportHandler(mainWindow, new List <ExportInfo>
            {
                new ExportInfo <int>(),
                new ExportInfo <int>()
            });

            // Call
            exportHandler.ExportFrom(1234);

            // Assert
            Assert.AreEqual("Kies wat u wilt exporteren", dialogText);

            Assert.AreEqual(2, listViewItems.Length);
            Assert.AreEqual("", listViewItems[0].Name);
            Assert.AreEqual("Algemeen", listViewItems[0].Group);
            Assert.AreEqual("", listViewItems[1].Name);
            Assert.AreEqual("Algemeen", listViewItems[1].Group);

            mockRepository.VerifyAll();
        }
示例#5
0
        public void CanExportFrom_HasOneFileExporterForTarget_ReturnTrue()
        {
            // Setup
            var mocks        = new MockRepository();
            var dialogParent = mocks.Stub <IWin32Window>();

            mocks.ReplayAll();

            var commandHandler = new GuiExportHandler(dialogParent, new List <ExportInfo>
            {
                new ExportInfo <object>()
            });

            // Call
            bool isExportPossible = commandHandler.CanExportFrom(new object());

            // Assert
            Assert.IsTrue(isExportPossible);
            mocks.VerifyAll();
        }
示例#6
0
        public void ExportFrom_SupportedExporterAvailableAndFilePathGivenAndExporterRunsSuccessful_CallsExportAndLogsMessages()
        {
            // Setup
            var mockRepository = new MockRepository();
            var mainWindow     = mockRepository.Stub <IMainWindow>();
            var exporter       = mockRepository.StrictMock <IFileExporter>();

            exporter.Stub(e => e.Export()).Return(true);
            mockRepository.ReplayAll();

            const int expectedData         = 1234;
            string    targetExportFileName = Path.GetFullPath("exportFile.txt");

            const string exportInfoName = "Random data";
            var          exportHandler  = new GuiExportHandler(mainWindow, new List <ExportInfo>
            {
                new ExportInfo <int>
                {
                    Name = i => exportInfoName,
                    CreateFileExporter = (data, filePath) =>
                    {
                        Assert.AreEqual(expectedData, data);
                        Assert.AreEqual(targetExportFileName, filePath);
                        return(exporter);
                    },
                    GetExportPath = () => targetExportFileName
                }
            });

            // Call
            Action call = () => exportHandler.ExportFrom(expectedData);

            // Assert
            TestHelper.AssertLogMessagesAreGenerated(call, new[]
            {
                $"Exporteren van '{exportInfoName}' is gestart.",
                $"Gegevens zijn geëxporteerd naar bestand '{targetExportFileName}'.",
                $"Exporteren van '{exportInfoName}' is gelukt."
            });
            mockRepository.VerifyAll();
        }
示例#7
0
        public void CanExportFrom_HasNoFileExportersForTarget_ReturnFalse()
        {
            // Setup
            var mocks        = new MockRepository();
            var dialogParent = mocks.Stub <IWin32Window>();

            mocks.ReplayAll();

            var commandHandler = new GuiExportHandler(dialogParent, new List <ExportInfo>
            {
                new ExportInfo <int>(), // Wrong object type
                new ExportInfo <object> // Disabled
                {
                    IsEnabled = o => false
                }
            });

            // Call
            bool isExportPossible = commandHandler.CanExportFrom(new object());

            // Assert
            Assert.IsFalse(isExportPossible);
            mocks.VerifyAll();
        }
示例#8
0
        public void ExportFrom_SupportedExporterAvailableNoFilePathGiven_AbortsExport()
        {
            // Setup
            var mockRepository = new MockRepository();
            var mainWindow     = mockRepository.Stub <IMainWindow>();
            var exporter       = mockRepository.StrictMock <IFileExporter>();

            mockRepository.ReplayAll();

            var exportHandler = new GuiExportHandler(mainWindow, new List <ExportInfo>
            {
                new ExportInfo <int>
                {
                    CreateFileExporter = (o, s) => exporter,
                    GetExportPath      = () => null
                }
            });

            // Call
            exportHandler.ExportFrom(1234);

            // Assert
            mockRepository.VerifyAll(); // Expect no calls on exporter mock
        }
示例#9
0
        public void ExportFrom_MultipleSupportedExportersAvailableWithCustomSelectionDialogStyling_GivesExpectedSelectionDialog(bool hasFileExtension)
        {
            // Setup
            var mockRepository = new MockRepository();
            var mainWindow     = mockRepository.Stub <IMainWindow>();

            mockRepository.ReplayAll();

            var dialogText = "";

            TestListViewItem[] listViewItems = null;

            ModalFormHandler = (name, wnd, form) =>
            {
                var dialog    = new FormTester(name);
                var imageList = TypeUtils.GetField <ImageList>(dialog.TheObject, "imageList");
                var listView  = (ListView) new ControlTester("listViewItemTypes").TheObject;

                dialogText    = dialog.Text;
                listViewItems = listView.Items
                                .OfType <ListViewItem>()
                                .Select(lvi => new TestListViewItem(lvi.Name, lvi.Group.Name, imageList.Images[lvi.ImageIndex]))
                                .ToArray();

                dialog.Close();
            };

            var exportInfo1 = new ExportInfo <int>
            {
                Name      = i => "Name 1",
                Category  = "Category 1",
                Image     = Resources.Busy_indicator,
                Extension = hasFileExtension ? "extension 1" : null
            };

            var exportInfo2 = new ExportInfo <int>
            {
                Name      = i => "Name 2",
                Category  = "Category 2",
                Image     = Resources.DeleteIcon,
                Extension = hasFileExtension ? "extension 2" : null
            };

            var exportHandler = new GuiExportHandler(mainWindow, new List <ExportInfo>
            {
                exportInfo1,
                exportInfo2
            });

            // Call
            exportHandler.ExportFrom(1234);

            // Assert
            Assert.AreEqual("Kies wat u wilt exporteren", dialogText);

            Assert.AreEqual(2, listViewItems.Length);
            string exportInfo1Name   = exportInfo1.Name(1234);
            string expectedItemName1 = hasFileExtension
                                           ? $"{exportInfo1Name} (*.{exportInfo1.Extension})"
                                           : exportInfo1Name;

            Assert.AreEqual(expectedItemName1, listViewItems[0].Name);
            Assert.AreEqual(exportInfo1.Category, listViewItems[0].Group);
            string exportInfo2Name   = exportInfo2.Name(1234);
            string expectedItemName2 = hasFileExtension
                                           ? $"{exportInfo2Name} (*.{exportInfo2.Extension})"
                                           : exportInfo2Name;

            Assert.AreEqual(expectedItemName2, listViewItems[1].Name);
            Assert.AreEqual(exportInfo2.Category, listViewItems[1].Group);

            mockRepository.VerifyAll();
        }