Beispiel #1
0
        public void GivenRiskeerGuiWithStorageSql_WhenRunWithMigratedFile_MigratedProjectSet(string sourceFilePath)
        {
            string targetFilePath = Path.Combine(workingDirectory, nameof(GivenRiskeerGuiWithStorageSql_WhenRunWithMigratedFile_MigratedProjectSet));

            MigrateFile(sourceFilePath, targetFilePath);

            // Given
            var projectStore  = new StorageSqLite();
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.StrictMock <IInquiryHelper>();

            mocks.ReplayAll();

            var projectMigrator = new ProjectMigrator(inquiryHelper);
            var guiCoreSettings = new GuiCoreSettings
            {
                ApplicationIcon = SystemIcons.Application
            };

            using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RiskeerProjectFactory(() => null), guiCoreSettings))
            {
                // When
                gui.Run(targetFilePath);

                // Then
                Assert.AreEqual(targetFilePath, gui.ProjectFilePath);
                Assert.NotNull(gui.Project);
                string expectedProjectName = Path.GetFileNameWithoutExtension(targetFilePath);
                Assert.AreEqual(expectedProjectName, gui.Project.Name);
                Assert.AreEqual("description", gui.Project.Description);
                Assert.IsInstanceOf <RiskeerProject>(gui.Project);
            }

            mocks.VerifyAll();
        }
Beispiel #2
0
        public void GivenRiskeerGui_WhenRunWithUnmigratedFileAndNoInquireContinuation_MigratedProjectNotSet(string sourceFilePath)
        {
            // Given
            var projectStore  = new StorageSqLite();
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.Stub <IInquiryHelper>();

            inquiryHelper.Expect(helper => helper.InquireContinuation(null))
            .IgnoreArguments()
            .Return(false);
            mocks.ReplayAll();

            var projectMigrator = new ProjectMigrator(inquiryHelper);

            using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RiskeerProjectFactory(() => null), new GuiCoreSettings()))
            {
                // When
                gui.Run(sourceFilePath);

                // Then
                Assert.IsNull(gui.ProjectFilePath);
                Assert.IsNull(gui.Project);
            }

            mocks.VerifyAll();
        }
Beispiel #3
0
        public void GivenPluginWithGuiSetAndOpenedDuneLocationCalculationsView_WhenUserDefinedTargetProbabilityRemovedFromCollectionAndObserversNotified_ThenViewTitleUpdated()
        {
            // Given
            var mocks             = new MockRepository();
            var projectStore      = mocks.Stub <IStoreProject>();
            var projectMigrator   = mocks.Stub <IMigrateProject>();
            var projectFactory    = mocks.Stub <IProjectFactory>();
            var project           = mocks.Stub <IProject>();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings()))
            {
                gui.Plugins.AddRange(new PluginBase[]
                {
                    new DuneErosionPlugin()
                });

                gui.Run();
                gui.SetProject(project, null);

                const double targetProbability    = 0.1;
                var          removedCalculations  = new DuneLocationCalculationsForTargetProbability(targetProbability);
                var          affectedCalculations = new DuneLocationCalculationsForTargetProbability(targetProbability);
                var          failureMechanism     = new DuneErosionFailureMechanism
                {
                    DuneLocationCalculationsForUserDefinedTargetProbabilities =
                    {
                        removedCalculations,
                        affectedCalculations
                    }
                };

                gui.DocumentViewController.CloseAllViews();
                gui.DocumentViewController.OpenViewForData(new DuneLocationCalculationsForUserDefinedTargetProbabilityContext(affectedCalculations,
                                                                                                                              failureMechanism,
                                                                                                                              assessmentSection));

                IView view = gui.ViewHost.DocumentViews.First();

                // Precondition
                Assert.IsInstanceOf <DuneLocationCalculationsView>(view);
                Assert.IsTrue(AvalonDockViewHostTestHelper.IsTitleSet((AvalonDockViewHost)gui.ViewHost, view, "Hydraulische belastingen - 1/10 (1)"));

                // When
                failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.Remove(removedCalculations);
                failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.NotifyObservers();

                // Then
                Assert.IsTrue(AvalonDockViewHostTestHelper.IsTitleSet((AvalonDockViewHost)gui.ViewHost, view, "Hydraulische belastingen - 1/10"));
                mocks.VerifyAll();
            }
        }
