// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // 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.KernelWrapper.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; using Ringtoets.ClosingStructures.Data; using Ringtoets.ClosingStructures.Data.TestUtil; using Ringtoets.ClosingStructures.Forms.Views; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.TestUtil; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Primitives; namespace Ringtoets.ClosingStructures.Forms.Test.Views { [TestFixture] public class ClosingStructuresFailureMechanismSectionResultRowTest { private static ClosingStructuresFailureMechanismSectionResultRow.ConstructionProperties ConstructionProperties { get { return new ClosingStructuresFailureMechanismSectionResultRow.ConstructionProperties { SimpleAssessmentResultIndex = 1, DetailedAssessmentResultIndex = 2, DetailedAssessmentProbabilityIndex = 3, TailorMadeAssessmentResultIndex = 4, TailorMadeAssessmentProbabilityIndex = 5, SimpleAssemblyCategoryGroupIndex = 6, DetailedAssemblyCategoryGroupIndex = 7, TailorMadeAssemblyCategoryGroupIndex = 8, CombinedAssemblyCategoryGroupIndex = 9, CombinedAssemblyProbabilityIndex = 10, ManualAssemblyProbabilityIndex = 11 }; } } [Test] public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); // Call TestDelegate call = () => new ClosingStructuresFailureMechanismSectionResultRow(result, null, assessmentSection, ConstructionProperties); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanism", exception.ParamName); mocks.VerifyAll(); } [Test] public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() { // Setup FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); // Call TestDelegate call = () => new ClosingStructuresFailureMechanismSectionResultRow(result, new ClosingStructuresFailureMechanism(), null, ConstructionProperties); // Assert var exception = Assert.Throws(call); Assert.AreEqual("assessmentSection", exception.ParamName); } [Test] public void Constructor_ConstructionPropertiesNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); // Call TestDelegate call = () => new ClosingStructuresFailureMechanismSectionResultRow(result, new ClosingStructuresFailureMechanism(), assessmentSection, null); // Assert var exception = Assert.Throws(call); Assert.AreEqual("constructionProperties", exception.ParamName); mocks.VerifyAll(); } [Test] public void Constructor_WithParameters_ExpectedValues() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section) { Calculation = CreateCalculationWithOutput() }; // Call using (new AssemblyToolCalculatorFactoryConfig()) { var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection, ConstructionProperties); // Assert Assert.IsInstanceOf>(row); Assert.AreEqual(result.SimpleAssessmentResult, row.SimpleAssessmentResult); Assert.AreEqual(result.DetailedAssessmentResult, row.DetailedAssessmentResult); Assert.AreEqual(result.GetDetailedAssessmentProbability(failureMechanism, assessmentSection), row.DetailedAssessmentProbability); Assert.AreEqual(result.TailorMadeAssessmentResult, row.TailorMadeAssessmentResult); Assert.AreEqual(result.TailorMadeAssessmentProbability, row.TailorMadeAssessmentProbability); Assert.AreEqual(result.UseManualAssemblyProbability, row.UseManualAssemblyProbability); Assert.AreEqual(result.ManualAssemblyProbability, row.ManualAssemblyProbability); TestHelper.AssertTypeConverter( nameof(ClosingStructuresFailureMechanismSectionResultRow.DetailedAssessmentProbability)); TestHelper.AssertTypeConverter( nameof(ClosingStructuresFailureMechanismSectionResultRow.TailorMadeAssessmentProbability)); TestHelper.AssertTypeConverter( nameof(ClosingStructuresFailureMechanismSectionResultRow.CombinedAssemblyProbability)); TestHelper.AssertTypeConverter( nameof(ClosingStructuresFailureMechanismSectionResultRow.ManualAssemblyProbability)); IDictionary columnStateDefinitions = row.ColumnStateDefinitions; Assert.AreEqual(11, columnStateDefinitions.Count); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.SimpleAssessmentResultIndex); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.DetailedAssessmentResultIndex); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.DetailedAssessmentProbabilityIndex); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.TailorMadeAssessmentResultIndex); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.TailorMadeAssessmentProbabilityIndex); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.SimpleAssemblyCategoryGroupIndex); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.DetailedAssemblyCategoryGroupIndex); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.CombinedAssemblyCategoryGroupIndex); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.CombinedAssemblyProbabilityIndex); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.ManualAssemblyProbabilityIndex); mocks.VerifyAll(); } } [Test] public void Constructor_AssemblyRan_ReturnCategoryGroups() { // Setup var random = new Random(39); var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; calculator.SimpleAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( random.NextDouble(), random.NextEnumValue()); calculator.DetailedAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( random.NextDouble(), random.NextEnumValue()); calculator.TailorMadeAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( random.NextDouble(), random.NextEnumValue()); calculator.CombinedAssemblyOutput = new FailureMechanismSectionAssembly( random.NextDouble(), random.NextEnumValue()); // Call var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection, ConstructionProperties); // Assert Assert.AreEqual(FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(calculator.SimpleAssessmentAssemblyOutput.Group), row.SimpleAssemblyCategoryGroup); Assert.AreEqual(FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(calculator.DetailedAssessmentAssemblyOutput.Group), row.DetailedAssemblyCategoryGroup); Assert.AreEqual(FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(calculator.TailorMadeAssessmentAssemblyOutput.Group), row.TailorMadeAssemblyCategoryGroup); Assert.AreEqual(FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(calculator.CombinedAssemblyOutput.Group), row.CombinedAssemblyCategoryGroup); Assert.AreEqual(calculator.CombinedAssemblyOutput.Probability, row.CombinedAssemblyProbability); mocks.VerifyAll(); } } [Test] public void UseManualAssemblyProbability_SetNewValue_NotifyObserversAndPropertyChanged() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); result.Attach(observer); using (new AssemblyToolCalculatorFactoryConfig()) { var row = new ClosingStructuresFailureMechanismSectionResultRow( result, failureMechanism, assessmentSection, ConstructionProperties); bool originalValue = result.UseManualAssemblyProbability; bool newValue = !originalValue; // Call row.UseManualAssemblyProbability = newValue; // Assert Assert.AreEqual(newValue, result.UseManualAssemblyProbability); mocks.VerifyAll(); } } [Test] [TestCase(0)] [TestCase(1)] [TestCase(0.5)] [TestCase(1e-6)] [TestCase(double.NaN)] public void ManualAssemblyProbability_ValidValue_NotifyObserversAndPropertyChanged(double value) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); result.Attach(observer); using (new AssemblyToolCalculatorFactoryConfig()) { var row = new ClosingStructuresFailureMechanismSectionResultRow( result, failureMechanism, assessmentSection, ConstructionProperties); // Call row.ManualAssemblyProbability = value; // Assert Assert.AreEqual(value, row.ManualAssemblyProbability); mocks.VerifyAll(); } } [Test] [SetCulture("nl-NL")] [TestCase(-20)] [TestCase(-1e-6)] [TestCase(1 + 1e-6)] [TestCase(12)] public void ManualAssemblyProbability_InvalidValue_ThrowsArgumentOutOfRangeException(double value) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); using (new AssemblyToolCalculatorFactoryConfig()) { var row = new ClosingStructuresFailureMechanismSectionResultRow( result, failureMechanism, assessmentSection, ConstructionProperties); // Call TestDelegate test = () => row.ManualAssemblyProbability = value; // Assert const string expectedMessage = "De waarde voor de faalkans moet in het bereik [0,0, 1,0] liggen."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); mocks.VerifyAll(); } } [Test] public void GivenRowWithoutAssemblyErrors_WhenUpdatingAndAssemblyThrowsException_ThenAssemblyGroupSetToNone() { // Given var random = new Random(39); var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; calculator.SimpleAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( random.NextDouble(), random.NextEnumValue()); calculator.DetailedAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( random.NextDouble(), random.NextEnumValue()); calculator.TailorMadeAssessmentAssemblyOutput = new FailureMechanismSectionAssembly( random.NextDouble(), random.NextEnumValue()); calculator.CombinedAssemblyOutput = new FailureMechanismSectionAssembly( random.NextDouble(), random.NextEnumValue()); var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection, ConstructionProperties); // Precondition Assert.AreEqual(FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(calculator.SimpleAssessmentAssemblyOutput.Group), row.SimpleAssemblyCategoryGroup); Assert.AreEqual(FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(calculator.DetailedAssessmentAssemblyOutput.Group), row.DetailedAssemblyCategoryGroup); Assert.AreEqual(FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(calculator.TailorMadeAssessmentAssemblyOutput.Group), row.TailorMadeAssemblyCategoryGroup); Assert.AreEqual(FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(calculator.CombinedAssemblyOutput.Group), row.CombinedAssemblyCategoryGroup); Assert.AreEqual(calculator.CombinedAssemblyOutput.Probability, row.CombinedAssemblyProbability); // When calculator.ThrowExceptionOnCalculate = true; row.SimpleAssessmentResult = SimpleAssessmentResultType.AssessFurther; // Then string expectedAssemblyDisplayName = FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(FailureMechanismSectionAssemblyCategoryGroup.None); Assert.AreEqual(expectedAssemblyDisplayName, row.SimpleAssemblyCategoryGroup); Assert.AreEqual(expectedAssemblyDisplayName, row.DetailedAssemblyCategoryGroup); Assert.AreEqual(expectedAssemblyDisplayName, row.TailorMadeAssemblyCategoryGroup); Assert.AreEqual(expectedAssemblyDisplayName, row.CombinedAssemblyCategoryGroup); Assert.IsNaN(row.CombinedAssemblyProbability); mocks.VerifyAll(); } } [Test] public void GivenRowWithAssemblyErrors_WhenUpdatingAndAssemblyDoesNotThrowException_ExpectedColumnStates() { // Given var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; calculator.ThrowExceptionOnCalculate = true; var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection, ConstructionProperties); // Precondition IDictionary columnStateDefinitions = row.ColumnStateDefinitions; const string expectedErrorText = "Message"; Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex].ErrorText); Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.DetailedAssemblyCategoryGroupIndex].ErrorText); Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex].ErrorText); Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex].ErrorText); Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.CombinedAssemblyProbabilityIndex].ErrorText); // When calculator.ThrowExceptionOnCalculate = false; row.SimpleAssessmentResult = SimpleAssessmentResultType.AssessFurther; // Then Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex].ErrorText); Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.DetailedAssemblyCategoryGroupIndex].ErrorText); Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex].ErrorText); Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex].ErrorText); Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.CombinedAssemblyProbabilityIndex].ErrorText); mocks.VerifyAll(); } } private static TestClosingStructuresCalculation CreateCalculationWithOutput() { return new TestClosingStructuresCalculation { Output = new TestStructuresOutput() }; } #region Column States [Test] [TestCase(SimpleAssessmentResultType.None, true)] [TestCase(SimpleAssessmentResultType.NotApplicable, false)] [TestCase(SimpleAssessmentResultType.ProbabilityNegligible, false)] [TestCase(SimpleAssessmentResultType.AssessFurther, true)] public void Constructor_WithSimpleAssessmentResultSet_ExpectedColumnStates(SimpleAssessmentResultType simpleAssessmentResult, bool cellsEnabled) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section) { SimpleAssessmentResult = simpleAssessmentResult, Calculation = CreateCalculationWithOutput(), TailorMadeAssessmentResult = TailorMadeAssessmentProbabilityCalculationResultType.Probability }; using (new AssemblyToolCalculatorFactoryConfig()) { // Call var row = new ClosingStructuresFailureMechanismSectionResultRow( result, failureMechanism, assessmentSection, ConstructionProperties); // Assert IDictionary columnStateDefinitions = row.ColumnStateDefinitions; DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentResultIndex], cellsEnabled); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex], cellsEnabled, true); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentResultIndex], cellsEnabled); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentProbabilityIndex], cellsEnabled); mocks.VerifyAll(); } } [Test] [TestCase(DetailedAssessmentProbabilityOnlyResultType.NotAssessed, false)] [TestCase(DetailedAssessmentProbabilityOnlyResultType.Probability, true)] public void Constructor_WithDetailedAssessmentResultSet_ExpectedColumnStates(DetailedAssessmentProbabilityOnlyResultType detailedAssessmentResult, bool cellEnabled) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section) { DetailedAssessmentResult = detailedAssessmentResult, Calculation = CreateCalculationWithOutput() }; using (new AssemblyToolCalculatorFactoryConfig()) { // Call var row = new ClosingStructuresFailureMechanismSectionResultRow( result, failureMechanism, assessmentSection, ConstructionProperties); // Assert IDictionary columnStateDefinitions = row.ColumnStateDefinitions; DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex], cellEnabled, true); mocks.VerifyAll(); } } [Test] [TestCase(TailorMadeAssessmentProbabilityCalculationResultType.None, false)] [TestCase(TailorMadeAssessmentProbabilityCalculationResultType.NotAssessed, false)] [TestCase(TailorMadeAssessmentProbabilityCalculationResultType.ProbabilityNegligible, false)] [TestCase(TailorMadeAssessmentProbabilityCalculationResultType.Probability, true)] public void Constructor_WithTailorMadeAssessmentResultSet_ExpectedColumnStates( TailorMadeAssessmentProbabilityCalculationResultType tailorMadeAssessmentResult, bool cellEnabled) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section) { TailorMadeAssessmentResult = tailorMadeAssessmentResult }; using (new AssemblyToolCalculatorFactoryConfig()) { // Call var row = new ClosingStructuresFailureMechanismSectionResultRow( result, failureMechanism, assessmentSection, ConstructionProperties); // Assert IDictionary columnStateDefinitions = row.ColumnStateDefinitions; DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentProbabilityIndex], cellEnabled); mocks.VerifyAll(); } } [Test] [TestCase(true)] [TestCase(false)] public void Constructor_WithUseManualAssemblyProbability_ExpectedColumnStates(bool useManualAssemblyProbability) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section) { Calculation = CreateCalculationWithOutput(), TailorMadeAssessmentResult = TailorMadeAssessmentProbabilityCalculationResultType.Probability, UseManualAssemblyProbability = useManualAssemblyProbability }; using (new AssemblyToolCalculatorFactoryConfig()) { // Call var row = new ClosingStructuresFailureMechanismSectionResultRow( result, failureMechanism, assessmentSection, ConstructionProperties); // Assert IDictionary columnStateDefinitions = row.ColumnStateDefinitions; DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.SimpleAssessmentResultIndex], !useManualAssemblyProbability); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentResultIndex], !useManualAssemblyProbability); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex], !useManualAssemblyProbability, true); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentResultIndex], !useManualAssemblyProbability); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentProbabilityIndex], !useManualAssemblyProbability); if (useManualAssemblyProbability) { DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateIsDisabled( columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex]); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateIsDisabled( columnStateDefinitions[ConstructionProperties.DetailedAssemblyCategoryGroupIndex]); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateIsDisabled( columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex]); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateIsDisabled( columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex]); } DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.CombinedAssemblyProbabilityIndex], !useManualAssemblyProbability, true); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.ManualAssemblyProbabilityIndex], useManualAssemblyProbability); mocks.VerifyAll(); } } [Test] [TestCaseSource(typeof(AssemblyCategoryColorTestHelper), nameof(AssemblyCategoryColorTestHelper.FailureMechanismSectionAssemblyCategoryGroupColorCases))] public void Constructor_WithAssemblyCategoryGroupsSet_ExpectedColumnStates(FailureMechanismSectionAssemblyCategoryGroup assemblyCategoryGroup, Color expectedBackgroundColor) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section) { TailorMadeAssessmentResult = TailorMadeAssessmentProbabilityCalculationResultType.Probability }; using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; var assemblyOutput = new FailureMechanismSectionAssembly(0, assemblyCategoryGroup); calculator.SimpleAssessmentAssemblyOutput = assemblyOutput; calculator.DetailedAssessmentAssemblyOutput = assemblyOutput; calculator.TailorMadeAssessmentAssemblyOutput = assemblyOutput; calculator.CombinedAssemblyCategoryOutput = assemblyCategoryGroup; // Call var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection, ConstructionProperties); // Assert IDictionary columnStateDefinitions = row.ColumnStateDefinitions; DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnWithColorState( columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex], expectedBackgroundColor); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnWithColorState( columnStateDefinitions[ConstructionProperties.DetailedAssemblyCategoryGroupIndex], expectedBackgroundColor); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnWithColorState( columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex], expectedBackgroundColor); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnWithColorState( columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex], expectedBackgroundColor); mocks.VerifyAll(); } } [Test] [TestCase(SimpleAssessmentResultType.None)] [TestCase(SimpleAssessmentResultType.AssessFurther)] public void Constructor_SectionResultWithoutCalculation_DetailedAssessmentProbabilityHasErrorText( SimpleAssessmentResultType simpleAssessmentResult) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) { SimpleAssessmentResult = simpleAssessmentResult }; using (new AssemblyToolCalculatorFactoryConfig()) { // Call var resultRow = new ClosingStructuresFailureMechanismSectionResultRow( sectionResult, failureMechanism, assessmentSection, ConstructionProperties); // Assert Assert.IsNaN(resultRow.DetailedAssessmentProbability); Assert.AreEqual("Er moet een maatgevende berekening voor dit vak worden geselecteerd.", resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); mocks.VerifyAll(); } } [Test] [TestCase(SimpleAssessmentResultType.None)] [TestCase(SimpleAssessmentResultType.AssessFurther)] public void Constructor_SectionResultAndCalculationNotCalculated_DetailedAssessmentProbabilityHasErrorText( SimpleAssessmentResultType simpleAssessmentResult) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) { Calculation = new TestClosingStructuresCalculation(), SimpleAssessmentResult = simpleAssessmentResult }; using (new AssemblyToolCalculatorFactoryConfig()) { // Call var resultRow = new ClosingStructuresFailureMechanismSectionResultRow( sectionResult, failureMechanism, assessmentSection, ConstructionProperties); // Assert Assert.IsNaN(resultRow.DetailedAssessmentProbability); Assert.AreEqual("De maatgevende berekening voor dit vak moet nog worden uitgevoerd.", resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); mocks.VerifyAll(); } } [Test] [TestCase(SimpleAssessmentResultType.None)] [TestCase(SimpleAssessmentResultType.AssessFurther)] public void Constructor_SectionResultAndFailedCalculation_DetailedAssessmentProbabilityHasErrorText( SimpleAssessmentResultType simpleAssessmentResult) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var calculation = new TestClosingStructuresCalculation { Output = new TestStructuresOutput(double.NaN) }; FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) { Calculation = calculation, SimpleAssessmentResult = simpleAssessmentResult }; using (new AssemblyToolCalculatorFactoryConfig()) { // Call var resultRow = new ClosingStructuresFailureMechanismSectionResultRow( sectionResult, failureMechanism, assessmentSection, ConstructionProperties); // Assert Assert.IsNaN(resultRow.DetailedAssessmentProbability); Assert.AreEqual("De maatgevende berekening voor dit vak moet een geldige uitkomst hebben.", resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); mocks.VerifyAll(); } } [Test] public void Constructor_SectionResultAndSuccessfulCalculation_DetailedAssessmentProbabilityNoError() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) { Calculation = CreateCalculationWithOutput() }; using (new AssemblyToolCalculatorFactoryConfig()) { // Call var resultRow = new ClosingStructuresFailureMechanismSectionResultRow( sectionResult, failureMechanism, assessmentSection, ConstructionProperties); // Assert Assert.AreEqual(sectionResult.GetDetailedAssessmentProbability(failureMechanism, assessmentSection), resultRow.DetailedAssessmentProbability); Assert.IsEmpty(resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); mocks.VerifyAll(); } } [Test] public void Constructor_SectionResultWithManualAssemblyAndNotCalculated_DetailedAssessmentProbabilityNoError() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) { Calculation = new TestClosingStructuresCalculation(), UseManualAssemblyProbability = true }; using (new AssemblyToolCalculatorFactoryConfig()) { // Call var resultRow = new ClosingStructuresFailureMechanismSectionResultRow( sectionResult, failureMechanism, assessmentSection, ConstructionProperties); // Assert Assert.IsNaN(resultRow.DetailedAssessmentProbability); Assert.IsEmpty(resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); mocks.VerifyAll(); } } [Test] public void Constructor_SectionResultWithDetailedAssessmentNotAssessedAndNotCalculated_DetailedAssessmentProbabilityNoError() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) { Calculation = new TestClosingStructuresCalculation(), DetailedAssessmentResult = DetailedAssessmentProbabilityOnlyResultType.NotAssessed }; using (new AssemblyToolCalculatorFactoryConfig()) { // Call var resultRow = new ClosingStructuresFailureMechanismSectionResultRow( sectionResult, failureMechanism, assessmentSection, ConstructionProperties); // Assert Assert.IsNaN(resultRow.DetailedAssessmentProbability); Assert.IsEmpty(resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); mocks.VerifyAll(); } } [Test] [TestCaseSource(nameof(SimpleAssessmentResultIsSufficientVariousSectionResults))] public void Constructor_SectionResultAndAssessmentSimpleAssessmentSufficient_DetailedAssessmentProbabilityNoError( ClosingStructuresFailureMechanismSectionResult sectionResult) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); using (new AssemblyToolCalculatorFactoryConfig()) { // Call var resultRow = new ClosingStructuresFailureMechanismSectionResultRow( sectionResult, failureMechanism, assessmentSection, ConstructionProperties); // Assert Assert.AreEqual(sectionResult.GetDetailedAssessmentProbability(failureMechanism, assessmentSection), resultRow.DetailedAssessmentProbability); Assert.IsEmpty(resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); mocks.VerifyAll(); } } private static IEnumerable SimpleAssessmentResultIsSufficientVariousSectionResults() { FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); yield return new TestCaseData(new ClosingStructuresFailureMechanismSectionResult(section) { SimpleAssessmentResult = SimpleAssessmentResultType.ProbabilityNegligible }).SetName("SectionWithoutCalculationAndSimpleAssessmentResultProbabilityNegligible"); yield return new TestCaseData(new ClosingStructuresFailureMechanismSectionResult(section) { SimpleAssessmentResult = SimpleAssessmentResultType.ProbabilityNegligible, Calculation = new StructuresCalculation() }).SetName("SectionWithCalculationNoOutputAndSimpleAssessmentResultProbabilityNegligible"); yield return new TestCaseData(new ClosingStructuresFailureMechanismSectionResult(section) { SimpleAssessmentResult = SimpleAssessmentResultType.ProbabilityNegligible, Calculation = new StructuresCalculation { Output = new TestStructuresOutput(double.NaN) } }).SetName("SectionWithInvalidCalculationOutputAndSimpleAssessmentResultProbabilityNegligible"); yield return new TestCaseData(new ClosingStructuresFailureMechanismSectionResult(section) { SimpleAssessmentResult = SimpleAssessmentResultType.ProbabilityNegligible, Calculation = CreateCalculationWithOutput() }).SetName("SectionWithValidCalculationOutputAndSimpleAssessmentResultProbabilityNegligible"); yield return new TestCaseData(new ClosingStructuresFailureMechanismSectionResult(section) { SimpleAssessmentResult = SimpleAssessmentResultType.NotApplicable }).SetName("SectionWithoutCalculationAndSimpleAssessmentResultNotApplicable"); yield return new TestCaseData(new ClosingStructuresFailureMechanismSectionResult(section) { SimpleAssessmentResult = SimpleAssessmentResultType.NotApplicable, Calculation = new StructuresCalculation() }).SetName("SectionWithCalculationNoOutputAndSimpleAssessmentResultNotApplicable"); yield return new TestCaseData(new ClosingStructuresFailureMechanismSectionResult(section) { SimpleAssessmentResult = SimpleAssessmentResultType.NotApplicable, Calculation = new StructuresCalculation { Output = new TestStructuresOutput(double.NaN) } }).SetName("SectionWithInvalidCalculationOutputAndSimpleAssessmentResultNotApplicable"); yield return new TestCaseData(new ClosingStructuresFailureMechanismSectionResult(section) { SimpleAssessmentResult = SimpleAssessmentResultType.NotApplicable, Calculation = CreateCalculationWithOutput() }).SetName("SectionWithValidCalculationOutputAndSimpleAssessmentResultNotApplicable"); } #endregion #region Registration [Test] public void SimpleAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); result.Attach(observer); var newValue = new Random(21).NextEnumValue(); using (new AssemblyToolCalculatorFactoryConfig()) { var row = new ClosingStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection, ConstructionProperties); // Call row.SimpleAssessmentResult = newValue; // Assert Assert.AreEqual(newValue, result.SimpleAssessmentResult); mocks.VerifyAll(); } } [Test] public void DetailedAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); 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 ClosingStructuresFailureMechanismSectionResult(section); result.Attach(observer); using (new AssemblyToolCalculatorFactoryConfig()) { var row = new ClosingStructuresFailureMechanismSectionResultRow( result, failureMechanism, assessmentSection, ConstructionProperties); // Call row.DetailedAssessmentResult = newValue; // Assert Assert.AreEqual(newValue, result.DetailedAssessmentResult); mocks.VerifyAll(); } } [Test] public void DetailedAssessmentProbability_NoCalculationSet_ReturnNaN() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section); // Precondition Assert.IsNull(sectionResult.Calculation); using (new AssemblyToolCalculatorFactoryConfig()) { var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection, ConstructionProperties); // Call double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; // Assert Assert.IsNaN(detailedAssessmentProbability); mocks.VerifyAll(); } } [Test] [TestCase(CalculationScenarioStatus.Failed)] [TestCase(CalculationScenarioStatus.NotCalculated)] public void DetailedAssessmentProbability_CalculationNotDone_ReturnNaN(CalculationScenarioStatus status) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var calculation = new StructuresCalculation(); if (status == CalculationScenarioStatus.Failed) { calculation.Output = new TestStructuresOutput(double.NaN); } FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) { Calculation = calculation }; using (new AssemblyToolCalculatorFactoryConfig()) { var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection, ConstructionProperties); // Call double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; // Assert Assert.IsNaN(detailedAssessmentProbability); mocks.VerifyAll(); } } [Test] public void DetailedAssessmentProbability_CalculationSuccessful_ReturnDetailedAssessmentProbability() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); const double reliability = 0.586789; var calculation = new StructuresCalculation { Output = new TestStructuresOutput(reliability) }; FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var sectionResult = new ClosingStructuresFailureMechanismSectionResult(section) { Calculation = calculation }; using (new AssemblyToolCalculatorFactoryConfig()) { var resultRow = new ClosingStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection, ConstructionProperties); // Call double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability; // Assert Assert.AreEqual(0.2786727127146118, detailedAssessmentProbability); mocks.VerifyAll(); } } [Test] public void TailorMadeAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); 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 ClosingStructuresFailureMechanismSectionResult(section); result.Attach(observer); using (new AssemblyToolCalculatorFactoryConfig()) { var row = new ClosingStructuresFailureMechanismSectionResultRow( result, failureMechanism, assessmentSection, ConstructionProperties); // Call row.TailorMadeAssessmentResult = newValue; // Assert Assert.AreEqual(newValue, result.TailorMadeAssessmentResult); mocks.VerifyAll(); } } [Test] [TestCase(0)] [TestCase(1)] [TestCase(0.5)] [TestCase(1e-6)] [TestCase(double.NaN)] public void TailorMadeAssessmentProbability_ValidValue_NotifyObserversAndPropertyChanged(double value) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); result.Attach(observer); using (new AssemblyToolCalculatorFactoryConfig()) { var row = new ClosingStructuresFailureMechanismSectionResultRow( result, failureMechanism, assessmentSection, ConstructionProperties); // Call row.TailorMadeAssessmentProbability = value; // Assert Assert.AreEqual(value, row.TailorMadeAssessmentProbability); mocks.VerifyAll(); } } [Test] [SetCulture("nl-NL")] [TestCase(-20)] [TestCase(-1e-6)] [TestCase(1 + 1e-6)] [TestCase(12)] public void TailorMadeAssessmentProbability_InvalidValue_ThrowsArgumentOutOfRangeException(double value) { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var result = new ClosingStructuresFailureMechanismSectionResult(section); using (new AssemblyToolCalculatorFactoryConfig()) { var row = new ClosingStructuresFailureMechanismSectionResultRow( result, failureMechanism, assessmentSection, ConstructionProperties); // Call TestDelegate test = () => row.TailorMadeAssessmentProbability = value; // Assert const string expectedMessage = "De waarde voor de faalkans moet in het bereik [0,0, 1,0] liggen."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); mocks.VerifyAll(); } } #endregion } }