public void Run_CalculationInvalidInput_LogValidationStartAndEndWithError()
        {
            // Setup
            var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike)
            {
                HydraulicBoundaryDatabase =
                {
                    FilePath = Path.Combine(testDataPath, "notexisting.sqlite")
                }
            };

            var failureMechanism = new HeightStructuresFailureMechanism();
            var calculation      = new StructuresCalculation <HeightStructuresInput>();

            CalculatableActivity activity = HeightStructuresCalculationActivityFactory.CreateCalculationActivity(calculation,
                                                                                                                 failureMechanism,
                                                                                                                 assessmentSection);

            // Call
            Action call = () => activity.Run();

            // Assert
            TestHelper.AssertLogMessages(call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(4, msgs.Length);
                Assert.AreEqual($"Uitvoeren van berekening '{calculation.Name}' is gestart.", msgs[0]);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]);
                StringAssert.StartsWith("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt. " +
                                        "Fout bij het lezen van bestand", msgs[2]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[3]);
            });
            Assert.AreEqual(ActivityState.Failed, activity.State);
        }
示例#2
0
        public void Export_InvalidDirectoryRights_LogsErrorAndReturnsFalse()
        {
            // Setup
            string            filePath          = TestHelper.GetScratchPadPath(nameof(Export_InvalidDirectoryRights_LogsErrorAndReturnsFalse));
            AssessmentSection assessmentSection = CreateConfiguredAssessmentSection();

            var exporter = new AssemblyExporter(assessmentSection, filePath);

            using (var fileDisposeHelper = new FileDisposeHelper(filePath))
                using (new AssemblyToolCalculatorFactoryConfig())
                {
                    var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                    AssessmentSectionAssemblyCalculatorStub assessmentSectionAssemblyCalculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyCalculator;
                    assessmentSectionAssemblyCalculator.CombinedFailureMechanismSectionAssemblyOutput = new CombinedFailureMechanismSectionAssemblyResultWrapper(
                        Array.Empty <CombinedFailureMechanismSectionAssembly>(), AssemblyMethod.BOI3A1, AssemblyMethod.BOI3B1, AssemblyMethod.BOI3C1);

                    fileDisposeHelper.LockFiles();

                    // Call
                    var isExported            = true;
                    void Call() => isExported = exporter.Export();

                    // Assert
                    string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'. " +
                                             "Er zijn geen assemblageresultaten geëxporteerd.";
                    TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Error));
                    Assert.IsFalse(isExported);
                }
        }
        public void ScenariosView_ImportFailureMechanismSections_ChangesCorrectlyObservedAndSynced()
        {
            // Setup
            using (var form = new Form())
            {
                var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
                DataImportHelper.ImportReferenceLine(assessmentSection);

                var view = new ClosingStructuresScenariosView(assessmentSection.ClosingStructures.CalculationsGroup, assessmentSection.ClosingStructures);
                form.Controls.Add(view);
                form.Show();

                var listBox = (ListBox) new ControlTester("listBox").TheObject;

                // Precondition
                CollectionAssert.IsEmpty(listBox.Items);

                // Call
                ClosingStructuresFailureMechanism failureMechanism = assessmentSection.ClosingStructures;
                DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);
                assessmentSection.ClosingStructures.NotifyObservers();

                // Assert
                CollectionAssert.AreEqual(assessmentSection.ClosingStructures.Sections, listBox.Items);
            }
        }
        public void GivenAssessmentSectionResultObserverWithAttachedObserver_WhenMacroStabilityInwardsCalculationScenarioNotified_ThenAttachedObserverNotified()
        {
            // Given
            AssessmentSection assessmentSection = CreateAssessmentSection();
            MacroStabilityInwardsCalculationScenario calculation =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithInvalidInput();

            assessmentSection.MacroStabilityInwards.CalculationsGroup.Children.Add(calculation);

            using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                observer.Expect(o => o.UpdateObserver());
                mocks.ReplayAll();

                resultObserver.Attach(observer);

                // When
                calculation.NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
        public void GivenAssessmentSectionResultObserverWithAttachedObserver_WhenPipingScenarioConfigurationsPerFailureMechanismSectionNotified_ThenAttachedObserverNotified()
        {
            // Given
            AssessmentSection assessmentSection = CreateAssessmentSection();

            assessmentSection.Piping = new PipingFailureMechanism();
            FailureMechanismTestHelper.SetSections(assessmentSection.Piping, new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1")
            });

            using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                observer.Expect(o => o.UpdateObserver());
                mocks.ReplayAll();

                resultObserver.Attach(observer);

                // When
                assessmentSection.Piping.ScenarioConfigurationsPerFailureMechanismSection.First().NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
        public void GivenAssessmentSectionResultObserverWithAttachedObserver_WhenSpecificFailureMechanismInCollectionNotified_ThenAttachedObserverNotified()
        {
            // Given
            var specificFailureMechanism = new SpecificFailureMechanism();

            AssessmentSection assessmentSection = CreateAssessmentSection();

            assessmentSection.SpecificFailureMechanisms.Add(specificFailureMechanism);

            using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                observer.Expect(o => o.UpdateObserver());
                mocks.ReplayAll();

                resultObserver.Attach(observer);

                // When
                specificFailureMechanism.NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
        public void GivenAssessmentSectionWithFailureMechanismsReplaced_WhenNewFailureMechanismNotified_ThenAssessmentSectionResultObserverNotified <TFailureMechanism>(
            AssessmentSection assessmentSection, Func <AssessmentSection, TFailureMechanism> getFailureMechanismFunc, Action setNewFailureMechanismAction)
            where TFailureMechanism : IFailureMechanism
        {
            // Given
            using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                observer.Expect(o => o.UpdateObserver());
                mocks.ReplayAll();

                setNewFailureMechanismAction();
                assessmentSection.NotifyObservers();

                resultObserver.Attach(observer);

                TFailureMechanism newFailureMechanism = getFailureMechanismFunc(assessmentSection);

                // When
                newFailureMechanism.NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
示例#8
0
        public void GivenFormWithAssemblyResultPerSectionView_WhenCalculationNotifiesObservers_ThenRefreshButtonEnabledAndWarningSet()
        {
            // Given
            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults(
                new Random(21).NextEnumValue <AssessmentSectionComposition>());
            var calculation = new TestHeightStructuresCalculationScenario();

            assessmentSection.HeightStructures.CalculationsGroup.Children.Add(calculation);

            using (new AssemblyToolCalculatorFactoryConfig())
                using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection))
                {
                    // Precondition
                    ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester();
                    Button       button       = buttonTester.Properties;
                    Assert.IsFalse(button.Enabled);
                    ErrorProvider warningProvider = GetWarningProvider(view);
                    Assert.IsEmpty(warningProvider.GetError(button));

                    // When
                    calculation.NotifyObservers();

                    // Then
                    Assert.IsTrue(buttonTester.Properties.Enabled);
                    Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button));
                }
        }
