// 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.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;
using Ringtoets.StabilityPointStructures.Data;
using Ringtoets.StabilityPointStructures.Data.TestUtil;
using Ringtoets.StabilityPointStructures.Forms.Views;
namespace Ringtoets.StabilityPointStructures.Forms.Test.Views
{
[TestFixture]
public class StabilityPointStructuresFailureMechanismSectionResultRowTest
{
private static StabilityPointStructuresFailureMechanismSectionResultRow.ConstructionProperties ConstructionProperties
{
get
{
return new StabilityPointStructuresFailureMechanismSectionResultRow.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 StabilityPointStructuresFailureMechanismSectionResult(section);
// Call
TestDelegate call = () => new StabilityPointStructuresFailureMechanismSectionResultRow(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 StabilityPointStructuresFailureMechanismSectionResult(section);
// Call
TestDelegate call = () => new StabilityPointStructuresFailureMechanismSectionResultRow(
result, new StabilityPointStructuresFailureMechanism(), 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 StabilityPointStructuresFailureMechanismSectionResult(section);
// Call
TestDelegate call = () => new StabilityPointStructuresFailureMechanismSectionResultRow(result,
new StabilityPointStructuresFailureMechanism(),
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 StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var result = new StabilityPointStructuresFailureMechanismSectionResult(section);
// Call
using (new AssemblyToolCalculatorFactoryConfig())
{
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection,
ConstructionProperties);
// Assert
Assert.IsInstanceOf>(row);
IDictionary columnStateDefinitions = row.ColumnStateDefinitions;
Assert.AreEqual(11, columnStateDefinitions.Count);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.SimpleAssessmentResultIndex);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.DetailedAssessmentResultIndex);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.DetailedAssessmentProbabilityIndex);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.TailorMadeAssessmentResultIndex);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.TailorMadeAssessmentProbabilityIndex);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.SimpleAssemblyCategoryGroupIndex);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.DetailedAssemblyCategoryGroupIndex);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.CombinedAssemblyCategoryGroupIndex);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.CombinedAssemblyProbabilityIndex);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateDefinition(columnStateDefinitions, ConstructionProperties.ManualAssemblyProbabilityIndex);
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(row.TailorMadeAssessmentProbability, result.TailorMadeAssessmentProbability);
Assert.AreEqual(result.UseManualAssemblyProbability, row.UseManualAssemblyProbability);
Assert.AreEqual(result.ManualAssemblyProbability, row.ManualAssemblyProbability);
TestHelper.AssertTypeConverter(
nameof(StabilityPointStructuresFailureMechanismSectionResultRow.DetailedAssessmentProbability));
TestHelper.AssertTypeConverter(
nameof(StabilityPointStructuresFailureMechanismSectionResultRow.TailorMadeAssessmentProbability));
TestHelper.AssertTypeConverter(
nameof(StabilityPointStructuresFailureMechanismSectionResultRow.CombinedAssemblyProbability));
mocks.VerifyAll();
}
}
[Test]
public void Constructor_AssemblyRan_ReturnCategoryGroups()
{
// Setup
var random = new Random(39);
var failureMechanism = new StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var result = new StabilityPointStructuresFailureMechanismSectionResult(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 StabilityPointStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection,
ConstructionProperties);
// Assert
Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.SimpleAssessmentAssemblyOutput.Group),
row.SimpleAssemblyCategoryGroup);
Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.DetailedAssessmentAssemblyOutput.Group),
row.DetailedAssemblyCategoryGroup);
Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.TailorMadeAssessmentAssemblyOutput.Group),
row.TailorMadeAssemblyCategoryGroup);
Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.CombinedAssemblyOutput.Group),
row.CombinedAssemblyCategoryGroup);
Assert.AreEqual(calculator.CombinedAssemblyOutput.Probability, row.CombinedAssemblyProbability);
mocks.VerifyAll();
}
}
[Test]
public void GivenRowWithoutAssemblyErrors_WhenUpdatingAndAssemblyThrowsException_ThenAssemblyGroupSetToNone()
{
// Given
var random = new Random(39);
var failureMechanism = new StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var result = new StabilityPointStructuresFailureMechanismSectionResult(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 StabilityPointStructuresFailureMechanismSectionResultRow(result, failureMechanism, assessmentSection,
ConstructionProperties);
// Precondition
Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.SimpleAssessmentAssemblyOutput.Group),
row.SimpleAssemblyCategoryGroup);
Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.DetailedAssessmentAssemblyOutput.Group),
row.DetailedAssemblyCategoryGroup);
Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.TailorMadeAssessmentAssemblyOutput.Group),
row.TailorMadeAssemblyCategoryGroup);
Assert.AreEqual(FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(calculator.CombinedAssemblyOutput.Group),
row.CombinedAssemblyCategoryGroup);
Assert.AreEqual(calculator.CombinedAssemblyOutput.Probability, row.CombinedAssemblyProbability);
// When
calculator.ThrowExceptionOnCalculate = true;
row.SimpleAssessmentResult = SimpleAssessmentValidityOnlyResultType.Applicable;
// Then
string expectedAssemblyDisplayName = FailureMechanismSectionResultRowHelper.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 StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var result = new StabilityPointStructuresFailureMechanismSectionResult(section);
using (new AssemblyToolCalculatorFactoryConfig())
{
var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
calculator.ThrowExceptionOnCalculate = true;
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(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 = SimpleAssessmentValidityOnlyResultType.Applicable;
// 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();
}
}
[Test]
public void UseManualAssemblyProbability_SetNewValue_NotifyObserversAndPropertyChanged()
{
// Setup
var failureMechanism = new StabilityPointStructuresFailureMechanism();
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 StabilityPointStructuresFailureMechanismSectionResult(section);
result.Attach(observer);
using (new AssemblyToolCalculatorFactoryConfig())
{
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(
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 StabilityPointStructuresFailureMechanism();
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 StabilityPointStructuresFailureMechanismSectionResult(section);
result.Attach(observer);
using (new AssemblyToolCalculatorFactoryConfig())
{
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(
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 StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var result = new StabilityPointStructuresFailureMechanismSectionResult(section);
using (new AssemblyToolCalculatorFactoryConfig())
{
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(
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();
}
}
private static TestStabilityPointStructuresCalculation CreateCalculationWithOutput()
{
return new TestStabilityPointStructuresCalculation
{
Output = new TestStructuresOutput()
};
}
#region Column States
[Test]
[TestCase(SimpleAssessmentValidityOnlyResultType.None, true)]
[TestCase(SimpleAssessmentValidityOnlyResultType.NotApplicable, false)]
[TestCase(SimpleAssessmentValidityOnlyResultType.Applicable, true)]
public void Constructor_WithSimpleAssessmentResultSet_ExpectedColumnStates(SimpleAssessmentValidityOnlyResultType simpleAssessmentResult,
bool cellsEnabled)
{
// Setup
var failureMechanism = new StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var result = new StabilityPointStructuresFailureMechanismSectionResult(section)
{
SimpleAssessmentResult = simpleAssessmentResult,
Calculation = CreateCalculationWithOutput(),
TailorMadeAssessmentResult = TailorMadeAssessmentProbabilityCalculationResultType.Probability
};
using (new AssemblyToolCalculatorFactoryConfig())
{
// Call
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(
result, failureMechanism, assessmentSection, ConstructionProperties);
// Assert
IDictionary columnStateDefinitions = row.ColumnStateDefinitions;
FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentResultIndex],
cellsEnabled);
FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex],
cellsEnabled,
true);
FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentResultIndex],
cellsEnabled);
FailureMechanismSectionResultRowTestHelper.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 StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var result = new StabilityPointStructuresFailureMechanismSectionResult(section)
{
DetailedAssessmentResult = detailedAssessmentResult,
Calculation = CreateCalculationWithOutput()
};
using (new AssemblyToolCalculatorFactoryConfig())
{
// Call
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(
result, failureMechanism, assessmentSection, ConstructionProperties);
// Assert
IDictionary columnStateDefinitions = row.ColumnStateDefinitions;
FailureMechanismSectionResultRowTestHelper.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 StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var result = new StabilityPointStructuresFailureMechanismSectionResult(section)
{
TailorMadeAssessmentResult = tailorMadeAssessmentResult
};
using (new AssemblyToolCalculatorFactoryConfig())
{
// Call
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(
result, failureMechanism, assessmentSection, ConstructionProperties);
// Assert
IDictionary columnStateDefinitions = row.ColumnStateDefinitions;
FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentProbabilityIndex],
cellEnabled);
mocks.VerifyAll();
}
}
[Test]
[TestCase(true)]
[TestCase(false)]
public void Constructor_WithUseManualAssemblyProbability_ExpectedColumnStates(bool useManualAssemblyProbability)
{
// Setup
var failureMechanism = new StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var result = new StabilityPointStructuresFailureMechanismSectionResult(section)
{
Calculation = CreateCalculationWithOutput(),
TailorMadeAssessmentResult = TailorMadeAssessmentProbabilityCalculationResultType.Probability,
UseManualAssemblyProbability = useManualAssemblyProbability
};
using (new AssemblyToolCalculatorFactoryConfig())
{
// Call
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(
result, failureMechanism, assessmentSection, ConstructionProperties);
// Assert
IDictionary columnStateDefinitions = row.ColumnStateDefinitions;
FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.SimpleAssessmentResultIndex],
!useManualAssemblyProbability);
FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentResultIndex],
!useManualAssemblyProbability);
FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex],
!useManualAssemblyProbability, true);
FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentResultIndex],
!useManualAssemblyProbability);
FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.TailorMadeAssessmentProbabilityIndex],
!useManualAssemblyProbability);
if (useManualAssemblyProbability)
{
FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled(
columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex]);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled(
columnStateDefinitions[ConstructionProperties.DetailedAssemblyCategoryGroupIndex]);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled(
columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex]);
FailureMechanismSectionResultRowTestHelper.AssertColumnStateIsDisabled(
columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex]);
}
FailureMechanismSectionResultRowTestHelper.AssertColumnState(columnStateDefinitions[ConstructionProperties.CombinedAssemblyProbabilityIndex],
!useManualAssemblyProbability, true);
FailureMechanismSectionResultRowTestHelper.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 StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var result = new StabilityPointStructuresFailureMechanismSectionResult(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 StabilityPointStructuresFailureMechanismSectionResultRow(result,
failureMechanism,
assessmentSection,
ConstructionProperties);
// Assert
IDictionary columnStateDefinitions = row.ColumnStateDefinitions;
FailureMechanismSectionResultRowTestHelper.AssertColumnWithColorState(
columnStateDefinitions[ConstructionProperties.SimpleAssemblyCategoryGroupIndex], expectedBackgroundColor);
FailureMechanismSectionResultRowTestHelper.AssertColumnWithColorState(
columnStateDefinitions[ConstructionProperties.DetailedAssemblyCategoryGroupIndex], expectedBackgroundColor);
FailureMechanismSectionResultRowTestHelper.AssertColumnWithColorState(
columnStateDefinitions[ConstructionProperties.TailorMadeAssemblyCategoryGroupIndex], expectedBackgroundColor);
FailureMechanismSectionResultRowTestHelper.AssertColumnWithColorState(
columnStateDefinitions[ConstructionProperties.CombinedAssemblyCategoryGroupIndex], expectedBackgroundColor);
mocks.VerifyAll();
}
}
[Test]
[TestCase(SimpleAssessmentValidityOnlyResultType.None)]
[TestCase(SimpleAssessmentValidityOnlyResultType.Applicable)]
public void Constructor_SectionResultWithoutCalculation_DetailedAssessmentProbabilityHasErrorText(
SimpleAssessmentValidityOnlyResultType simpleAssessmentResult)
{
// Setup
var failureMechanism = new StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
{
SimpleAssessmentResult = simpleAssessmentResult
};
using (new AssemblyToolCalculatorFactoryConfig())
{
// Call
var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(
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(SimpleAssessmentValidityOnlyResultType.None)]
[TestCase(SimpleAssessmentValidityOnlyResultType.Applicable)]
public void Constructor_SectionResultAndCalculationNotCalculated_DetailedAssessmentProbabilityHasErrorText(
SimpleAssessmentValidityOnlyResultType simpleAssessmentResult)
{
// Setup
var failureMechanism = new StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
{
Calculation = new TestStabilityPointStructuresCalculation(),
SimpleAssessmentResult = simpleAssessmentResult
};
using (new AssemblyToolCalculatorFactoryConfig())
{
// Call
var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(
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(SimpleAssessmentValidityOnlyResultType.None)]
[TestCase(SimpleAssessmentValidityOnlyResultType.Applicable)]
public void Constructor_SectionResultAndFailedCalculation_DetailedAssessmentProbabilityHasErrorText(
SimpleAssessmentValidityOnlyResultType simpleAssessmentResult)
{
// Setup
var failureMechanism = new StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
var calculation = new TestStabilityPointStructuresCalculation
{
Output = new TestStructuresOutput(double.NaN)
};
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(section)
{
Calculation = calculation,
SimpleAssessmentResult = simpleAssessmentResult
};
using (new AssemblyToolCalculatorFactoryConfig())
{
// Call
var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(
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 StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
{
Calculation = CreateCalculationWithOutput()
};
using (new AssemblyToolCalculatorFactoryConfig())
{
// Call
var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(
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 StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
{
Calculation = new TestStabilityPointStructuresCalculation(),
UseManualAssemblyProbability = true
};
using (new AssemblyToolCalculatorFactoryConfig())
{
// Call
var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(
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 StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
{
Calculation = new TestStabilityPointStructuresCalculation(),
DetailedAssessmentResult = DetailedAssessmentProbabilityOnlyResultType.NotAssessed
};
using (new AssemblyToolCalculatorFactoryConfig())
{
// Call
var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(
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(
StabilityPointStructuresFailureMechanismSectionResult sectionResult)
{
// Setup
var failureMechanism = new StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
using (new AssemblyToolCalculatorFactoryConfig())
{
// Call
var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(
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 StabilityPointStructuresFailureMechanismSectionResult(section)
{
SimpleAssessmentResult = SimpleAssessmentValidityOnlyResultType.NotApplicable
}).SetName("SectionWithoutCalculationAndSimpleAssessmentResultNotApplicable");
yield return new TestCaseData(new StabilityPointStructuresFailureMechanismSectionResult(section)
{
SimpleAssessmentResult = SimpleAssessmentValidityOnlyResultType.NotApplicable,
Calculation = new StructuresCalculation()
}).SetName("SectionWithCalculationNoOutputAndSimpleAssessmentResultNotApplicable");
yield return new TestCaseData(new StabilityPointStructuresFailureMechanismSectionResult(section)
{
SimpleAssessmentResult = SimpleAssessmentValidityOnlyResultType.NotApplicable,
Calculation = new StructuresCalculation
{
Output = new TestStructuresOutput(double.NaN)
}
}).SetName("SectionWithInvalidCalculationOutputAndSimpleAssessmentResultNotApplicable");
yield return new TestCaseData(new StabilityPointStructuresFailureMechanismSectionResult(section)
{
SimpleAssessmentResult = SimpleAssessmentValidityOnlyResultType.NotApplicable,
Calculation = CreateCalculationWithOutput()
}).SetName("SectionWithValidCalculationOutputAndSimpleAssessmentResultNotApplicable");
}
#endregion
#region Registration
[Test]
public void SimpleAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged()
{
// Setup
var failureMechanism = new StabilityPointStructuresFailureMechanism();
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 StabilityPointStructuresFailureMechanismSectionResult(section);
result.Attach(observer);
var newValue = new Random(21).NextEnumValue();
using (new AssemblyToolCalculatorFactoryConfig())
{
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(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 StabilityPointStructuresFailureMechanism();
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 StabilityPointStructuresFailureMechanismSectionResult(section);
result.Attach(observer);
using (new AssemblyToolCalculatorFactoryConfig())
{
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(
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 StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(section);
// Precondition
Assert.IsNull(sectionResult.Calculation);
using (new AssemblyToolCalculatorFactoryConfig())
{
var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(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 StabilityPointStructuresFailureMechanism();
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 StabilityPointStructuresFailureMechanismSectionResult(section)
{
Calculation = calculation
};
using (new AssemblyToolCalculatorFactoryConfig())
{
var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(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 StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
var calculation = new StructuresCalculation
{
Output = new TestStructuresOutput(0.95)
};
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var sectionResult = new StabilityPointStructuresFailureMechanismSectionResult(section)
{
Calculation = calculation
};
using (new AssemblyToolCalculatorFactoryConfig())
{
var resultRow = new StabilityPointStructuresFailureMechanismSectionResultRow(sectionResult, failureMechanism, assessmentSection,
ConstructionProperties);
// Call
double detailedAssessmentProbability = resultRow.DetailedAssessmentProbability;
// Assert
Assert.AreEqual(0.17105612630848185, detailedAssessmentProbability);
mocks.VerifyAll();
}
}
[Test]
public void TailorMadeAssessmentResult_SetNewValue_NotifyObserversAndPropertyChanged()
{
// Setup
var failureMechanism = new StabilityPointStructuresFailureMechanism();
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 StabilityPointStructuresFailureMechanismSectionResult(section);
result.Attach(observer);
using (new AssemblyToolCalculatorFactoryConfig())
{
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(
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 StabilityPointStructuresFailureMechanism();
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 StabilityPointStructuresFailureMechanismSectionResult(section);
result.Attach(observer);
using (new AssemblyToolCalculatorFactoryConfig())
{
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(
result, new StabilityPointStructuresFailureMechanism(), 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 StabilityPointStructuresFailureMechanism();
var mocks = new MockRepository();
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks);
mocks.ReplayAll();
FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
var result = new StabilityPointStructuresFailureMechanismSectionResult(section);
using (new AssemblyToolCalculatorFactoryConfig())
{
var row = new StabilityPointStructuresFailureMechanismSectionResultRow(
result, new StabilityPointStructuresFailureMechanism(), 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
}
}