public void GetInitialFailureMechanismResultProbability_ScenarioWithNaNResults_ReturnsNaN()
        {
            // Setup
            FailureMechanismSection section   = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var failureMechanismSectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            const double contribution1 = 0.2;
            const double contribution2 = 0.8;

            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario1 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithNaNOutput(section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section);

            macroStabilityInwardsCalculationScenario1.IsRelevant   = true;
            macroStabilityInwardsCalculationScenario1.Contribution = (RoundedDouble)contribution1;

            macroStabilityInwardsCalculationScenario2.IsRelevant   = true;
            macroStabilityInwardsCalculationScenario2.Contribution = (RoundedDouble)contribution2;

            MacroStabilityInwardsCalculationScenario[] calculations =
            {
                macroStabilityInwardsCalculationScenario1,
                macroStabilityInwardsCalculationScenario2
            };

            // Call
            double initialFailureMechanismResultProbability = failureMechanismSectionResult.GetInitialFailureMechanismResultProbability(calculations, 0.1);

            // Assert
            Assert.IsNaN(initialFailureMechanismResultProbability);
        }
示例#2
0
        public void Constructor_Always_ExpectedColumnStates()
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create;

            // Call
            var row = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResultRow(result, errorProvider, performAssemblyFunc, ConstructionProperties);

            // Assert
            IDictionary <int, DataGridViewColumnStateDefinition> columnStateDefinitions = row.ColumnStateDefinitions;

            DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(
                columnStateDefinitions[ConstructionProperties.ProfileProbabilityIndex], true, true);
            DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(
                columnStateDefinitions[ConstructionProperties.SectionProbabilityIndex], true, true);
            DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(
                columnStateDefinitions[ConstructionProperties.SectionNIndex], true, true);

            mocks.VerifyAll();
        }
示例#3
0
        public void Constructor_WithAssemblyGroupSet_ExpectedColumnStates(FailureMechanismSectionAssemblyGroup assemblyGroup,
                                                                          Color expectedBackgroundColor)
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = () => new FailureMechanismSectionAssemblyResultWrapper(
                FailureMechanismSectionAssemblyResultTestFactory.CreateFailureMechanismSectionAssemblyResult(assemblyGroup),
                AssemblyMethod.BOI0A1, AssemblyMethod.BOI0B1);

            // Call
            var row = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResultRow(result, errorProvider, performAssemblyFunc, ConstructionProperties);

            // Assert
            IDictionary <int, DataGridViewColumnStateDefinition> columnStateDefinitions = row.ColumnStateDefinitions;

            DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnWithColorState(
                columnStateDefinitions[ConstructionProperties.AssemblyGroupIndex], expectedBackgroundColor);

            mocks.VerifyAll();
        }
示例#4
0
        public void GivenRowWithIsRelevantAndInitialFailureMechanismResultType_WhenErrorProviderReturnsError_ThenShowNoError(
            bool isRelevant, NonAdoptableInitialFailureMechanismResultType initialFailureMechanismResultType)
        {
            // Given
            var mocks         = new MockRepository();
            var errorProvider = mocks.StrictMock <IFailureMechanismSectionResultRowErrorProvider>();

            errorProvider.Stub(ep => ep.GetManualProbabilityValidationError(double.NaN))
            .IgnoreArguments()
            .Return("error message");
            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section)
            {
                IsRelevant = isRelevant,
                InitialFailureMechanismResultType = initialFailureMechanismResultType
            };

            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create;

            // When
            var row = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResultRow(result, errorProvider, performAssemblyFunc, ConstructionProperties);

            // Then
            IDictionary <int, DataGridViewColumnStateDefinition> columnStateDefinitions = row.ColumnStateDefinitions;

            Assert.IsEmpty(columnStateDefinitions[ConstructionProperties.InitialFailureMechanismResultProfileProbabilityIndex].ErrorText);
            Assert.IsEmpty(columnStateDefinitions[ConstructionProperties.InitialFailureMechanismResultSectionProbabilityIndex].ErrorText);

            mocks.VerifyAll();
        }