示例#9
0
        public void GivenFormWithAssemblyResultPerSectionView_WithOrWithoutErrorSetAndObserverNotified_ThenWarningSetWithPadding(bool withError, int expectedPadding)
        {
            // Given
            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults(
                new Random(21).NextEnumValue <AssessmentSectionComposition>());

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                AssessmentSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyCalculator;
                calculator.ThrowExceptionOnCalculate = withError;

                using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection))
                {
                    // Precondition
                    ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester();
                    Button       button       = buttonTester.Properties;
                    Assert.IsFalse(button.Enabled);
                    ErrorProvider errorProvider = GetErrorProvider(view);
                    Assert.AreEqual(withError, !string.IsNullOrEmpty(errorProvider.GetError(button)));
                    ErrorProvider warningProvider = GetWarningProvider(view);
                    Assert.IsEmpty(warningProvider.GetError(button));

                    // When
                    assessmentSection.NotifyObservers();

                    // Then
                    Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button));
                    Assert.AreEqual(expectedPadding, warningProvider.GetIconPadding(button));
                }
            }
        }
示例#10
0
        public void GivenFormWithAssemblyResultPerSectionViewWithOutdatedContent_WhenRefreshingAssemblyResults_ThenRefreshButtonDisabledAndWarningCleared()
        {
            // Given
            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults(
                new Random(21).NextEnumValue <AssessmentSectionComposition>());

            using (new AssemblyToolCalculatorFactoryConfig())
                using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection))
                {
                    assessmentSection.NotifyObservers();

                    // Precondition
                    ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester();
                    Button       button       = buttonTester.Properties;
                    Assert.IsTrue(button.Enabled);
                    ErrorProvider warningProvider = GetWarningProvider(view);
                    Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button));

                    // When
                    buttonTester.Click();

                    // Then
                    Assert.IsFalse(button.Enabled);
                    Assert.IsEmpty(warningProvider.GetError(button));
                }
        }
