public void Export_SoilProfileWithMultiplePreconsolidationStressesOnOneLayer_LogsWarningAndReturnsTrue() { // Setup string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_SoilProfileWithMultiplePreconsolidationStressesOnOneLayer_LogsWarningAndReturnsTrue)}.ValidFile.stix"); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.InputParameters.StochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[] { MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1)), MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 2)) }); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call var exportResult = false; void Call() => exportResult = exporter.Export(); // Assert var expectedMessage = $"'{calculation.Name}': De schematisatie van de berekening bevat meerdere stresspunten binnen één laag of stresspunten die niet aan een laag gekoppeld kunnen worden. Er worden daarom geen POP en grensspanningen geëxporteerd."; TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Warn)); Assert.IsTrue(exportResult); } } finally { File.Delete(filePath); } }
public void CreateInstance_ValidData_NewPropertiesWithOutputAsData() { // Setup var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var scenario = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var context = new MacroStabilityInwardsOutputContext(scenario, failureMechanism, assessmentSection); // Call IObjectProperties objectProperties = info.CreateInstance(context); // Assert Assert.IsInstanceOf <MacroStabilityInwardsOutputProperties>(objectProperties); Assert.AreSame(scenario.Output, objectProperties.Data); mocks.VerifyAll(); }
public void Export_MaximumSliceWidthNotOne_LogsWarningAndReturnsTrue(double maximumSliceWidth) { // Setup string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_MaximumSliceWidthNotOne_LogsWarningAndReturnsTrue)}.ValidFile.stix"); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.InputParameters.MaximumSliceWidth = (RoundedDouble)maximumSliceWidth; calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call var exportResult = false; void Call() => exportResult = exporter.Export(); // Assert var expectedMessage = $"'{calculation.Name}': De berekening bevat een lamelbreedte van {calculation.InputParameters.MaximumSliceWidth.ToString(null, CultureInfo.CurrentCulture)} meter. D-GEO Suite Stability ondersteunt enkel een maximale lamelbreedte van 1 meter. Er wordt daarom een lamelbreedte van 1 meter geëxporteerd."; TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Warn)); Assert.IsTrue(exportResult); } } finally { File.Delete(filePath); } }
public void Export_SoilProfileWithMultipleAquiferLayers_LogsWarningAndReturnsTrue() { // Setup string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_MaximumSliceWidthNotOne_LogsWarningAndReturnsTrue)}.ValidFile.stix"); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.InputParameters.StochasticSoilProfile.SoilProfile.Layers.ForEachElementDo(layer => layer.Data.IsAquifer = true); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call var exportResult = false; void Call() => exportResult = exporter.Export(); // Assert var expectedMessage = $"'{calculation.Name}': De schematisatie van de berekening bevat meerdere aquifer lagen. De volgorde van de aquifer lagen kan niet bepaald worden tijdens exporteren. Er worden daarom geen lagen als aquifer geëxporteerd."; TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Warn)); Assert.IsTrue(exportResult); } } finally { File.Delete(filePath); } }
public void Export_RunsSuccessful_WritesFileAndRemovesTempFile() { // Setup string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_RunsSuccessful_WritesFileAndRemovesTempFile)}.ValidFile.stix"); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); try { using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call bool exportResult = exporter.Export(); // Assert Assert.IsTrue(exportResult); Assert.IsTrue(File.Exists(filePath)); Assert.IsFalse(File.Exists($"{filePath}.temp")); } } finally { File.Delete(filePath); } }
public void Export_PersistenceFactoryThrowsException_NoFileWritten() { // Setup string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_PersistenceFactoryThrowsException_NoFileWritten)}.ValidFile.stix"); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); using (new MacroStabilityInwardsCalculatorFactoryConfig()) { var persistenceFactory = new MacroStabilityInwardsTestPersistenceFactory { ThrowException = true, WriteFile = true }; var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), persistenceFactory, filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); // Call exporter.Export(); // Assert Assert.IsFalse(File.Exists(filePath)); Assert.IsFalse(File.Exists($"{filePath}.temp")); } }
public void Export_PersistenceFactoryThrowsException_LogsErrorAndReturnsFalse() { // Setup const string filePath = "ValidFilePath"; MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); using (new MacroStabilityInwardsCalculatorFactoryConfig()) { var persistenceFactory = new MacroStabilityInwardsTestPersistenceFactory { ThrowException = true }; var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), persistenceFactory, filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); // Call var exportResult = true; void Call() => exportResult = exporter.Export(); // Assert string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'. Er is geen D-GEO Suite Stability Project geëxporteerd."; TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Error)); Assert.IsFalse(exportResult); } }
public void GivenScenarioRow_WhenOutputSetToNullAndUpdate_ThenDerivedOutputUpdated() { // Given var calculation = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput() }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); FailureMechanismSection failureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var row = new MacroStabilityInwardsScenarioRow(calculation, failureMechanism, failureMechanismSection); // Precondition DerivedMacroStabilityInwardsOutput expectedDerivedOutput = DerivedMacroStabilityInwardsOutputFactory.Create(calculation.Output, failureMechanism.GeneralInput.ModelFactor); Assert.AreEqual(expectedDerivedOutput.MacroStabilityInwardsProbability, row.FailureProbability); Assert.AreEqual(expectedDerivedOutput.MacroStabilityInwardsProbability * failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.GetN( failureMechanismSection.Length), row.SectionFailureProbability); // When calculation.Output = null; row.Update(); // Then Assert.IsNaN(row.FailureProbability); Assert.IsNaN(row.SectionFailureProbability); }
public void IsEnabled_CalculationGroupChildIsNestedGroupWithCalculationWithAndWithoutOutput_ReturnTrue() { // Setup var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var calculation = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var nestedGroup = new CalculationGroup(); nestedGroup.Children.Add(calculation); nestedGroup.Children.Add(new MacroStabilityInwardsCalculationScenario()); var calculationGroup = new CalculationGroup(); calculationGroup.Children.Add(nestedGroup); var context = new MacroStabilityInwardsCalculationGroupContext(calculationGroup, null, Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), new MacroStabilityInwardsFailureMechanism(), assessmentSection); // Call bool isEnabled = info.IsEnabled(context); // Assert Assert.IsTrue(isEnabled); }
public void Constructor_WithCalculationWithOutput_PropertiesFromCalculation(double sectionLength) { // Setup var calculation = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(new MacroStabilityInwardsOutput.ConstructionProperties { FactorOfStability = 0.1 }) }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var failureMechanismSection = new FailureMechanismSection("test", new[] { new Point2D(0, 0), new Point2D(sectionLength, 0) }); // Call var row = new MacroStabilityInwardsScenarioRow(calculation, failureMechanism, failureMechanismSection); // Assert DerivedMacroStabilityInwardsOutput expectedDerivedOutput = DerivedMacroStabilityInwardsOutputFactory.Create(calculation.Output, failureMechanism.GeneralInput.ModelFactor); Assert.AreEqual(expectedDerivedOutput.MacroStabilityInwardsProbability, row.FailureProbability); Assert.AreEqual(Math.Min(1.0, expectedDerivedOutput.MacroStabilityInwardsProbability * failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.GetN( failureMechanismSection.Length)), row.SectionFailureProbability); }
public void Create_WithValidData_ReturnsPersistableCalculationSettingsCollection() { // Setup MacroStabilityInwardsSlidingCurve slidingCurve = MacroStabilityInwardsOutputTestFactory.CreateOutput().SlidingCurve; var idFactory = new IdFactory(); var registry = new MacroStabilityInwardsExportRegistry(); // Call IEnumerable <PersistableCalculationSettings> settingsCollection = PersistableCalculationSettingsFactory.Create(slidingCurve, idFactory, registry); // Assert PersistableDataModelTestHelper.AssertCalculationSettings(slidingCurve, settingsCollection); var stages = new[] { MacroStabilityInwardsExportStageType.Daily, MacroStabilityInwardsExportStageType.Extreme }; Assert.AreEqual(2, registry.Settings.Count); for (var i = 0; i < stages.Length; i++) { Assert.AreEqual(registry.Settings[stages[i]], settingsCollection.ElementAt(i).Id); } }
public void GivenCalculationWithStochasticSoilProfileAndSurfaceLine_WhenStochasticSoilProfileUpdate_ThenChartDataUpdated() { // Given MacroStabilityInwardsStochasticSoilProfile originalSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(); var calculation = new MacroStabilityInwardsCalculationScenario { InputParameters = { StochasticSoilProfile = originalSoilProfile, SurfaceLine = GetSurfaceLineWithGeometry() }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; using (new MacroStabilityInwardsCalculatorFactoryConfig()) using (var control = new MacroStabilityInwardsOutputChartControl(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel)) { ChartDataCollection chartData = GetChartControl(control).Data; // Precondition MacroStabilityInwardsOutputViewChartDataAssert.AssertInputChartData(calculation, chartData); MacroStabilityInwardsStochasticSoilProfile newSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(); // When calculation.InputParameters.StochasticSoilProfile = newSoilProfile; control.UpdateChartData(); // Then MacroStabilityInwardsOutputViewChartDataAssert.AssertInputChartData(calculation, chartData); } }
public void Constructor_CalculationWithOutput_ChartDataSet() { // Setup MacroStabilityInwardsSurfaceLine surfaceLine = GetSurfaceLineWithGeometry(); MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(); var calculation = new MacroStabilityInwardsCalculationScenario { InputParameters = { SurfaceLine = surfaceLine, StochasticSoilProfile = stochasticSoilProfile }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; // Call using (new MacroStabilityInwardsCalculatorFactoryConfig()) using (var control = new MacroStabilityInwardsOutputChartControl(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel)) { // Assert IChartControl chartControl = GetChartControl(control); ChartDataCollection chartData = chartControl.Data; MacroStabilityInwardsOutputViewChartDataAssert.AssertInputChartData(calculation, chartData); MacroStabilityInwardsOutputViewChartDataAssert.AssertOutputChartData(calculation, chartData); Assert.AreEqual(calculation.Name, chartControl.ChartTitle); } }
public void GivenCalculationWithOutput_WhenClearingOutputFromContextMenu_ThenCalculationOutputClearedAndNotified(bool confirm) { // Given using (var treeViewControl = new TreeViewControl()) { var calculation = new MacroStabilityInwardsCalculationScenario(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var calculationContext = new MacroStabilityInwardsCalculationScenarioContext(calculation, new CalculationGroup(), Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); var observer = mocks.StrictMock <IObserver>(); if (confirm) { observer.Expect(o => o.UpdateObserver()); } mocks.ReplayAll(); plugin.Gui = gui; calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); calculation.Attach(observer); string messageBoxText = null, messageBoxTitle = null; DialogBoxHandler = (name, wnd) => { var messageBox = new MessageBoxTester(wnd); messageBoxText = messageBox.Text; messageBoxTitle = messageBox.Title; if (confirm) { messageBox.ClickOk(); } else { messageBox.ClickCancel(); } }; using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(calculationContext, null, treeViewControl)) { // When contextMenuStrip.Items[contextMenuClearIndex].PerformClick(); // Then Assert.AreNotEqual(confirm, calculation.HasOutput); Assert.AreEqual("Bevestigen", messageBoxTitle); Assert.AreEqual("Weet u zeker dat u de uitvoer van deze berekening wilt wissen?", messageBoxText); } } }
public void GivenViewWithWaternets_WhenWaternetSetEmpty_ThenNoChartData() { // Setup MacroStabilityInwardsStochasticSoilProfile originalSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(); var calculation = new MacroStabilityInwardsCalculationScenario { InputParameters = { StochasticSoilProfile = originalSoilProfile, SurfaceLine = GetSurfaceLineWithGeometry() }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; using (new MacroStabilityInwardsCalculatorFactoryConfig()) using (var control = new MacroStabilityInwardsOutputChartControl(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel)) { // Precondition MacroStabilityInwardsOutputViewChartDataAssert.AssertInputChartData(calculation, GetChartControl(control).Data); var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance; calculatorFactory.LastCreatedWaternetDailyCalculator.Output = WaternetCalculatorResultTestFactory.CreateEmptyResult(); calculatorFactory.LastCreatedWaternetExtremeCalculator.Output = WaternetCalculatorResultTestFactory.CreateEmptyResult(); // Call control.UpdateChartData(); // Assert MacroStabilityInwardsOutputViewChartDataAssert.AssertEmptyWaternetChartData(GetChartControl(control).Data); } }
public void GivenViewWithOutputSet_WhenOutputCleared_ThenTableCleared() { // Given var calculation = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; using (var view = new MacroStabilityInwardsOutputView(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel)) { MacroStabilityInwardsSlicesTable slicesTable = GetSlicesTable(view); // Precondition Assert.AreEqual(3, slicesTable.Rows.Count); // When calculation.ClearOutput(); calculation.NotifyObservers(); // Then Assert.AreEqual(0, slicesTable.Rows.Count); } }
private static void AssertPropertyChangeWithOrWithoutCalculationOutput( Action <MacroStabilityInwardsCalculationRow> setProperty, Action <MacroStabilityInwardsCalculationScenario> assertions, bool hasOutput, bool expectUpdates) { // Setup var mockRepository = new MockRepository(); var inputObserver = mockRepository.StrictMock <IObserver>(); if (expectUpdates) { inputObserver.Expect(o => o.UpdateObserver()); } var calculationObserver = mockRepository.StrictMock <IObserver>(); if (expectUpdates && hasOutput) { calculationObserver.Expect(o => o.UpdateObserver()); } var handler = mockRepository.Stub <IObservablePropertyChangeHandler>(); mockRepository.ReplayAll(); MacroStabilityInwardsOutput assignedOutput = null; MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); if (hasOutput) { assignedOutput = MacroStabilityInwardsOutputTestFactory.CreateOutput(); } calculation.Output = assignedOutput; var row = new MacroStabilityInwardsCalculationRow(calculation, handler); calculation.Attach(calculationObserver); calculation.InputParameters.Attach(inputObserver); // Call setProperty(row); // Assert assertions(calculation); if (expectUpdates) { Assert.IsNull(calculation.Output); } else { Assert.AreSame(assignedOutput, calculation.Output); } mockRepository.VerifyAll(); }
public void Create_RegistryNull_ThrowsArgumentNullException() { // Call void Call() => PersistableCalculationSettingsFactory.Create(MacroStabilityInwardsOutputTestFactory.CreateOutput().SlidingCurve, new IdFactory(), null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("registry", exception.ParamName); }
public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed) { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var mainWindow = mocks.Stub <IMainWindow>(); var gui = mocks.Stub <IGui>(); gui.Stub(g => g.MainWindow).Return(mainWindow); mocks.ReplayAll(); plugin.Gui = gui; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var calculationWithOutput = new MacroStabilityInwardsCalculationScenario { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; failureMechanism.CalculationsGroup.Children.Add(calculationWithOutput); var stochasticSoilModelCollection = new MacroStabilityInwardsStochasticSoilModelCollection(); var context = new MacroStabilityInwardsStochasticSoilModelCollectionContext(stochasticSoilModelCollection, failureMechanism, assessmentSection); string textBoxMessage = null; DialogBoxHandler = (name, wnd) => { var helper = new MessageBoxTester(wnd); textBoxMessage = helper.Text; if (isActionConfirmed) { helper.ClickOk(); } else { helper.ClickCancel(); } }; // Call bool updatesVerified = importInfo.VerifyUpdates(context); // Assert string expectedInquiryMessage = "Als u stochastische ondergrondmodellen importeert, " + "dan worden alle rekenresultaten van dit faalmechanisme verwijderd." + $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; Assert.AreEqual(expectedInquiryMessage, textBoxMessage); Assert.AreEqual(isActionConfirmed, updatesVerified); mocks.VerifyAll(); }
public void CalculationsView_EditingPropertyViaDataGridView_ObserversCorrectlyNotified( int cellIndex, object newValue, bool useCalculationWithOutput) { // Setup var mocks = new MockRepository(); var calculationObserver = mocks.StrictMock <IObserver>(); var calculationInputObserver = mocks.StrictMock <IObserver>(); if (useCalculationWithOutput) { DialogBoxHandler = (name, wnd) => { var tester = new MessageBoxTester(wnd); tester.ClickOk(); }; calculationObserver.Expect(o => o.UpdateObserver()); } calculationInputObserver.Expect(o => o.UpdateObserver()); var assessmentSection = mocks.Stub <IAssessmentSection>(); ConfigureHydraulicBoundaryDatabase(assessmentSection); assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); mocks.ReplayAll(); MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailureMechanism(); CalculationGroup calculationGroup = ConfigureCalculationGroup(assessmentSection, failureMechanism); ShowMacroStabilityInwardsCalculationsView(calculationGroup, failureMechanism, assessmentSection); var calculation = (MacroStabilityInwardsCalculationScenario)calculationGroup.Children[1]; if (useCalculationWithOutput) { calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); } calculation.Attach(calculationObserver); calculation.InputParameters.Attach(calculationInputObserver); var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; // Call dataGridView.Rows[1].Cells[cellIndex].Value = newValue is double value ? (RoundedDouble)value : newValue; // Assert Assert.IsNull(calculation.Output); mocks.VerifyAll(); }
public void Constructor_ExpectedValues() { // Setup MacroStabilityInwardsOutput output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); // Call var properties = new MacroStabilityInwardsOutputProperties(output, 1.1); // Assert Assert.IsInstanceOf <ObjectProperties <MacroStabilityInwardsOutput> >(properties); Assert.AreSame(output, properties.Data); }
private static MacroStabilityInwardsCalculationScenario CreateCalculation(string calculationName, bool setOutput = true) { MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.Name = calculationName; if (setOutput) { calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); } return(calculation); }
public void Clone_AllPropertiesSet_ReturnNewInstanceWithCopiedValues() { // Setup MacroStabilityInwardsCalculation original = CreateRandomCalculationWithoutOutput(); original.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); // Call object clone = original.Clone(); // Assert CoreCloneAssert.AreObjectClones(original, clone, MacroStabilityInwardsCloneAssert.AreClones); }
public void UpdateSurfaceLinesWithImportedData_CalculationWithSameReferences_OnlyReturnsDistinctCalculation() { // Setup const string updatedSurfaceLineName = "Name A"; var affectedSurfaceLine = new MacroStabilityInwardsSurfaceLine(updatedSurfaceLineName); affectedSurfaceLine.SetGeometry(new[] { new Point3D(1, 2, 3), new Point3D(4, 5, 6) }); var affectedCalculation = new MacroStabilityInwardsCalculation { InputParameters = { SurfaceLine = affectedSurfaceLine }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(affectedCalculation); failureMechanism.CalculationsGroup.Children.Add(affectedCalculation); failureMechanism.SurfaceLines.AddRange(new[] { affectedSurfaceLine }, "path"); MacroStabilityInwardsSurfaceLine importedSurfaceLine = DeepCloneAndModifyPoints(affectedSurfaceLine); var strategy = new MacroStabilityInwardsSurfaceLineUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(new[] { importedSurfaceLine }, "path").ToArray(); // Assert CollectionAssert.AreEquivalent(new IObservable[] { failureMechanism.SurfaceLines, affectedSurfaceLine, affectedCalculation, affectedCalculation.InputParameters }, affectedObjects); }
public void ShouldCalculate_OutputSet_ReturnsFalse() { // Setup var calculation = new MacroStabilityInwardsCalculation { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; // Call bool shouldCalculate = calculation.ShouldCalculate; // Assert Assert.IsFalse(shouldCalculate); }
public void HasOutput_OutputSet_ReturnsTrue() { // Setup var calculation = new MacroStabilityInwardsCalculation { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; // Call bool hasOutput = calculation.HasOutput; // Assert Assert.IsTrue(hasOutput); }
public void ClearOutput_Always_SetsOutputToNull() { // Setup var calculation = new MacroStabilityInwardsCalculation { Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; // Call calculation.ClearOutput(); // Assert Assert.IsNull(calculation.Output); }
public void Create_ValidData_ReturnsExpectedValue() { // Setup MacroStabilityInwardsOutput output = MacroStabilityInwardsOutputTestFactory.CreateOutput(new MacroStabilityInwardsOutput.ConstructionProperties { FactorOfStability = new Random(21).NextDouble() }); // Call DerivedMacroStabilityInwardsOutput derivedOutput = DerivedMacroStabilityInwardsOutputFactory.Create(output, 1.1); // Assert Assert.AreEqual(output.FactorOfStability, derivedOutput.FactorOfStability, derivedOutput.FactorOfStability.GetAccuracy()); Assert.AreEqual(0.067853, derivedOutput.MacroStabilityInwardsProbability, 1e-6); Assert.AreEqual(1.49197, derivedOutput.MacroStabilityInwardsReliability, derivedOutput.MacroStabilityInwardsReliability.GetAccuracy()); }
public void Create_WithValidData_ReturnsPersistableDataModel() { // Setup const string filePath = "ValidFilePath"; MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel, filePath); // Assert PersistableDataModelTestHelper.AssertPersistableDataModel(calculation, filePath, persistableDataModel); } }
public void UpdateSurfaceLinesWithImportedData_CalculationWithOutputSurfaceLine_CalculationUpdatedAndReturnsAffectedObject() { // Setup var existingSurfaceLine = new MacroStabilityInwardsSurfaceLine(string.Empty); existingSurfaceLine.SetGeometry(new[] { new Point3D(0, 1, 2), new Point3D(3, 4, 5) }); var calculation = new MacroStabilityInwardsCalculationScenario { InputParameters = { SurfaceLine = existingSurfaceLine }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.SurfaceLines.AddRange(new[] { existingSurfaceLine }, sourceFilePath); failureMechanism.CalculationsGroup.Children.Add(calculation); var strategy = new MacroStabilityInwardsSurfaceLineReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), sourceFilePath).ToArray(); // Assert Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.SurfaceLine); CollectionAssert.AreEquivalent(new IObservable[] { calculation, calculation.InputParameters, failureMechanism.SurfaceLines }, affectedObjects); }