示例#5
0
        private static void ProbabilityProperty_SetInvalidValue_ThrowsArgumentOutOfRangeException(
            Action <NonAdoptableWithProfileProbabilityFailureMechanismSectionResultRow> setPropertyAction)
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create;
            var row = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResultRow(result, errorProvider, performAssemblyFunc, ConstructionProperties);

            // Call
            void Call() => setPropertyAction(row);

            // Assert
            const string expectedMessage = "De waarde voor de faalkans moet in het bereik [0,0, 1,0] liggen.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentOutOfRangeException>(Call, expectedMessage);

            mocks.VerifyAll();
        }
示例#6
0
        public void GetCalculatedProbabilityValidationError_ValidCalculationScenarios_ReturnsEmptyMessage()
        {
            // Setup
            var random = new Random(39);
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new TestFailureMechanismSectionResult(section);

            var calculationScenarios = new[]
            {
                new TestCalculationScenario
                {
                    Contribution = (RoundedDouble)0.5,
                    Output       = new object()
                },
                new TestCalculationScenario
                {
                    Contribution = (RoundedDouble)0.5,
                    Output       = new object()
                }
            };

            var errorProvider = new FailureMechanismSectionResultRowWithCalculatedProbabilityErrorProvider <ICalculationScenario>(
                sectionResult, calculationScenarios, (scenario, segments) => true);

            // Call
            string errorMessage = errorProvider.GetCalculatedProbabilityValidationError(() => random.NextDouble());

            // Assert
            Assert.AreEqual(string.Empty, errorMessage);
        }
示例#7
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var failureMechanism = new PipingFailureMechanism();

            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks);

            mocks.ReplayAll();

            var calculation = new SemiProbabilisticPipingCalculationScenario();
            FailureMechanismSection failureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();

            // Call
            var row = new SemiProbabilisticPipingScenarioRow(calculation, failureMechanism, failureMechanismSection, assessmentSection);

            // Assert
            Assert.IsInstanceOf <PipingScenarioRow <SemiProbabilisticPipingCalculationScenario> >(row);
            Assert.AreSame(calculation, row.CalculationScenario);

            TestHelper.AssertTypeConverter <SemiProbabilisticPipingScenarioRow, NoProbabilityValueDoubleConverter>(
                nameof(SemiProbabilisticPipingScenarioRow.FailureProbabilityUplift));
            TestHelper.AssertTypeConverter <SemiProbabilisticPipingScenarioRow, NoProbabilityValueDoubleConverter>(
                nameof(SemiProbabilisticPipingScenarioRow.FailureProbabilityHeave));
            TestHelper.AssertTypeConverter <SemiProbabilisticPipingScenarioRow, NoProbabilityValueDoubleConverter>(
                nameof(SemiProbabilisticPipingScenarioRow.FailureProbabilitySellmeijer));
        }
        public void GivenRowWithIsRelevantTrueAndInitialFailureMechanismResultTypeManual_WhenErrorProviderReturnsError_ThenShowError()
        {
            // Given
            var    random             = new Random(21);
            double sectionProbability = random.NextDouble();

            const string errorText     = "error";
            var          mocks         = new MockRepository();
            var          errorProvider = mocks.StrictMock <IFailureMechanismSectionResultRowErrorProvider>();

            errorProvider.Expect(ep => ep.GetManualProbabilityValidationError(sectionProbability))
            .Return(errorText);
            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableFailureMechanismSectionResult(section)
            {
                InitialFailureMechanismResultType = NonAdoptableInitialFailureMechanismResultType.Manual,
                ManualInitialFailureMechanismResultSectionProbability = sectionProbability
            };

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                // When
                var row = new NonAdoptableFailureMechanismSectionResultRow(result, errorProvider, new AssessmentSectionStub(), ConstructionProperties);

                // Then
                IDictionary <int, DataGridViewColumnStateDefinition> columnStateDefinitions = row.ColumnStateDefinitions;
                Assert.AreEqual(errorText, columnStateDefinitions[ConstructionProperties.InitialFailureMechanismResultSectionProbabilityIndex].ErrorText);
            }

            mocks.VerifyAll();
        }
        public void GivenRowWithFurtherAnalysisTypeNotExecuted_WhenErrorProviderReturnsError_ThenShowsNoError(FailureMechanismSectionResultFurtherAnalysisType furtherAnalysisType)
        {
            // Given
            var    random             = new Random(21);
            double sectionProbability = random.NextDouble();

            var mocks         = new MockRepository();
            var errorProvider = mocks.StrictMock <IFailureMechanismSectionResultRowErrorProvider>();

            errorProvider.Stub(ep => ep.GetManualProbabilityValidationError(double.NaN))
            .IgnoreArguments()
            .Return("error");
            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableFailureMechanismSectionResult(section)
            {
                InitialFailureMechanismResultType = NonAdoptableInitialFailureMechanismResultType.NoFailureProbability,
                FurtherAnalysisType       = furtherAnalysisType,
                RefinedSectionProbability = sectionProbability
            };

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                // When
                var row = new NonAdoptableFailureMechanismSectionResultRow(result, errorProvider, new AssessmentSectionStub(), ConstructionProperties);

                // Then
                IDictionary <int, DataGridViewColumnStateDefinition> columnStateDefinitions = row.ColumnStateDefinitions;
                Assert.IsEmpty(columnStateDefinitions[ConstructionProperties.RefinedSectionProbabilityIndex].ErrorText);
            }

            mocks.VerifyAll();
        }
        public void CreateCalculateStrategy_WithProbabilisticConfigurations_ReturnsExpectedStrategy(
            PipingFailureMechanism failureMechanism, PipingScenarioConfigurationPerFailureMechanismSectionType configurationType)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();

            failureMechanism.SetSections(new[]
            {
                section
            }, "APath");

            PipingScenarioConfigurationPerFailureMechanismSection scenarioConfigurationPerFailureMechanismSection =
                failureMechanism.ScenarioConfigurationsPerFailureMechanismSection.Single();

            scenarioConfigurationPerFailureMechanismSection.ScenarioConfigurationType = configurationType;

            // Call
            IFailureMechanismSectionResultCalculateProbabilityStrategy strategy =
                PipingFailureMechanismSectionResultCalculateProbabilityStrategyFactory.CreateCalculateStrategy(
                    failureMechanism.SectionResults.Single(), failureMechanism, assessmentSection);

            // Assert
            Assert.IsInstanceOf <ProbabilisticPipingFailureMechanismSectionResultCalculateProbabilityStrategy>(strategy);
        }
        public void AssembleSection_CalculatorThrowsException_ThrowsAssemblyException()
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            var failureMechanism  = new GrassCoverErosionOutwardsFailureMechanism();
            var assessmentSection = new AssessmentSectionStub();

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
                calculator.ThrowExceptionOnCalculate = true;

                // Call
                void Call() => GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.AssembleSection(
                    sectionResult, failureMechanism, assessmentSection);

                // Assert
                var       exception      = Assert.Throws <AssemblyException>(Call);
                Exception innerException = exception.InnerException;
                Assert.IsInstanceOf <FailureMechanismSectionAssemblyCalculatorException>(innerException);
                Assert.AreEqual(innerException.Message, exception.Message);
            }
        }
示例#12
0
        public void UpdateSectionsWithImportedData_WithEmptyData_ClearsSectionsAndUpdatesPathAndReturnsAffectedObjects()
        {
            // Setup
            const string oldSourcePath = "old/path";
            string       sourcePath    = TestHelper.GetScratchPadPath();

            var failureMechanism = new TestFailureMechanism();

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, oldSourcePath);

            var failureMechanismSectionReplaceStrategy = new FailureMechanismSectionReplaceStrategy(failureMechanism);

            // Precondition
            IEnumerable <FailureMechanismSection> failureMechanismSections = failureMechanism.Sections;

            Assert.AreEqual(1, failureMechanismSections.Count());
            Assert.AreEqual(oldSourcePath, failureMechanism.FailureMechanismSectionSourcePath);

            // Call
            IEnumerable <IObservable> affectedObjects = failureMechanismSectionReplaceStrategy.UpdateSectionsWithImportedData(Enumerable.Empty <FailureMechanismSection>(), sourcePath);

            // Assert
            Assert.AreEqual(sourcePath, failureMechanism.FailureMechanismSectionSourcePath);
            Assert.IsEmpty(failureMechanismSections);
            CollectionAssert.AreEqual(new IObservable[]
            {
                failureMechanism,
                failureMechanism.SectionResults
            }, affectedObjects);
        }
示例#13
0
        public void UpdateSectionsWithImportedData_WithInvalidSections_ThrowsUpdateDataException()
        {
            // Setup
            string sourcePath = TestHelper.GetScratchPadPath();

            var failureMechanism = new TestFailureMechanism();
            FailureMechanismSection failureMechanismSection1 = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
            {
                new Point2D(0.0, 0.0),
                new Point2D(5.0, 5.0)
            });
            FailureMechanismSection failureMechanismSection2 = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
            {
                new Point2D(10.0, 10.0),
                new Point2D(15.0, 15.0)
            });

            var failureMechanismSectionReplaceStrategy = new FailureMechanismSectionReplaceStrategy(failureMechanism);

            FailureMechanismSection[] sections =
            {
                failureMechanismSection1,
                failureMechanismSection2
            };

            // Call
            void Call() => failureMechanismSectionReplaceStrategy.UpdateSectionsWithImportedData(sections, sourcePath);

            // Assert
            var exception = Assert.Throws <UpdateDataException>(Call);

            Assert.IsInstanceOf <ArgumentException>(exception.InnerException);
            Assert.AreEqual(exception.InnerException.Message, exception.Message);
        }
        public void GetInitialFailureMechanismResultProbability_MultipleScenarios_ReturnsValueBasedOnRelevantScenarios()
        {
            // Setup
            FailureMechanismSection section   = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var failureMechanismSectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            const double factorOfStability1 = 1.0 / 10.0;
            const double factorOfStability2 = 1.0 / 20.0;

            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario1 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability1, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability2, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario3 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario(section);

            macroStabilityInwardsCalculationScenario1.Contribution = (RoundedDouble)0.2111;
            macroStabilityInwardsCalculationScenario2.Contribution = (RoundedDouble)0.7889;

            MacroStabilityInwardsCalculationScenario[] calculations =
            {
                macroStabilityInwardsCalculationScenario1,
                macroStabilityInwardsCalculationScenario2,
                macroStabilityInwardsCalculationScenario3
            };

            // Call
            double initialFailureMechanismResultProbability = failureMechanismSectionResult.GetInitialFailureMechanismResultProbability(calculations, 1.1);

            // Assert
            Assert.AreEqual(0.99052414832077185, initialFailureMechanismResultProbability);
        }
        public void AssembleFailureMechanism_WithInput_SetsInputOnCalculator()
        {
            // Setup
            var failureMechanism = new DuneErosionFailureMechanism
            {
                AssemblyResult =
                {
                    ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Automatic
                }
            };

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, "APath");

            var assessmentSection = new AssessmentSectionStub();

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;

                FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator;

                // Call
                DuneErosionFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection);

                // Assert
                Assert.AreEqual(failureMechanism.GeneralInput.N, failureMechanismAssemblyCalculator.FailureMechanismN);
                Assert.AreSame(calculator.FailureMechanismSectionAssemblyResultOutput.AssemblyResult, failureMechanismAssemblyCalculator.SectionAssemblyResultsInput.Single());
                Assert.AreEqual(failureMechanism.GeneralInput.ApplyLengthEffectInSection, failureMechanismAssemblyCalculator.ApplyLengthEffect);
            }
        }
        private static void Property_SetNewValue_NotifyObserversAndPropertyChanged <T>(
            Action <NonAdoptableFailureMechanismSectionResultRow> setPropertyAction,
            Func <NonAdoptableFailureMechanismSectionResult, T> assertPropertyFunc,
            T newValue)
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();
            var observer      = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableFailureMechanismSectionResult(section);

            result.Attach(observer);

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var row = new NonAdoptableFailureMechanismSectionResultRow(result, errorProvider, new AssessmentSectionStub(), ConstructionProperties);

                // Call
                setPropertyAction(row);

                // Assert
                Assert.AreEqual(newValue, assertPropertyFunc(result));
            }

            mocks.VerifyAll();
        }
示例#17
0
        public void GetCalculatedProbabilityValidationError_TotalContributionNotOne_ReturnsErrorMessage(double contribution)
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new TestFailureMechanismSectionResult(section);

            var calculationScenarios = new[]
            {
                new TestCalculationScenario
                {
                    Contribution = (RoundedDouble)0.5
                },
                new TestCalculationScenario
                {
                    Contribution = (RoundedDouble)contribution
                }
            };

            var errorProvider = new FailureMechanismSectionResultRowWithCalculatedProbabilityErrorProvider <ICalculationScenario>(
                sectionResult, calculationScenarios, (scenario, segments) => true);

            // Call
            string errorMessage = errorProvider.GetCalculatedProbabilityValidationError(() => double.NaN);

            // Assert
            Assert.AreEqual("De bijdragen van de maatgevende scenario's voor dit vak moeten opgeteld gelijk zijn aan 100%.", errorMessage);
        }
        public void Constructor_AssemblyRan_InputCorrectlySetOnCalculator()
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            mocks.ReplayAll();

            var assessmentSection = new AssessmentSectionStub();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableFailureMechanismSectionResult(section);

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;

                // Call
                var row = new NonAdoptableFailureMechanismSectionResultRow(result, errorProvider, assessmentSection, ConstructionProperties);

                // Assert
                FailureMechanismSectionAssemblyInput input = calculator.FailureMechanismSectionAssemblyInput;
                Assert.AreEqual(assessmentSection.FailureMechanismContribution.SignalFloodingProbability, input.SignalFloodingProbability);
                Assert.AreEqual(assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability, input.MaximumAllowableFloodingProbability);
                Assert.AreEqual(row.IsRelevant, input.IsRelevant);
                Assert.IsTrue(input.HasProbabilitySpecified);
                Assert.AreEqual(row.InitialFailureMechanismResultSectionProbability, input.InitialSectionProbability);
                Assert.AreEqual(row.FurtherAnalysisType, input.FurtherAnalysisType);
                Assert.AreEqual(row.RefinedSectionProbability, input.RefinedSectionProbability);
            }

            mocks.VerifyAll();
        }
        public void FailureMechanismResultsView_AllDataSet_DataGridViewCorrectlyInitialized()
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1");

            var failureMechanism = new TestNonAdoptableFailureMechanism();

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                section
            });

            // Call
            using (new AssemblyToolCalculatorFactoryConfig())
                using (ShowFailureMechanismResultsView(failureMechanism))
                {
                    DataGridView dataGridView = GetDataGridView();

                    // Assert
                    DataGridViewRowCollection rows = dataGridView.Rows;
                    Assert.AreEqual(1, rows.Count);

                    DataGridViewCellCollection cells = rows[0].Cells;
                    Assert.AreEqual(columnCount, cells.Count);
                    Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue);
                    Assert.AreEqual(true, cells[isRelevantIndex].Value);
                    Assert.AreEqual(NonAdoptableInitialFailureMechanismResultType.Manual, cells[initialFailureMechanismResultTypeIndex].Value);
                    Assert.AreEqual("-", cells[initialFailureMechanismResultSectionProbabilityIndex].FormattedValue);
                    Assert.AreEqual(FailureMechanismSectionResultFurtherAnalysisType.NotNecessary, cells[furtherAnalysisTypeIndex].Value);
                    Assert.AreEqual("-", cells[refinedSectionProbabilityIndex].FormattedValue);
                    Assert.AreEqual("1/10", cells[sectionProbabilityIndex].FormattedValue);
                    Assert.AreEqual("+I", cells[assemblyGroupIndex].FormattedValue);
                }
        }
        public void Constructor_AssemblyRan_ReturnsAssemblyResult()
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            mocks.ReplayAll();

            var random = new Random(39);

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableFailureMechanismSectionResult(section);

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
                calculator.FailureMechanismSectionAssemblyResultOutput = new FailureMechanismSectionAssemblyResultWrapper(
                    new FailureMechanismSectionAssemblyResult(random.NextDouble(), random.NextDouble(), random.NextDouble(),
                                                              random.NextEnumValue <FailureMechanismSectionAssemblyGroup>()),
                    random.NextEnumValue <AssemblyMethod>(), random.NextEnumValue <AssemblyMethod>());

                // Call
                var row = new NonAdoptableFailureMechanismSectionResultRow(result, errorProvider, new AssessmentSectionStub(), ConstructionProperties);

                // Assert
                FailureMechanismSectionAssemblyResult calculatorOutput = calculator.FailureMechanismSectionAssemblyResultOutput.AssemblyResult;
                Assert.AreEqual(calculatorOutput.SectionProbability, row.SectionProbability);
                Assert.AreEqual(EnumDisplayNameHelper.GetDisplayName(calculatorOutput.FailureMechanismSectionAssemblyGroup),
                                row.AssemblyGroup);
            }

            mocks.VerifyAll();
        }
示例#21
0
        public void FailureMechanismResultsView_AllDataSet_SetsCorrectInputOnCalculator()
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();

            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                section
            });

            var assessmentSection = new AssessmentSectionStub();

            // Call
            using (new AssemblyToolCalculatorFactoryConfig())
                using (ShowFailureMechanismResultsView(failureMechanism, assessmentSection))
                {
                    // Assert
                    var testFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                    FailureMechanismAssemblyCalculatorStub calculator = testFactory.LastCreatedFailureMechanismAssemblyCalculator;

                    Assert.AreEqual(failureMechanism.GeneralInput.N, calculator.FailureMechanismN);
                }
        }
        public void GivenRowWithAssemblyErrors_WhenUpdatingAndAssemblyDoesNotThrowException_ThenNoErrorShown()
        {
            // Given
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableFailureMechanismSectionResult(section);

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
                calculator.ThrowExceptionOnCalculate = true;

                var row = new NonAdoptableFailureMechanismSectionResultRow(result, errorProvider, new AssessmentSectionStub(), ConstructionProperties);

                // Precondition
                IDictionary <int, DataGridViewColumnStateDefinition> columnStateDefinitions = row.ColumnStateDefinitions;
                const string expectedErrorText = "Message";

                Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.SectionProbabilityIndex].ErrorText);
                Assert.AreEqual(expectedErrorText, columnStateDefinitions[ConstructionProperties.AssemblyGroupIndex].ErrorText);

                // When
                calculator.ThrowExceptionOnCalculate  = false;
                row.InitialFailureMechanismResultType = NonAdoptableInitialFailureMechanismResultType.NoFailureProbability;

                // Then
                Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.SectionProbabilityIndex].ErrorText);
                Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.AssemblyGroupIndex].ErrorText);
            }
        }
示例#23
0
        private static void Property_SetNewValue_NotifyObserversAndPropertyChanged <T>(
            Action <NonAdoptableWithProfileProbabilityFailureMechanismSectionResultRow> setPropertyAction,
            Func <NonAdoptableWithProfileProbabilityFailureMechanismSectionResult, T> assertPropertyFunc,
            T newValue)
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();
            var observer      = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            result.Attach(observer);

            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create;
            var row = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResultRow(result, errorProvider, performAssemblyFunc, ConstructionProperties);

            // Call
            setPropertyAction(row);

            // Assert
            Assert.AreEqual(newValue, assertPropertyFunc(result));

            mocks.VerifyAll();
        }
        public void Constructor_Always_ExpectedColumnStates()
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableFailureMechanismSectionResult(section);

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                // Call
                var row = new NonAdoptableFailureMechanismSectionResultRow(result, errorProvider, new AssessmentSectionStub(), ConstructionProperties);

                // Assert
                IDictionary <int, DataGridViewColumnStateDefinition> columnStateDefinitions = row.ColumnStateDefinitions;

                DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(
                    columnStateDefinitions[ConstructionProperties.SectionProbabilityIndex], true, true);
            }

            mocks.VerifyAll();
        }
示例#25
0
        public void Constructor_PerformAssemblyFuncReturnsResult_ReturnsAssemblyResult()
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            FailureMechanismSectionAssemblyResultWrapper        assemblyResultWrapper = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create();
            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc   = () => assemblyResultWrapper;

            // Call
            var row = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResultRow(result, errorProvider, performAssemblyFunc, ConstructionProperties);

            // Assert
            FailureMechanismSectionAssemblyResult assemblyResult = assemblyResultWrapper.AssemblyResult;

            Assert.AreEqual(assemblyResult.ProfileProbability, row.ProfileProbability);
            Assert.AreEqual(assemblyResult.SectionProbability, row.SectionProbability);
            Assert.AreEqual(assemblyResult.N, row.SectionN, row.SectionN.GetAccuracy());
            Assert.AreEqual(2, row.SectionN.NumberOfDecimalPlaces);
            Assert.AreEqual(EnumDisplayNameHelper.GetDisplayName(assemblyResult.FailureMechanismSectionAssemblyGroup),
                            row.AssemblyGroup);

            mocks.VerifyAll();
        }
        public void Constructor_WithInitialFailureMechanismResultType_ExpectedColumnStates(NonAdoptableInitialFailureMechanismResultType initialFailureMechanismResultType,
                                                                                           bool isEnabled, bool isReadOnly)
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            errorProvider.Stub(ep => ep.GetManualProbabilityValidationError(double.NaN))
            .IgnoreArguments()
            .Return(string.Empty);
            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableFailureMechanismSectionResult(section)
            {
                InitialFailureMechanismResultType = initialFailureMechanismResultType
            };

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                // Call
                var row = new NonAdoptableFailureMechanismSectionResultRow(result, errorProvider, new AssessmentSectionStub(), ConstructionProperties);

                // Assert
                IDictionary <int, DataGridViewColumnStateDefinition> columnStateDefinitions = row.ColumnStateDefinitions;

                DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(
                    columnStateDefinitions[ConstructionProperties.InitialFailureMechanismResultSectionProbabilityIndex], isEnabled, isReadOnly);
            }

            mocks.VerifyAll();
        }
示例#27
0
        public void Constructor_WithFurtherAnalysisType_ExpectedColumnStates(FailureMechanismSectionResultFurtherAnalysisType furtherAnalysisType,
                                                                             bool expectedDisabled)
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            errorProvider.Stub(ep => ep.GetManualProbabilityValidationError(double.NaN))
            .IgnoreArguments()
            .Return(string.Empty);
            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section)
            {
                FurtherAnalysisType = furtherAnalysisType
            };

            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create;

            // Call
            var row = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResultRow(result, errorProvider, performAssemblyFunc, ConstructionProperties);

            // Assert
            IDictionary <int, DataGridViewColumnStateDefinition> columnStateDefinitions = row.ColumnStateDefinitions;

            DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(
                columnStateDefinitions[ConstructionProperties.RefinedProfileProbabilityIndex], expectedDisabled);
            DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnState(
                columnStateDefinitions[ConstructionProperties.RefinedSectionProbabilityIndex], expectedDisabled);

            mocks.VerifyAll();
        }
        public void Constructor_WithAssemblyGroupSet_ExpectedColumnStates(FailureMechanismSectionAssemblyGroup assemblyGroup,
                                                                          Color expectedBackgroundColor)
        {
            // Setup
            var random = new Random(21);

            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableFailureMechanismSectionResult(section);

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
                calculator.FailureMechanismSectionAssemblyResultOutput = new FailureMechanismSectionAssemblyResultWrapper(
                    new FailureMechanismSectionAssemblyResult(double.NaN, double.NaN, double.NaN, assemblyGroup),
                    random.NextEnumValue <AssemblyMethod>(), random.NextEnumValue <AssemblyMethod>());

                // Call
                var row = new NonAdoptableFailureMechanismSectionResultRow(result, errorProvider, new AssessmentSectionStub(), ConstructionProperties);

                // Assert
                IDictionary <int, DataGridViewColumnStateDefinition> columnStateDefinitions = row.ColumnStateDefinitions;

                DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnWithColorState(
                    columnStateDefinitions[ConstructionProperties.AssemblyGroupIndex], expectedBackgroundColor);
            }

            mocks.VerifyAll();
        }
        public void FailureMechanismResultsView_AllDataSet_SetsCorrectInputOnCalculator()
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();

            var failureMechanism = new MacroStabilityInwardsFailureMechanism();

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                section
            });

            var assessmentSection = new AssessmentSectionStub();

            // Call
            using (new AssemblyToolCalculatorFactoryConfig())
                using (ShowFailureMechanismResultsView(failureMechanism, assessmentSection))
                {
                    // Assert
                    var testFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                    FailureMechanismAssemblyCalculatorStub calculator = testFactory.LastCreatedFailureMechanismAssemblyCalculator;

                    double expectedN = failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.GetN(assessmentSection.ReferenceLine.Length);
                    Assert.AreEqual(expectedN, calculator.FailureMechanismN);
                }
        }
示例#30
0
        public void Constructor_AssemblyRan_ReturnsAssemblyResult()
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowWithCalculatedProbabilityErrorProvider>();

            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new AdoptableFailureMechanismSectionResult(section);

            FailureMechanismSectionAssemblyResultWrapper        assemblyResultWrapper = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create();
            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc   = () => assemblyResultWrapper;

            // Call
            var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider,
                                                                    performAssemblyFunc, ConstructionProperties);

            // Assert
            var assemblyResult = assemblyResultWrapper.AssemblyResult;

            Assert.AreEqual(assemblyResult.SectionProbability, row.SectionProbability);
            Assert.AreEqual(EnumDisplayNameHelper.GetDisplayName(assemblyResult.FailureMechanismSectionAssemblyGroup),
                            row.AssemblyGroup);

            mocks.VerifyAll();
        }