示例#11
0
        public void GivenFormWithAssemblyResultPerSectionView_WhenFailureMechanismNotifiesObservers_ThenRefreshButtonEnabledAndWarningSet()
        {
            // Given
            var random = new Random(21);
            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults(
                random.NextEnumValue <AssessmentSectionComposition>());

            using (new AssemblyToolCalculatorFactoryConfig())
                using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection))
                {
                    // Precondition
                    ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester();
                    Button       button       = buttonTester.Properties;
                    Assert.IsFalse(button.Enabled);
                    ErrorProvider warningProvider = GetWarningProvider(view);
                    Assert.IsEmpty(warningProvider.GetError(button));

                    // When
                    IFailureMechanism[] failureMechanisms = assessmentSection.GetFailureMechanisms().ToArray();
                    failureMechanisms[random.Next(failureMechanisms.Length)].NotifyObservers();

                    // Then
                    Assert.IsTrue(buttonTester.Properties.Enabled);
                    Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button));
                }
        }
示例#12
0
        public void GivenFormWithAssemblyResultPerSectionView_WhenSpecificFailureMechanismRemoved_ThenColumnRemoved()
        {
            // Given
            var random = new Random(21);
            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults(
                random.NextEnumValue <AssessmentSectionComposition>());

            using (new AssemblyToolCalculatorFactoryConfig())
                using (ShowAssemblyResultPerSectionView(assessmentSection))
                {
                    // Precondition
                    DataGridView dataGridView = GetDataGridView();

                    DataGridViewColumnCollection dataGridViewColumns = dataGridView.Columns;
                    AssertColumns(dataGridViewColumns, GetExpectedNrOfColumns(assessmentSection), assessmentSection.SpecificFailureMechanisms);

                    ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester();

                    // When
                    SpecificFailureMechanism failureMechanismToRemove = assessmentSection.SpecificFailureMechanisms.First();
                    assessmentSection.SpecificFailureMechanisms.Remove(failureMechanismToRemove);
                    assessmentSection.NotifyObservers();
                    buttonTester.Click();

                    // Then
                    AssertColumns(dataGridViewColumns, GetExpectedNrOfColumns(assessmentSection), assessmentSection.SpecificFailureMechanisms);
                }
        }
示例#13
0
        public void GivenFormWithAssemblyResultPerSectionView_WhenSpecificFailureMechanismAdded_ThenColumnAdded()
        {
            // Given
            var random = new Random(21);
            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllFailureMechanismSectionsAndResults(
                random.NextEnumValue <AssessmentSectionComposition>());

            using (new AssemblyToolCalculatorFactoryConfig())
                using (ShowAssemblyResultPerSectionView(assessmentSection))
                {
                    var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                    AssessmentSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyCalculator;

                    // Precondition
                    DataGridView dataGridView = GetDataGridView();
                    Assert.AreEqual(20, dataGridView.ColumnCount);

                    ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester();

                    // When
                    const string testCode         = "TestCode";
                    var          failureMechanism = new SpecificFailureMechanism
                    {
                        Code = testCode
                    };

                    assessmentSection.SpecificFailureMechanisms.Add(failureMechanism);
                    assessmentSection.SpecificFailureMechanisms.NotifyObservers();
                    calculator.CombinedFailureMechanismSectionAssemblyOutput = null;
                    buttonTester.Click();

                    // Then
                    AssertColumns(dataGridView.Columns, GetExpectedNrOfColumns(assessmentSection), assessmentSection.SpecificFailureMechanisms);
                }
        }
示例#14
0
        public void Create_StringPropertiesDoNotShareReference()
        {
            // Setup
            const string originalName     = "name";
            const string originalComments = "comments";

            var section = new AssessmentSection(AssessmentSectionComposition.Dike)
            {
                Name     = originalName,
                Comments =
                {
                    Body = originalComments
                }
            };

            var registry = new PersistenceRegistry();

            // Call
            AssessmentSectionEntity entity = section.Create(registry);

            // Assert
            Assert.AreNotSame(originalName, entity.Name,
                              "To create stable binary representations/fingerprints, it's really important that strings are not shared.");
            Assert.AreNotSame(originalComments, entity.Comments,
                              "To create stable binary representations/fingerprints, it's really important that strings are not shared.");

            Assert.AreEqual(originalName, entity.Name);
            Assert.AreEqual(originalComments, entity.Comments);
        }
        private static AssessmentSection TestAssessmentSection1_2(bool useSignalFloodingProbability)
        {
            var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike,
                                                          1.0 / 1000,
                                                          1.0 / 3000)
            {
                Id   = "1-2",
                Name = "Traject 1-2",
                FailureMechanismContribution =
                {
                    NormativeProbabilityType = useSignalFloodingProbability ? NormativeProbabilityType.SignalFloodingProbability : NormativeProbabilityType.MaximumAllowableFloodingProbability
                }
            };

            assessmentSection.GrassCoverErosionInwards.GeneralInput.N  = (RoundedDouble)2.0;
            assessmentSection.GrassCoverErosionOutwards.GeneralInput.N = (RoundedDouble)2.0;
            assessmentSection.HeightStructures.GeneralInput.N          = (RoundedDouble)2.0;
            assessmentSection.ReferenceLine.SetGeometry(new[]
            {
                new Point2D(160679.9250, 475072.583),
                new Point2D(160892.0751, 474315.4917)
            });

            return(assessmentSection);
        }
示例#16
0
        public void OnNodeRenamed_WithData_SetProjectNameWithNotification()
        {
            // Setup
            var mocks    = new MockRepository();
            var observer = mocks.Stub <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
            var context           = new CalculationsStateRootContext(assessmentSection);

            context.Attach(observer);

            using (var plugin = new RiskeerPlugin())
            {
                TreeNodeInfo info = GetInfo(plugin);

                // Call
                const string newName = "New Name";
                info.OnNodeRenamed(context, newName);

                // Assert
                Assert.AreEqual(newName, assessmentSection.Name);
            }

            mocks.VerifyAll();
        }