Beispiel #4
0
        public void GivenPluginWithGuiSetAndOpenedDuneLocationCalculationsView_WhenRemovingDataForOpenedViewAndObserversNotified_ThenNoExceptionThrown()
        {
            // Given
            var mocks             = new MockRepository();
            var projectStore      = mocks.Stub <IStoreProject>();
            var projectMigrator   = mocks.Stub <IMigrateProject>();
            var projectFactory    = mocks.Stub <IProjectFactory>();
            var project           = mocks.Stub <IProject>();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, projectFactory, new GuiCoreSettings()))
            {
                gui.Plugins.AddRange(new PluginBase[]
                {
                    new DuneErosionPlugin()
                });
                gui.Run();
                gui.SetProject(project, null);

                var calculations     = new DuneLocationCalculationsForTargetProbability(0.1);
                var failureMechanism = new DuneErosionFailureMechanism
                {
                    DuneLocationCalculationsForUserDefinedTargetProbabilities =
                    {
                        calculations
                    }
                };

                gui.SetProject(project, null);

                gui.DocumentViewController.CloseAllViews();
                gui.DocumentViewController.OpenViewForData(new DuneLocationCalculationsForUserDefinedTargetProbabilityContext(calculations,
                                                                                                                              failureMechanism,
                                                                                                                              assessmentSection));

                IView view = gui.ViewHost.DocumentViews.First();

                // Precondition
                Assert.IsInstanceOf <DuneLocationCalculationsView>(view);

                // When
                failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.Remove(calculations);
                void Call() => failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.NotifyObservers();

                // Then
                Assert.DoesNotThrow(Call);
                mocks.VerifyAll();
            }
        }
Beispiel #5
0
        public void GivenRiskeerGui_WhenRunWithUnmigratedFileAndInquireContinuation_MigratedProjectSet(string sourceFilePath)
        {
            // Given
            string targetFilePath = Path.Combine(workingDirectory, nameof(GivenRiskeerGui_WhenRunWithUnmigratedFileAndInquireContinuation_MigratedProjectSet));

            var projectStore  = new StorageSqLite();
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.Stub <IInquiryHelper>();

            inquiryHelper.Expect(helper => helper.InquireContinuation(null))
            .IgnoreArguments()
            .Return(true);
            inquiryHelper.Expect(helper => helper.GetTargetFileLocation(null, null))
            .IgnoreArguments()
            .Return(targetFilePath);
            mocks.ReplayAll();

            var projectMigrator = new ProjectMigrator(inquiryHelper);
            var guiCoreSettings = new GuiCoreSettings
            {
                ApplicationIcon = SystemIcons.Application
            };

            using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RiskeerProjectFactory(() => null), guiCoreSettings))
            {
                // When
                gui.Run(sourceFilePath);

                // Then
                Assert.AreEqual(targetFilePath, gui.ProjectFilePath);
                string expectedProjectName = Path.GetFileNameWithoutExtension(targetFilePath);
                Assert.AreEqual(expectedProjectName, gui.Project.Name);
                Assert.AreEqual("description", gui.Project.Description);
                Assert.IsInstanceOf <RiskeerProject>(gui.Project);
            }

            mocks.VerifyAll();
        }
Beispiel #6
0
        private void RunRiskeer()
        {
            string loaderDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (loaderDirectory != null)
            {
                Environment.CurrentDirectory = loaderDirectory;
            }

            System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);

            // handle exception from UI thread
            System.Windows.Forms.Application.ThreadException += Application_ThreadException;

            // handle exception from all threads except UI
            AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException;

            gui.Run(fileToOpen);

            // Riskeer started, clean-up all possible memory
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }