Index: Riskeer/Integration/src/Riskeer.Integration.Forms/Views/AssemblyResultTotalView.cs =================================================================== diff -u -r67bc709cc78154496005fd21344e1043eb4c1872 -r4705ff4ab5813dca45603ae25f5a9fcfab93fbd0 --- Riskeer/Integration/src/Riskeer.Integration.Forms/Views/AssemblyResultTotalView.cs (.../AssemblyResultTotalView.cs) (revision 67bc709cc78154496005fd21344e1043eb4c1872) +++ Riskeer/Integration/src/Riskeer.Integration.Forms/Views/AssemblyResultTotalView.cs (.../AssemblyResultTotalView.cs) (revision 4705ff4ab5813dca45603ae25f5a9fcfab93fbd0) @@ -26,11 +26,11 @@ using Core.Common.Base; using Core.Common.Controls.DataGrid; using Core.Common.Controls.Views; -using Core.Common.Util.Extensions; using Riskeer.ClosingStructures.Data; using Riskeer.Common.Data.Exceptions; using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.FailurePath; +using Riskeer.Common.Forms.Helpers; using Riskeer.DuneErosion.Data; using Riskeer.GrassCoverErosionInwards.Data; using Riskeer.GrassCoverErosionOutwards.Data; @@ -60,8 +60,6 @@ private readonly Observer assessmentSectionResultObserver; private IEnumerable assemblyResultRows; - private bool updateDataSource; - /// /// Creates a new instance of . /// @@ -79,21 +77,13 @@ InitializeComponent(); - assessmentSectionObserver = new Observer(() => + assessmentSectionObserver = new Observer(EnableRefreshButton) { - updateDataSource = true; - EnableRefreshButton(); - }) - { Observable = assessmentSection }; - assessmentSectionResultObserver = new Observer(() => + assessmentSectionResultObserver = new Observer(EnableRefreshButton) { - updateDataSource = true; - EnableRefreshButton(); - }) - { Observable = new AssessmentSectionResultObserver(assessmentSection) }; } @@ -163,22 +153,13 @@ assemblyResultRows = failureMechanismAssemblyResultRows; dataGridViewControl.SetDataSource(assemblyResultRows); - updateDataSource = false; } private void RefreshAssemblyResults_Click(object sender, EventArgs e) { ResetRefreshAssemblyResultsButton(); - if (updateDataSource) - { - SetDataSource(); - } - else - { - assemblyResultRows.ForEachElementDo(row => row.Update()); - dataGridViewControl.RefreshDataGridView(); - } + SetDataSource(); UpdateAssemblyResultControls(); } @@ -220,8 +201,7 @@ private IEnumerable CreateFailurePathResultRows() { return AssessmentSection.SpecificFailurePaths - .Select(fp => new FailureMechanismAssemblyResultRow(fp, - () => FailureMechanismAssemblyFactory.AssembleFailureMechanism(fp, AssessmentSection))) + .Select(fp => CreateRow(fp, () => FailureMechanismAssemblyFactory.AssembleFailureMechanism(fp, AssessmentSection))) .ToArray(); } @@ -251,70 +231,96 @@ }; } + private static FailureMechanismAssemblyResultRow CreateRow(IFailurePath failureMechanism, + Func performAssemblyFunc) + { + return failureMechanism.AssemblyResult.IsManualProbability() + ? CreateManualAssemblyRow(failureMechanism) + : CreateAutomaticAssemblyRow(failureMechanism, performAssemblyFunc); + } + + private static FailureMechanismAssemblyResultRow CreateManualAssemblyRow(IFailurePath failureMechanism) + { + FailurePathAssemblyResult assemblyResult = failureMechanism.AssemblyResult; + + string validationError = FailurePathAssemblyResultValidationHelper.GetValidationError(assemblyResult); + return !string.IsNullOrEmpty(validationError) + ? new FailureMechanismAssemblyResultRow(failureMechanism, validationError) + : new FailureMechanismAssemblyResultRow(failureMechanism, assemblyResult.ManualFailurePathAssemblyProbability); + } + + private static FailureMechanismAssemblyResultRow CreateAutomaticAssemblyRow(IFailurePath failureMechanism, + Func performAssemblyFunc) + { + try + { + double assemblyResult = performAssemblyFunc(); + return new FailureMechanismAssemblyResultRow(failureMechanism, assemblyResult); + } + catch (AssemblyException e) + { + return new FailureMechanismAssemblyResultRow(failureMechanism, e.Message); + } + } + private FailureMechanismAssemblyResultRow CreateClosingStructuresFailureMechanismAssemblyResultRow() { ClosingStructuresFailureMechanism closingStructures = AssessmentSection.ClosingStructures; - return new FailureMechanismAssemblyResultRow(closingStructures, - () => ClosingStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(closingStructures, AssessmentSection)); + return CreateRow(closingStructures, () => ClosingStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(closingStructures, AssessmentSection)); } private FailureMechanismAssemblyResultRow CreateHeightStructuresFailureMechanismAssemblyResultRow() { HeightStructuresFailureMechanism heightStructures = AssessmentSection.HeightStructures; - return new FailureMechanismAssemblyResultRow(heightStructures, - () => HeightStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(heightStructures, AssessmentSection)); + return CreateRow(heightStructures, () => HeightStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(heightStructures, AssessmentSection)); } private FailureMechanismAssemblyResultRow CreateStabilityPointsStructuresFailureMechanismAssemblyResultRow() { StabilityPointStructuresFailureMechanism stabilityPointStructures = AssessmentSection.StabilityPointStructures; - return new FailureMechanismAssemblyResultRow(stabilityPointStructures, - () => StabilityPointStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(stabilityPointStructures, AssessmentSection)); + return CreateRow(stabilityPointStructures, () => StabilityPointStructuresFailureMechanismAssemblyFactory.AssembleFailureMechanism(stabilityPointStructures, AssessmentSection)); } private FailureMechanismAssemblyResultRow CreateGrassCoverErosionInwardsFailureMechanismAssemblyResultRow() { GrassCoverErosionInwardsFailureMechanism grassCoverErosionInwards = AssessmentSection.GrassCoverErosionInwards; - return new FailureMechanismAssemblyResultRow(grassCoverErosionInwards, - () => GrassCoverErosionInwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(grassCoverErosionInwards, AssessmentSection)); + return CreateRow(grassCoverErosionInwards, () => GrassCoverErosionInwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(grassCoverErosionInwards, AssessmentSection)); } private FailureMechanismAssemblyResultRow CreatePipingFailureMechanismAssemblyResultRow() { PipingFailureMechanism piping = AssessmentSection.Piping; - return new FailureMechanismAssemblyResultRow(piping, - () => PipingFailureMechanismAssemblyFactory.AssembleFailureMechanism(piping, AssessmentSection)); + return CreateRow(piping, () => PipingFailureMechanismAssemblyFactory.AssembleFailureMechanism(piping, AssessmentSection)); } private FailureMechanismAssemblyResultRow CreateMacroStabilityInwardsFailureMechanismAssemblyResultRow() { MacroStabilityInwardsFailureMechanism macroStabilityInwards = AssessmentSection.MacroStabilityInwards; - return new FailureMechanismAssemblyResultRow(macroStabilityInwards, - () => MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(macroStabilityInwards, AssessmentSection)); + return CreateRow(macroStabilityInwards, () => MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(macroStabilityInwards, AssessmentSection)); } private FailureMechanismAssemblyResultRow CreateStabilityStoneCoverFailureMechanismAssemblyResultRow() { StabilityStoneCoverFailureMechanism stabilityStoneCover = AssessmentSection.StabilityStoneCover; - return new FailureMechanismAssemblyResultRow(stabilityStoneCover, () => StabilityStoneCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(stabilityStoneCover, AssessmentSection)); + return CreateRow(stabilityStoneCover, () => StabilityStoneCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(stabilityStoneCover, AssessmentSection)); } private FailureMechanismAssemblyResultRow CreateWaveImpactFailureMechanismAssemblyResultRow() { WaveImpactAsphaltCoverFailureMechanism waveImpactAsphaltCover = AssessmentSection.WaveImpactAsphaltCover; - return new FailureMechanismAssemblyResultRow(waveImpactAsphaltCover, () => WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(waveImpactAsphaltCover, AssessmentSection)); + return CreateRow(waveImpactAsphaltCover, () => WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(waveImpactAsphaltCover, AssessmentSection)); } private FailureMechanismAssemblyResultRow CreateGrassCoverErosionOutwardsFailureMechanismAssemblyResultRow() { GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwards = AssessmentSection.GrassCoverErosionOutwards; - return new FailureMechanismAssemblyResultRow(grassCoverErosionOutwards, () => GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(grassCoverErosionOutwards, AssessmentSection)); + return CreateRow(grassCoverErosionOutwards, () => GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(grassCoverErosionOutwards, AssessmentSection)); } private FailureMechanismAssemblyResultRow CreateDuneErosionFailureMechanismAssemblyResultRow() { DuneErosionFailureMechanism duneErosion = AssessmentSection.DuneErosion; - return new FailureMechanismAssemblyResultRow(duneErosion, () => DuneErosionFailureMechanismAssemblyFactory.AssembleFailureMechanism(duneErosion, AssessmentSection)); + return CreateRow(duneErosion, () => DuneErosionFailureMechanismAssemblyFactory.AssembleFailureMechanism(duneErosion, AssessmentSection)); } private FailureMechanismAssemblyResultRow CreateMicrostabilityFailureMechanismAssemblyResultRow() @@ -340,14 +346,13 @@ private FailureMechanismAssemblyResultRow CreatePipingStructureFailureMechanismAssemblyResultRow() { PipingStructureFailureMechanism pipingStructure = AssessmentSection.PipingStructure; - return new FailureMechanismAssemblyResultRow(pipingStructure, - () => PipingStructureFailureMechanismAssemblyFactory.AssembleFailureMechanism(pipingStructure, AssessmentSection)); + return CreateRow(pipingStructure, () => PipingStructureFailureMechanismAssemblyFactory.AssembleFailureMechanism(pipingStructure, AssessmentSection)); } private FailureMechanismAssemblyResultRow CreateStandAloneFailureMechanismAssemblyResultRow(TFailureMechanism failureMechanism) where TFailureMechanism : IHasGeneralInput, IFailurePath { - return new FailureMechanismAssemblyResultRow(failureMechanism, () => FailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, AssessmentSection)); + return CreateRow(failureMechanism, () => FailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, AssessmentSection)); } #endregion Index: Riskeer/Integration/src/Riskeer.Integration.Forms/Views/FailureMechanismAssemblyResultRow.cs =================================================================== diff -u -rc5b45071661b4a6c9365c661f19c01bed83e246f -r4705ff4ab5813dca45603ae25f5a9fcfab93fbd0 --- Riskeer/Integration/src/Riskeer.Integration.Forms/Views/FailureMechanismAssemblyResultRow.cs (.../FailureMechanismAssemblyResultRow.cs) (revision c5b45071661b4a6c9365c661f19c01bed83e246f) +++ Riskeer/Integration/src/Riskeer.Integration.Forms/Views/FailureMechanismAssemblyResultRow.cs (.../FailureMechanismAssemblyResultRow.cs) (revision 4705ff4ab5813dca45603ae25f5a9fcfab93fbd0) @@ -23,10 +23,8 @@ using System.Collections.Generic; using System.ComponentModel; using Core.Common.Controls.DataGrid; -using Riskeer.Common.Data.Exceptions; using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.FailurePath; -using Riskeer.Common.Forms.Helpers; using Riskeer.Common.Forms.TypeConverters; namespace Riskeer.Integration.Forms.Views @@ -39,37 +37,8 @@ { private const int probabilityIndex = 2; private readonly IFailurePath failureMechanism; - private readonly Func performAssemblyFunc; /// - /// Creates a new instance of . - /// - /// The to wrap so that it can be displayed as a row. - /// The used to assemble the result of a failure mechanism. - /// Thrown when any parameters is null. - public FailureMechanismAssemblyResultRow(IFailurePath failureMechanism, - Func performAssemblyFunc) - { - if (failureMechanism == null) - { - throw new ArgumentNullException(nameof(failureMechanism)); - } - - if (performAssemblyFunc == null) - { - throw new ArgumentNullException(nameof(performAssemblyFunc)); - } - - this.failureMechanism = failureMechanism; - this.performAssemblyFunc = performAssemblyFunc; - - ColumnStateDefinitions = new Dictionary(); - CreateColumnStateDefinitions(); - - Update(); - } - - /// /// Creates a new instance of with a default probability and an error message. /// /// The to wrap so that it can be displayed as a row. @@ -125,67 +94,13 @@ /// Gets the probability of the failure mechanism assembly. /// [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] - public double Probability { get; private set; } + public double Probability { get; } public IDictionary ColumnStateDefinitions { get; } - /// - /// Updates all data and states in the row. - /// - public void Update() - { - ResetErrorTexts(); - UpdateAssemblyData(); - } - - private void UpdateAssemblyData() - { - FailurePathAssemblyResult assemblyResult = failureMechanism.AssemblyResult; - if (assemblyResult.IsManualProbability()) - { - TryGetManualAssemblyData(assemblyResult); - } - else - { - TryGetAssemblyData(); - } - } - - private void TryGetManualAssemblyData(FailurePathAssemblyResult assemblyResult) - { - string validationError = FailurePathAssemblyResultValidationHelper.GetValidationError(assemblyResult); - if (!string.IsNullOrEmpty(validationError)) - { - Probability = double.NaN; - ColumnStateDefinitions[probabilityIndex].ErrorText = validationError; - } - else - { - Probability = assemblyResult.ManualFailurePathAssemblyProbability; - } - } - - private void TryGetAssemblyData() - { - try - { - Probability = performAssemblyFunc(); - } - catch (AssemblyException e) - { - Probability = double.NaN; - ColumnStateDefinitions[probabilityIndex].ErrorText = e.Message; - } - } - private void CreateColumnStateDefinitions() { ColumnStateDefinitions.Add(probabilityIndex, DataGridViewColumnStateDefinitionFactory.CreateReadOnlyColumnStateDefinition()); } - - private void ResetErrorTexts() - { - ColumnStateDefinitions[probabilityIndex].ErrorText = string.Empty; - } } } \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/FailureMechanismAssemblyResultRowTest.cs =================================================================== diff -u -rc5b45071661b4a6c9365c661f19c01bed83e246f -r4705ff4ab5813dca45603ae25f5a9fcfab93fbd0 --- Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/FailureMechanismAssemblyResultRowTest.cs (.../FailureMechanismAssemblyResultRowTest.cs) (revision c5b45071661b4a6c9365c661f19c01bed83e246f) +++ Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/FailureMechanismAssemblyResultRowTest.cs (.../FailureMechanismAssemblyResultRowTest.cs) (revision 4705ff4ab5813dca45603ae25f5a9fcfab93fbd0) @@ -25,7 +25,6 @@ using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; -using Riskeer.Common.Data.Exceptions; using Riskeer.Common.Data.FailurePath; using Riskeer.Common.Forms.TestUtil; using Riskeer.Common.Forms.TypeConverters; @@ -42,7 +41,7 @@ public void ConstructorWithErrorMessage_FailureMechanismNull_ThrowsArgumentNullException() { // Call - void Call() => new FailureMechanismAssemblyResultRow(null, () => double.NaN); + void Call() => new FailureMechanismAssemblyResultRow(null, string.Empty); // Assert var exception = Assert.Throws(Call); @@ -149,293 +148,5 @@ mocks.VerifyAll(); } - - [Test] - public void Constructor_WithArguments_ExpectedValues() - { - // Setup - const string failureMechanismName = "Failure Mechanism Name"; - const string failureMechanismCode = "Code"; - - var random = new Random(21); - double assemblyResult = random.NextDouble(); - - var mocks = new MockRepository(); - var failureMechanism = mocks.Stub(); - failureMechanism.Stub(fm => fm.Name).Return(failureMechanismName); - failureMechanism.Stub(fm => fm.Code).Return(failureMechanismCode); - failureMechanism.Stub(fm => fm.AssemblyResult).Return(new FailurePathAssemblyResult - { - ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic - }); - mocks.ReplayAll(); - - // Call - var row = new FailureMechanismAssemblyResultRow(failureMechanism, () => assemblyResult); - - // Assert - Assert.IsInstanceOf(row); - - TestHelper.AssertTypeConverter( - nameof(FailureMechanismAssemblyResultRow.Probability)); - - IDictionary columnStateDefinitions = row.ColumnStateDefinitions; - Assert.AreEqual(1, columnStateDefinitions.Count); - DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, probabilityIndex); - - Assert.AreEqual(failureMechanismName, row.Name); - Assert.AreEqual(failureMechanismCode, row.Code); - Assert.AreEqual(assemblyResult, row.Probability); - - mocks.VerifyAll(); - } - - [Test] - [TestCase(FailurePathAssemblyProbabilityResultType.Automatic, FailurePathAssemblyProbabilityResultType.Manual)] - [TestCase(FailurePathAssemblyProbabilityResultType.Manual, FailurePathAssemblyProbabilityResultType.Automatic)] - public void GivenRow_WhenChangingProbabilityResultTypeAndRowUpdated_ThenProbabilityUpdated( - FailurePathAssemblyProbabilityResultType initialResultType, - FailurePathAssemblyProbabilityResultType newResultType) - { - // Given - var random = new Random(21); - double manualAssemblyResult = random.NextDouble(); - double automaticAssemblyResult = random.NextDouble(); - - var assemblyResult = new FailurePathAssemblyResult - { - ProbabilityResultType = initialResultType, - ManualFailurePathAssemblyProbability = manualAssemblyResult - }; - - var mocks = new MockRepository(); - var failureMechanism = mocks.Stub(); - failureMechanism.Stub(fm => fm.AssemblyResult).Return(assemblyResult); - mocks.ReplayAll(); - - var row = new FailureMechanismAssemblyResultRow(failureMechanism, () => automaticAssemblyResult); - - // Precondition - double expectedProbability = assemblyResult.IsManualProbability() - ? manualAssemblyResult - : automaticAssemblyResult; - Assert.AreEqual(expectedProbability, row.Probability); - - // When - assemblyResult.ProbabilityResultType = newResultType; - row.Update(); - - // Then - expectedProbability = assemblyResult.IsManualProbability() - ? manualAssemblyResult - : automaticAssemblyResult; - Assert.AreEqual(expectedProbability, row.Probability); - mocks.VerifyAll(); - } - - #region ManualAssembly - - [Test] - public void GivenRowWithManualAssemblyResultAndWithoutError_WhenUpdatingAndInvalidAssemblyResult_ThenDefaultValueAndErrorSet() - { - // Given - var random = new Random(21); - double initialProbability = random.NextDouble(); - - var mocks = new MockRepository(); - var failureMechanism = mocks.Stub(); - var assemblyResult = new FailurePathAssemblyResult - { - ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Manual, - ManualFailurePathAssemblyProbability = initialProbability - }; - failureMechanism.Stub(fm => fm.AssemblyResult).Return(assemblyResult); - mocks.ReplayAll(); - - var row = new FailureMechanismAssemblyResultRow(failureMechanism, () => random.NextDouble()); - - // Precondition - Assert.IsEmpty(row.ColumnStateDefinitions[probabilityIndex].ErrorText); - Assert.AreEqual(initialProbability, row.Probability); - - // When - assemblyResult.ManualFailurePathAssemblyProbability = double.NaN; - row.Update(); - - // Then - Assert.AreEqual("Er moet een waarde worden ingevuld voor de faalkans.", row.ColumnStateDefinitions[probabilityIndex].ErrorText); - Assert.IsNaN(row.Probability); - mocks.VerifyAll(); - } - - [Test] - public void GivenRowWithManualAssemblyResultAndWithError_WhenUpdatingAndValidAssemblyResult_ThenValueSetAndErrorCleared() - { - // Given - var random = new Random(21); - - var mocks = new MockRepository(); - var failureMechanism = mocks.Stub(); - var assemblyResult = new FailurePathAssemblyResult - { - ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Manual, - ManualFailurePathAssemblyProbability = double.NaN - }; - failureMechanism.Stub(fm => fm.AssemblyResult).Return(assemblyResult); - mocks.ReplayAll(); - - var row = new FailureMechanismAssemblyResultRow(failureMechanism, () => random.NextDouble()); - - // Precondition - Assert.IsNotEmpty(row.ColumnStateDefinitions[probabilityIndex].ErrorText); - Assert.IsNaN(row.Probability); - - // When - double validProbability = random.NextDouble(); - assemblyResult.ManualFailurePathAssemblyProbability = validProbability; - row.Update(); - - // Then - Assert.IsEmpty(row.ColumnStateDefinitions[probabilityIndex].ErrorText); - Assert.AreEqual(validProbability, row.Probability); - mocks.VerifyAll(); - } - - #endregion - - #region AutomaticAssembly - - [Test] - public void GivenRowWithAutomaticAssemblyResult_WhenUpdating_ThenAssemblyFuncExecuted() - { - // Given - var random = new Random(21); - double initialProbability = random.NextDouble(); - double afterUpdateProbability = random.NextDouble(); - - var mocks = new MockRepository(); - var failureMechanism = mocks.Stub(); - failureMechanism.Stub(fm => fm.AssemblyResult).Return(new FailurePathAssemblyResult - { - ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic - }); - mocks.ReplayAll(); - - int i = 0; - Func performAssemblyFunc = () => - { - if (i == 0) - { - i++; - return initialProbability; - } - - return afterUpdateProbability; - }; - - var row = new FailureMechanismAssemblyResultRow(failureMechanism, performAssemblyFunc); - - // Precondition - Assert.AreEqual(initialProbability, row.Probability); - - // When - row.Update(); - - // Then - Assert.AreEqual(afterUpdateProbability, row.Probability); - mocks.VerifyAll(); - } - - [Test] - public void GivenRowWithAutomaticAssemblyResultAndWithoutError_WhenUpdatingAndAssemblyThrowsAssemblyException_ThenDefaultValueAndErrorSet() - { - // Given - const string exceptionMessage = "Something went wrong"; - - var random = new Random(21); - double initialProbability = random.NextDouble(); - - var mocks = new MockRepository(); - var failureMechanism = mocks.Stub(); - failureMechanism.Stub(fm => fm.AssemblyResult).Return(new FailurePathAssemblyResult - { - ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic - }); - mocks.ReplayAll(); - - int i = 0; - Func performAssemblyFunc = () => - { - if (i == 0) - { - i++; - return initialProbability; - } - - throw new AssemblyException(exceptionMessage); - }; - - var row = new FailureMechanismAssemblyResultRow(failureMechanism, performAssemblyFunc); - - // Precondition - Assert.IsEmpty(row.ColumnStateDefinitions[probabilityIndex].ErrorText); - Assert.AreEqual(initialProbability, row.Probability); - - // When - row.Update(); - - // Then - Assert.IsNaN(row.Probability); - Assert.AreEqual(exceptionMessage, row.ColumnStateDefinitions[probabilityIndex].ErrorText); - mocks.VerifyAll(); - } - - [Test] - public void GivenRowWithAutomaticAssemblyResultAndWithError_WhenUpdatingAndAssemblyRuns_ThenValueSetAndErrorCleared() - { - // Given - const string exceptionMessage = "Something went wrong"; - - var random = new Random(21); - double probability = random.NextDouble(); - - var mocks = new MockRepository(); - var failureMechanism = mocks.Stub(); - failureMechanism.Stub(fm => fm.AssemblyResult).Return(new FailurePathAssemblyResult - { - ProbabilityResultType = FailurePathAssemblyProbabilityResultType.Automatic - }); - mocks.ReplayAll(); - - int i = 0; - Func performAssemblyFunc = () => - { - if (i == 0) - { - i++; - throw new AssemblyException(exceptionMessage); - } - - return probability; - }; - - var row = new FailureMechanismAssemblyResultRow(failureMechanism, performAssemblyFunc); - - // Precondition - Assert.IsNaN(row.Probability); - Assert.AreEqual(exceptionMessage, row.ColumnStateDefinitions[probabilityIndex].ErrorText); - - // When - row.Update(); - - // Then - Assert.IsEmpty(row.ColumnStateDefinitions[probabilityIndex].ErrorText); - Assert.AreEqual(probability, row.Probability); - - mocks.VerifyAll(); - } - - #endregion } } \ No newline at end of file