示例#17
0
 /// <summary>
 /// Imports <see cref="FailureMechanismSection"/> data for a given enumeration of <see cref="IFailureMechanism{T}"/>.
 /// </summary>
 /// <param name="assessmentSection">The <see cref="AssessmentSection"/> that contains the <see cref="IFailureMechanism{T}"/> instances.</param>
 /// <param name="targetFailureMechanisms">The <see cref="IFailureMechanism{T}"/> instances to import on.</param>
 /// <remarks>
 /// <para>This will import the same 283 failure mechanism sections on all failure mechanisms.</para>
 /// <para>Does not import using <see cref="FileImportActivity"/>.</para>
 /// </remarks>
 public static void ImportFailureMechanismSections(AssessmentSection assessmentSection, IEnumerable <IFailureMechanism <FailureMechanismSectionResult> > targetFailureMechanisms)
 {
     using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(typeof(DataImportHelper).Assembly,
                                                                            true,
                                                                            "traject_6-3_vakken.shp",
                                                                            "traject_6-3_vakken.dbf",
                                                                            "traject_6-3_vakken.prj",
                                                                            "traject_6-3_vakken.shx"))
     {
         IFailureMechanism <FailureMechanismSectionResult>[] failureMechanisms = targetFailureMechanisms.ToArray();
         for (var i = 0; i < failureMechanisms.Length; i++)
         {
             IFailureMechanism <FailureMechanismSectionResult> failureMechanism = failureMechanisms[i];
             if (i == 0)
             {
                 string filePath = Path.Combine(embeddedResourceFileWriter.TargetFolderPath,
                                                "traject_6-3_vakken.shp");
                 var importer = new FailureMechanismSectionsImporter(
                     failureMechanism, assessmentSection.ReferenceLine, filePath,
                     new FailureMechanismSectionReplaceStrategy(failureMechanism),
                     new ImportMessageProvider());
                 importer.Import();
             }
             else
             {
                 // Copy same FailureMechanismSection instances to other failure mechanisms
                 FailureMechanismTestHelper.SetSections(failureMechanism, failureMechanisms[0].Sections.Select(DeepCloneSection).ToArray());
             }
         }
     }
 }
 private static void AddEntityForReferenceLine(AssessmentSection section, AssessmentSectionEntity entity)
 {
     if (section.ReferenceLine.Points.Any())
     {
         entity.ReferenceLinePointXml = new Point2DCollectionXmlSerializer().ToXml(section.ReferenceLine.Points);
     }
 }
        public void GivenAssessmentSectionResultObserverWithAttachedObserver_WhenSpecificFailureMechanismRemovedAndNotified_ThenAttachedObserverNotNotified()
        {
            // Given
            var failureMechanismToRemove        = new SpecificFailureMechanism();
            AssessmentSection assessmentSection = CreateAssessmentSection();

            assessmentSection.SpecificFailureMechanisms.AddRange(new[]
            {
                failureMechanismToRemove,
                new SpecificFailureMechanism()
            });

            using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                mocks.ReplayAll();

                assessmentSection.SpecificFailureMechanisms.Remove(failureMechanismToRemove);
                assessmentSection.SpecificFailureMechanisms.NotifyObservers();

                resultObserver.Attach(observer);

                // When
                failureMechanismToRemove.NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
 private static void AddHydraulicLocationCalculationEntities(AssessmentSection assessmentSection,
                                                             AssessmentSectionEntity entity,
                                                             PersistenceRegistry registry)
 {
     entity.HydraulicLocationCalculationCollectionEntity1 = assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.Create(registry);
     entity.HydraulicLocationCalculationCollectionEntity  = assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability.Create(registry);
 }
        public void GivenAssessmentSectionWithPipingFailureMechanismReplaced_WhenOldPipingScenarioConfigurationsPerFailureMechanismSectionNotified_ThenAssessmentSectionResultObserverNotNotified()
        {
            // Given
            AssessmentSection assessmentSection = CreateAssessmentSection();

            using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                mocks.ReplayAll();

                PipingFailureMechanism oldFailureMechanism = assessmentSection.Piping;
                FailureMechanismTestHelper.SetSections(oldFailureMechanism, new[]
                {
                    FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1")
                });

                assessmentSection.Piping = new PipingFailureMechanism();
                assessmentSection.NotifyObservers();

                resultObserver.Attach(observer);

                // When
                oldFailureMechanism.ScenarioConfigurationsPerFailureMechanismSection.First().NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
示例#22
0
 private void MapAssessment(AssessmentSection target)
 {
     target.AssessmentTitle = _assessment.AssessmentTitle;
     target.AssessedGradeLevelDescriptorId = _assessment.AssessedGradeLevelDescriptorId;
     target.AcademicSubjectDescriptorId    = _assessment.AcademicSubjectDescriptorId;
     target.Version = _assessment.Version;
 }
        public void GivenAssessmentSectionResultObserverWithAttachedObserver_WhenPipingCalculationScenarioNotified_ThenAttachedObserverNotified()
        {
            // Given
            AssessmentSection assessmentSection = CreateAssessmentSection();
            var calculationScenario             =
                SemiProbabilisticPipingCalculationTestFactory.CreateCalculationWithInvalidInput <SemiProbabilisticPipingCalculationScenario>();

            assessmentSection.Piping.CalculationsGroup.Children.Add(calculationScenario);

            using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                observer.Expect(o => o.UpdateObserver());
                mocks.ReplayAll();

                resultObserver.Attach(observer);

                // When
                calculationScenario.NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
        public void GetAssessmentSectionFromFile_ValidDirectoryUserClicksCancel_ReturnsNull()
        {
            // Setup
            var mockRepository = new MockRepository();
            var parentDialog   = mockRepository.Stub <IWin32Window>();

            mockRepository.ReplayAll();

            var assessmentSectionFromFileHandler = new AssessmentSectionFromFileHandler(parentDialog);

            string pathValidFolder = Path.Combine(testDataPath, "ValidShapeFile");

            SetShapeFileDirectory(assessmentSectionFromFileHandler, pathValidFolder);

            DialogBoxHandler = (name, wnd) =>
            {
                var selectionDialog = (ReferenceLineMetaSelectionDialog) new FormTester(name).TheObject;
                new ButtonTester("Cancel", selectionDialog).Click();
            };

            // Call
            AssessmentSection assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile();

            // Assert
            Assert.IsNull(assessmentSection);
            mockRepository.VerifyAll();
        }
示例#25
0
        public void Export_AssemblyCreatorExceptionThrown_LogsErrorAndReturnsFalse()
        {
            // Setup
            string            filePath          = TestHelper.GetScratchPadPath(nameof(Export_AssemblyCreatorExceptionThrown_LogsErrorAndReturnsFalse));
            AssessmentSection assessmentSection = CreateConfiguredAssessmentSection();

            var exporter = new AssemblyExporter(assessmentSection, filePath);

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub failureMechanismSectionAssemblyCalculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
                failureMechanismSectionAssemblyCalculator.FailureMechanismSectionAssemblyResultOutput = new FailureMechanismSectionAssemblyResultWrapper(
                    new DefaultFailureMechanismSectionAssemblyResult(), AssemblyMethod.BOI0A1, AssemblyMethod.BOI0B1);

                // Call
                var isExported            = true;
                void Call() => isExported = exporter.Export();

                // Assert
                const string expectedMessage = "De assemblage kan niet succesvol worden afgerond. Inspecteer de resultaten van de faalmechanismen die onderdeel zijn van de assemblage of het veiligheidsoordeel voor meer details.";
                TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Error));
                Assert.IsFalse(isExported);
            }
        }
        public void GetAssessmentSectionFromFile_ValidDirectoryLowLimitSelectedOkClicked_ReturnsFirstReadAssessmentSectionWithLowLimit()
        {
            // Setup
            var mockRepository = new MockRepository();
            var parentDialog   = mockRepository.Stub <IWin32Window>();

            mockRepository.ReplayAll();

            var assessmentSectionFromFileHandler = new AssessmentSectionFromFileHandler(parentDialog);

            string pathValidFolder = Path.Combine(testDataPath, "ValidShapeFile");

            SetShapeFileDirectory(assessmentSectionFromFileHandler, pathValidFolder);

            DialogBoxHandler = (name, wnd) =>
            {
                var selectionDialog          = (ReferenceLineMetaSelectionDialog) new FormTester(name).TheObject;
                var lowLimitValueRadioButton = (RadioButton) new RadioButtonTester("MaximumAllowableFloodingProbabilityRadioButton", selectionDialog).TheObject;
                lowLimitValueRadioButton.Checked = true;
                new ButtonTester("Ok", selectionDialog).Click();
            };

            // Call
            AssessmentSection assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile();

            // Assert
            AssertAssessmentSection(TestAssessmentSection1_2(false), assessmentSection);
            mockRepository.VerifyAll();
        }
        public void ScenariosView_ChangeStructureOfCalculation_ChangesCorrectlyObservedAndSynced()
        {
            // Setup
            var mocks           = new MockRepository();
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            using (var form = new Form())
            {
                var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
                DataImportHelper.ImportReferenceLine(assessmentSection);
                ClosingStructuresFailureMechanism failureMechanism = assessmentSection.ClosingStructures;
                DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);

                var view = new ClosingStructuresScenariosView(assessmentSection.ClosingStructures.CalculationsGroup, assessmentSection.ClosingStructures);
                form.Controls.Add(view);
                form.Show();

                var structuresImporter = new ClosingStructuresImporter(assessmentSection.ClosingStructures.ClosingStructures,
                                                                       assessmentSection.ReferenceLine, filePath, messageProvider,
                                                                       new ClosingStructureReplaceDataStrategy(failureMechanism));
                structuresImporter.Import();

                foreach (ClosingStructure structure in assessmentSection.ClosingStructures.ClosingStructures)
                {
                    assessmentSection.ClosingStructures.CalculationsGroup.Children.Add(new StructuresCalculationScenario <ClosingStructuresInput>
                    {
                        Name            = NamingHelper.GetUniqueName(assessmentSection.ClosingStructures.CalculationsGroup.Children, structure.Name + " Calculation", c => c.Name),
                        InputParameters =
                        {
                            Structure = structure
                        }
                    });
                }

                var listBox      = (ListBox) new ControlTester("listBox").TheObject;
                var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;

                listBox.SelectedItem = failureMechanism.Sections.ElementAt(32);

                // Precondition
                DataGridViewRowCollection rows = dataGridView.Rows;
                Assert.AreEqual(1, rows.Count);
                Assert.AreEqual("Eerste kunstwerk sluiting 6-3 Calculation", rows[0].Cells[nameColumnIndex].FormattedValue);

                // Call
                CalculationGroup calculationsGroup = assessmentSection.ClosingStructures.CalculationsGroup;
                ((StructuresCalculation <ClosingStructuresInput>)calculationsGroup.Children[1]).InputParameters.Structure =
                    ((StructuresCalculation <ClosingStructuresInput>)calculationsGroup.Children[0]).InputParameters.Structure;
                calculationsGroup.NotifyObservers();

                // Assert
                Assert.AreEqual(2, rows.Count);
                Assert.AreEqual("Eerste kunstwerk sluiting 6-3 Calculation", rows[0].Cells[nameColumnIndex].FormattedValue);
                Assert.AreEqual("Tweede kunstwerk sluiting 6-3 Calculation", rows[1].Cells[nameColumnIndex].FormattedValue);
            }

            mocks.VerifyAll();
        }
        public void GetAssessmentSectionFromFile_SecondRowSelectedOkClicked_ReturnsSecondReadAssessmentSection()
        {
            // Setup
            var mockRepository = new MockRepository();
            var parentDialog   = mockRepository.Stub <IWin32Window>();

            mockRepository.ReplayAll();

            var assessmentSectionFromFileHandler = new AssessmentSectionFromFileHandler(parentDialog);

            string pathValidFolder = Path.Combine(testDataPath, "ValidShapeFile");

            SetShapeFileDirectory(assessmentSectionFromFileHandler, pathValidFolder);

            var rowCount = 0;

            DialogBoxHandler = (name, wnd) =>
            {
                var selectionDialog = (ReferenceLineMetaSelectionDialog) new FormTester(name).TheObject;
                var grid            = (DataGridViewControl) new ControlTester("ReferenceLineMetaDataGridViewControl", selectionDialog).TheObject;
                rowCount = grid.Rows.Count;
                DataGridView dataGridView = grid.Controls.OfType <DataGridView>().First();
                dataGridView[0, 1].Selected = true;

                new ButtonTester("Ok", selectionDialog).Click();
            };

            // Call
            AssessmentSection assessmentSection = assessmentSectionFromFileHandler.GetAssessmentSectionFromFile();

            // Assert
            Assert.AreEqual(3, rowCount);
            AssertAssessmentSection(TestAssessmentSection2_1(), assessmentSection);
            mockRepository.VerifyAll();
        }
示例#29
0
        public void GetMergeData_WithAssessmentSection_SetsDataOnDialog()
        {
            // Setup
            DialogBoxHandler = (formName, wnd) =>
            {
                using (new FormTester(formName)) {}
            };

            AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurationsAndSpecificFailureMechanisms();

            using (var dialogParent = new Form())
                using (var dialog = new AssessmentSectionMergeDataProviderDialog(dialogParent))
                {
                    // Call
                    dialog.GetMergeData(assessmentSection);

                    // Assert
                    var dataGridView = (DataGridView) new ControlTester("dataGridView", dialog).TheObject;
                    DataGridViewRowCollection rows = dataGridView.Rows;

                    int expectedNrOfRows = assessmentSection.GetFailureMechanisms().Count() +
                                           assessmentSection.SpecificFailureMechanisms.Count;
                    Assert.AreEqual(expectedNrOfRows, rows.Count);
                    AssertFailureMechanismRows(assessmentSection, rows);
                    AssertSpecificFailureMechanismRows(assessmentSection, rows);
                }
        }
示例#30
0
        public void AssembleAssessmentSection_AssessmentSectionContainingFailureMechanismsWithRandomInAssemblyState_SetsInputOnCalculator()
        {
            // Setup
            AssessmentSection assessmentSection = CreateAssessmentSectionContainingFailureMechanismsWithRandomInAssemblyState();

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismAssemblyCalculatorStub  failureMechanismAssemblyCalculator  = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;
                AssessmentSectionAssemblyCalculatorStub assessmentSectionAssemblyCalculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyCalculator;

                // Call
                AssessmentSectionAssemblyFactory.AssembleAssessmentSection(assessmentSection);

                // Assert
                FailureMechanismContribution contribution = assessmentSection.FailureMechanismContribution;
                Assert.AreEqual(contribution.SignalFloodingProbability, assessmentSectionAssemblyCalculator.SignalFloodingProbability);
                Assert.AreEqual(contribution.MaximumAllowableFloodingProbability, assessmentSectionAssemblyCalculator.MaximumAllowableFloodingProbabilityInput);

                int expectedNrOfProbabilities = assessmentSection.GetFailureMechanisms()
                                                .Concat(assessmentSection.SpecificFailureMechanisms)
                                                .Count(fp => fp.InAssembly);
                IEnumerable <double> calculatorInput = assessmentSectionAssemblyCalculator.FailureMechanismProbabilitiesInput;
                Assert.AreEqual(expectedNrOfProbabilities, calculatorInput.Count());
                foreach (double failureMechanismProbability in calculatorInput)
                {
                    Assert.AreEqual(failureMechanismAssemblyCalculator.AssemblyResultOutput.AssemblyResult, failureMechanismProbability);
                }
            }
        }