Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/SectionResultRows/StrengthStabilityLengthwiseConstructionSectionResultRowTest.cs =================================================================== diff -u -r802d3cd39b925ac9873ea277588ecd1933e374f6 -r9b261d1aecde88dc1a0d996a274c040302cca40a --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/SectionResultRows/StrengthStabilityLengthwiseConstructionSectionResultRowTest.cs (.../StrengthStabilityLengthwiseConstructionSectionResultRowTest.cs) (revision 802d3cd39b925ac9873ea277588ecd1933e374f6) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/SectionResultRows/StrengthStabilityLengthwiseConstructionSectionResultRowTest.cs (.../StrengthStabilityLengthwiseConstructionSectionResultRowTest.cs) (revision 9b261d1aecde88dc1a0d996a274c040302cca40a) @@ -19,10 +19,25 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.Collections.Generic; +using System.Drawing; +using Core.Common.Base; +using Core.Common.Controls.DataGrid; +using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.AssemblyTool.Forms; +using Ringtoets.AssemblyTool.KernelWrapper.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.Helpers; +using Ringtoets.Common.Forms.TestUtil; using Ringtoets.Common.Forms.Views; +using Ringtoets.Common.Primitives; using Ringtoets.Integration.Data.StandAlone.SectionResults; using Ringtoets.Integration.Forms.Views.SectionResultRows; @@ -31,19 +46,427 @@ [TestFixture] public class StrengthStabilityLengthwiseConstructionSectionResultRowTest { + private static StrengthStabilityLengthwiseConstructionSectionResultRow.ConstructionProperties ConstructionProperties + { + get + { + return new StrengthStabilityLengthwiseConstructionSectionResultRow.ConstructionProperties + { + SimpleAssessmentResultIndex = 1, + TailorMadeAssessmentResultIndex = 2, + SimpleAssemblyCategoryGroupIndex = 3, + TailorMadeAssemblyCategoryGroupIndex = 4, + CombinedAssemblyCategoryGroupIndex = 5, + ManualAssemblyCategoryGroupIndex = 7 + }; + } + } + [Test] - public void Constructor_WithParameters_ExpectedValues() + public void Constructor_ConstructionPropertiesNull_ThrowsArgumentNullException() { // Setup FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section); // Call - var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result); + TestDelegate test = () => new StrengthStabilityLengthwiseConstructionSectionResultRow(result, null); // Assert - Assert.IsInstanceOf>(row); - Assert.AreEqual(result.SimpleAssessmentResult, row.SimpleAssessmentResult); + var exception = Assert.Throws(test); + Assert.AreEqual("constructionProperties", exception.ParamName); } + + [Test] + public void Constructor_WithParameters_ExpectedValues() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result, ConstructionProperties); + + // Assert + Assert.IsInstanceOf>(row); + Assert.AreEqual(result.SimpleAssessmentResult, row.SimpleAssessmentResult); + Assert.AreEqual(result.TailorMadeAssessmentResult, row.TailorMadeAssessmentResult); + Assert.AreEqual(result.UseManualAssemblyCategoryGroup, row.UseManualAssemblyCategoryGroup); + Assert.AreEqual(SelectableFailureMechanismSectionAssemblyCategoryGroupConverter.ConvertTo(result.ManualAssemblyCategoryGroup), + row.ManualAssemblyCategoryGroup); + + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + Assert.AreEqual(6, columnStateDefinitions.Count); + + FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.SimpleAssessmentResultIndex); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.TailorMadeAssessmentResultIndex); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.SimpleAssemblyCategoryGroupIndex); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.CombinedAssemblyCategoryGroupIndex); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.ManualAssemblyCategoryGroupIndex); + } + } + + [Test] + public void Constructor_AssemblyRan_ReturnCategoryGroups() + { + // Setup + var random = new Random(39); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.SimpleAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + calculator.TailorMadeAssemblyCategoryOutput = random.NextEnumValue(); + calculator.CombinedAssemblyCategoryOutput = random.NextEnumValue(); + + // Call + var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result, ConstructionProperties); + + // Assert + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.SimpleAssessmentAssemblyOutput.Group), + row.SimpleAssemblyCategoryGroup); + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.TailorMadeAssemblyCategoryOutput.Value), + row.TailorMadeAssemblyCategoryGroup); + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.CombinedAssemblyCategoryOutput.Value), + row.CombinedAssemblyCategoryGroup); + } + } + + [Test] + public void Constructor_AssemblyThrowsException_ExpectedColumnStates() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + + // Call + var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result, ConstructionProperties); + + // Assert + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + const string expectedErrorText = "Message"; + + Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex].ErrorText); + } + } + + [Test] + public void UseManualAssemblyCategoryGroup_SetNewValue_NotifyObserversAndPropertyChanged() + { + // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section); + result.Attach(observer); + + bool newValue = !result.UseManualAssemblyCategoryGroup; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result, ConstructionProperties); + + // Precondition + Assert.IsFalse(result.UseManualAssemblyCategoryGroup); + + // Call + row.UseManualAssemblyCategoryGroup = newValue; + + // Assert + Assert.AreEqual(newValue, result.UseManualAssemblyCategoryGroup); + mocks.VerifyAll(); + } + } + + [Test] + public void ManualAssemblyCategoryGroup_SetNewValue_NotifyObserversAndPropertyChanged() + { + // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var random = new Random(39); + var newValue = random.NextEnumValue(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section); + result.Attach(observer); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result, ConstructionProperties); + + // Call + row.ManualAssemblyCategoryGroup = newValue; + + // Assert + FailureMechanismSectionAssemblyCategoryGroup expectedCategoryGroup = SelectableFailureMechanismSectionAssemblyCategoryGroupConverter.ConvertFrom(newValue); + Assert.AreEqual(expectedCategoryGroup, result.ManualAssemblyCategoryGroup); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenRowWithoutAssemblyErrors_WhenUpdatingAndAssemblyThrowsException_ThenAssemblyGroupSetToNone() + { + // Given + var random = new Random(39); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.SimpleAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( + random.NextDouble(), + random.NextEnumValue()); + calculator.TailorMadeAssemblyCategoryOutput = random.NextEnumValue(); + calculator.CombinedAssemblyCategoryOutput = random.NextEnumValue(); + + var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result, ConstructionProperties); + + // Precondition + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.SimpleAssessmentAssemblyOutput.Group), + row.SimpleAssemblyCategoryGroup); + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.TailorMadeAssemblyCategoryOutput.Value), + row.TailorMadeAssemblyCategoryGroup); + Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.CombinedAssemblyCategoryOutput.Value), + row.CombinedAssemblyCategoryGroup); + + // When + calculator.ThrowExceptionOnCalculate = true; + row.SimpleAssessmentResult = SimpleAssessmentResultType.AssessFurther; + + // Then + string expectedAssemblyDisplayName = FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(FailureMechanismSectionAssemblyCategoryGroup.None); + Assert.AreEqual(expectedAssemblyDisplayName, row.SimpleAssemblyCategoryGroup); + Assert.AreEqual(expectedAssemblyDisplayName, row.TailorMadeAssemblyCategoryGroup); + Assert.AreEqual(expectedAssemblyDisplayName, row.CombinedAssemblyCategoryGroup); + } + } + + [Test] + public void GivenRowWithAssemblyErrors_WhenUpdatingAndAssemblyDoesNotThrowException_ThenExpectedColumnStates() + { + // Given + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + + var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result, ConstructionProperties); + + // Precondition + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + const string expectedErrorText = "Message"; + + Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex].ErrorText); + + // When + calculator.ThrowExceptionOnCalculate = false; + row.SimpleAssessmentResult = SimpleAssessmentResultType.AssessFurther; + + // Then + Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex].ErrorText); + Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex].ErrorText); + } + } + + #region Column States + + [Test] + [TestCase(SimpleAssessmentResultType.None, true)] + [TestCase(SimpleAssessmentResultType.AssessFurther, true)] + [TestCase(SimpleAssessmentResultType.NotApplicable, false)] + [TestCase(SimpleAssessmentResultType.ProbabilityNegligible, false)] + public void Constructor_WithSimpleAssessmentResultSet_ExpectedColumnStates(SimpleAssessmentResultType simpleAssessmentResult, + bool cellsEnabled) + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section) + { + SimpleAssessmentResult = simpleAssessmentResult + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result, ConstructionProperties); + + // Assert + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentResultIndex], + cellsEnabled); + } + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Constructor_WithUseManualAssemblyCategoryGroupSet_ExpectedColumnStates(bool useManualAssemblyCategoryGroup) + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section) + { + UseManualAssemblyCategoryGroup = useManualAssemblyCategoryGroup + }; + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result, ConstructionProperties); + + // Assert + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.SimpleAssessmentResultIndex], + !useManualAssemblyCategoryGroup); + + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentResultIndex], + !useManualAssemblyCategoryGroup); + + if (useManualAssemblyCategoryGroup) + { + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled( + columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled( + columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled( + columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex]); + } + + FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.ManualAssemblyCategoryGroupIndex], + useManualAssemblyCategoryGroup); + } + } + + [Test] + [TestCaseSource(typeof(FailureMechanismSectionResultRowTestHelper), nameof(FailureMechanismSectionResultRowTestHelper.CategoryGroupColorCases))] + public void Constructor_WithAssemblyCategoryGroupsSet_ExpectedColumnStates(FailureMechanismSectionAssemblyCategoryGroup assemblyCategoryGroup, + Color expectedBackgroundColor) + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + var assemblyOutput = new FailureMechanismSectionAssembly(0, assemblyCategoryGroup); + calculator.SimpleAssessmentAssemblyOutput = assemblyOutput; + calculator.TailorMadeAssemblyCategoryOutput = assemblyCategoryGroup; + calculator.CombinedAssemblyCategoryOutput = assemblyCategoryGroup; + + // Call + var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result, ConstructionProperties); + + // Assert + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; + + FailureMechanismSectionResultRowTestHelper.AssertColumnWithColorState(columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex], + expectedBackgroundColor); + FailureMechanismSectionResultRowTestHelper.AssertColumnWithColorState(columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex], + expectedBackgroundColor); + FailureMechanismSectionResultRowTestHelper.AssertColumnWithColorState(columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex], + expectedBackgroundColor); + } + } + + #endregion + + #region Registration + + [Test] + public void SimpleAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() + { + // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var random = new Random(39); + var newValue = random.NextEnumValue(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section); + result.Attach(observer); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result, ConstructionProperties); + + // Call + row.SimpleAssessmentResult = newValue; + + // Assert + Assert.AreEqual(newValue, result.SimpleAssessmentResult); + mocks.VerifyAll(); + } + } + + [Test] + public void TailorMadeAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() + { + // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var random = new Random(39); + var newValue = random.NextEnumValue(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var result = new StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult(section); + result.Attach(observer); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var row = new StrengthStabilityLengthwiseConstructionSectionResultRow(result, ConstructionProperties); + + // Call + row.TailorMadeAssessmentResult = newValue; + + // Assert + Assert.AreEqual(newValue, result.TailorMadeAssessmentResult); + mocks.VerifyAll(); + } + } + + #endregion } } \ No newline at end of file