Пример #1
0
        public void CloseForData_AssessmentSectionRemovedWithoutFailureMechanism_ReturnsFalse()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(Array.Empty <IFailureMechanism>());
            assessmentSection.Stub(asm => asm.SpecificFailureMechanisms).Return(new ObservableList <SpecificFailureMechanism>());
            mocks.ReplayAll();

            var failureMechanism = new GrassCoverSlipOffOutwardsFailureMechanism();

            using (var view = new NonAdoptableWithProfileProbabilityFailureMechanismResultView <GrassCoverSlipOffOutwardsFailureMechanism>(
                       failureMechanism.SectionResults, failureMechanism, assessmentSection,
                       (fm, ass) => new FailureMechanismAssemblyResultWrapper(double.NaN, AssemblyMethod.Manual),
                       fm => fm.GeneralInput.ApplyLengthEffectInSection,
                       sr => FailureMechanismSectionAssemblyResultWrapperTestFactory.Create()))
            {
                // Call
                bool closeForData = info.CloseForData(view, assessmentSection);

                // Assert
                Assert.IsFalse(closeForData);
            }

            mocks.VerifyAll();
        }
        public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue()
        {
            // Setup
            var failureMechanism = new MicrostabilityFailureMechanism();

            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new IFailureMechanism[]
            {
                failureMechanism
            });
            mocks.ReplayAll();

            using (var view = new NonAdoptableWithProfileProbabilityFailureMechanismResultView <MicrostabilityFailureMechanism>(
                       failureMechanism.SectionResults, failureMechanism, assessmentSection,
                       (fm, ass) => new FailureMechanismAssemblyResultWrapper(double.NaN, AssemblyMethod.Manual),
                       fm => fm.GeneralInput.ApplyLengthEffectInSection,
                       sr => FailureMechanismSectionAssemblyResultWrapperTestFactory.Create()))
            {
                // Call
                bool closeForData = info.CloseForData(view, assessmentSection);

                // Assert
                Assert.IsTrue(closeForData);
            }

            mocks.VerifyAll();
        }
Пример #3
0
        public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse()
        {
            // Setup
            var assessmentSection       = mocks.Stub <IAssessmentSection>();
            var failureMechanismContext = mocks.StrictMock <IFailureMechanismContext <IFailureMechanism> >();

            failureMechanismContext.Expect(fm => fm.WrappedData).Return(new GrassCoverSlipOffOutwardsFailureMechanism());
            mocks.ReplayAll();

            var failureMechanism = new GrassCoverSlipOffOutwardsFailureMechanism();

            using (var view = new NonAdoptableWithProfileProbabilityFailureMechanismResultView <GrassCoverSlipOffOutwardsFailureMechanism>(
                       failureMechanism.SectionResults, failureMechanism, assessmentSection,
                       (fm, ass) => new FailureMechanismAssemblyResultWrapper(double.NaN, AssemblyMethod.Manual),
                       fm => fm.GeneralInput.ApplyLengthEffectInSection,
                       sr => FailureMechanismSectionAssemblyResultWrapperTestFactory.Create()))
            {
                // Call
                bool closeForData = info.CloseForData(view, failureMechanismContext);

                // Assert
                Assert.IsFalse(closeForData);
            }

            mocks.VerifyAll();
        }
Пример #4
0
        public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue()
        {
            // Setup
            var failureMechanism = new SpecificFailureMechanism();

            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(Array.Empty <IFailureMechanism>());
            assessmentSection.Stub(asm => asm.SpecificFailureMechanisms).Return(new ObservableList <SpecificFailureMechanism>
            {
                failureMechanism
            });
            mocks.ReplayAll();

            using (var view = new NonAdoptableWithProfileProbabilityFailureMechanismResultView <SpecificFailureMechanism>(
                       failureMechanism.SectionResults, failureMechanism, assessmentSection,
                       (fm, ass) => new FailureMechanismAssemblyResultWrapper(double.NaN, AssemblyMethod.Manual),
                       fm => true,
                       sr => FailureMechanismSectionAssemblyResultWrapperTestFactory.Create()))
            {
                // Call
                bool closeForData = info.CloseForData(view, assessmentSection);

                // Assert
                Assert.IsTrue(closeForData);
            }

            mocks.VerifyAll();
        }
Пример #5
0
        public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism        = new SpecificFailureMechanism();
            var failureMechanismContext = new SpecificFailureMechanismContext(new SpecificFailureMechanism(), assessmentSection);

            using (var view = new NonAdoptableWithProfileProbabilityFailureMechanismResultView <SpecificFailureMechanism>(
                       failureMechanism.SectionResults, failureMechanism, assessmentSection,
                       (fm, ass) => new FailureMechanismAssemblyResultWrapper(double.NaN, AssemblyMethod.Manual),
                       fm => true,
                       sr => FailureMechanismSectionAssemblyResultWrapperTestFactory.Create()))
            {
                // Call
                bool closeForData = info.CloseForData(view, failureMechanismContext);

                // Assert
                Assert.IsFalse(closeForData);
            }

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

            var failureMechanism = new TestNonAdoptableWithProfileProbabilityFailureMechanism();

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

            NonAdoptableWithProfileProbabilityFailureMechanismSectionResult functionInput = null;
            Func <NonAdoptableWithProfileProbabilityFailureMechanismSectionResult, FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = sr =>
            {
                functionInput = sr;
                return(FailureMechanismSectionAssemblyResultWrapperTestFactory.Create());
            };

            // Call
            using (ShowFailureMechanismResultsView(failureMechanism, performAssemblyFunc))
            {
                // Assert
                Assert.AreSame(functionInput, failureMechanism.SectionResults.Single());
            }
        }
        public void CloseForData_AssessmentSectionRemovedWithoutFailureMechanism_ReturnsFalse()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(Array.Empty <IFailureMechanism>());
            mocks.ReplayAll();

            var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();

            using (var view = new NonAdoptableWithProfileProbabilityFailureMechanismResultView <WaveImpactAsphaltCoverFailureMechanism>(
                       failureMechanism.SectionResults, failureMechanism, assessmentSection,
                       (fm, ass) => new FailureMechanismAssemblyResultWrapper(double.NaN, AssemblyMethod.Manual),
                       fm => true,
                       sr => FailureMechanismSectionAssemblyResultWrapperTestFactory.Create()))
            {
                // Call
                bool closeForData = info.CloseForData(view, assessmentSection);

                // Assert
                Assert.IsFalse(closeForData);
            }

            mocks.VerifyAll();
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new TestNonAdoptableWithProfileProbabilityFailureMechanism();

            Func <NonAdoptableWithProfileProbabilityFailureMechanismSectionResult, FailureMechanismSectionAssemblyResultWrapper> performFailureMechanismSectionAssemblyFunc =
                sr => FailureMechanismSectionAssemblyResultWrapperTestFactory.Create();

            // Call
            using (var view = new NonAdoptableWithProfileProbabilityFailureMechanismResultView <TestNonAdoptableWithProfileProbabilityFailureMechanism>(
                       failureMechanism.SectionResults, failureMechanism, assessmentSection,
                       (fm, ass) => new FailureMechanismAssemblyResultWrapper(double.NaN, AssemblyMethod.Manual),
                       fm => false, performFailureMechanismSectionAssemblyFunc))
            {
                // Assert
                Assert.IsInstanceOf <FailureMechanismResultView <NonAdoptableWithProfileProbabilityFailureMechanismSectionResult,
                                                                 NonAdoptableWithProfileProbabilityFailureMechanismSectionResultRow,
                                                                 TestNonAdoptableWithProfileProbabilityFailureMechanism> >(view);
                Assert.IsNull(view.Data);
                Assert.AreSame(failureMechanism, view.FailureMechanism);
            }

            mocks.VerifyAll();
        }
Пример #9
0
        public void GivenRowWithoutAssemblyErrors_WhenUpdatingAndPerformAssemblyThrowsException_ThenShowError()
        {
            // Given
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            mocks.ReplayAll();

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

            var nrOfCalls = 0;
            FailureMechanismSectionAssemblyResultWrapper assemblyResultWrapper = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create();

            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = () =>
            {
                if (nrOfCalls == 1)
                {
                    throw new AssemblyException();
                }

                nrOfCalls++;
                return(assemblyResultWrapper);
            };

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

            // Precondition
            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);

            // When
            row.InitialFailureMechanismResultType = NonAdoptableInitialFailureMechanismResultType.NoFailureProbability;

            // Then
            var expectedAssemblyResult = new DefaultFailureMechanismSectionAssemblyResult();

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

            mocks.VerifyAll();
        }
Пример #10
0
        public void GivenRowWithoutAssemblyErrors_WhenUpdatingAndAssemblyThrowsException_ThenAssemblyPropertiesSetToDefault()
        {
            // Given
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowWithCalculatedProbabilityErrorProvider>();

            mocks.ReplayAll();

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

            var nrOfCalls = 0;
            FailureMechanismSectionAssemblyResultWrapper assemblyResultWrapper = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create();

            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = () =>
            {
                if (nrOfCalls == 1)
                {
                    throw new AssemblyException();
                }

                nrOfCalls++;
                return(assemblyResultWrapper);
            };

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

            // Precondition
            FailureMechanismSectionAssemblyResult assemblyResult = assemblyResultWrapper.AssemblyResult;

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

            // When
            row.InitialFailureMechanismResultType = AdoptableInitialFailureMechanismResultType.Manual;

            // Then
            var expectedAssemblyResult = new DefaultFailureMechanismSectionAssemblyResult();

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

            mocks.VerifyAll();
        }
Пример #11
0
        public void GivenRowWithAssemblyErrors_WhenUpdatingAndAssemblyDoesNotThrowException_ThenNoErrorShown()
        {
            // Given
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            mocks.ReplayAll();

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

            const string errorText = "Message";
            int          nrOfCalls = 0;
            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = () =>
            {
                if (nrOfCalls == 0)
                {
                    nrOfCalls++;
                    throw new AssemblyException(errorText);
                }

                return(FailureMechanismSectionAssemblyResultWrapperTestFactory.Create());
            };

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

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

            Assert.AreEqual(errorText, columnStateDefinitions[ConstructionProperties.ProfileProbabilityIndex].ErrorText);
            Assert.AreEqual(errorText, columnStateDefinitions[ConstructionProperties.SectionProbabilityIndex].ErrorText);
            Assert.AreEqual(errorText, columnStateDefinitions[ConstructionProperties.SectionNIndex].ErrorText);
            Assert.AreEqual(errorText, columnStateDefinitions[ConstructionProperties.AssemblyGroupIndex].ErrorText);

            // When
            row.InitialFailureMechanismResultType = NonAdoptableInitialFailureMechanismResultType.NoFailureProbability;

            // Then
            Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.ProfileProbabilityIndex].ErrorText);
            Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.SectionProbabilityIndex].ErrorText);
            Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.SectionNIndex].ErrorText);
            Assert.AreEqual(string.Empty, columnStateDefinitions[ConstructionProperties.AssemblyGroupIndex].ErrorText);

            mocks.VerifyAll();
        }
Пример #12
0
        public void CreateExportableFailureMechanism_WithValidData_ReturnsExportableFailureMechanism()
        {
            // Setup
            var random           = new Random(21);
            var failureMechanism = new TestFailureMechanism();

            FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(2, 10));
            var assessmentSection = new AssessmentSectionStub();

            double probability    = random.NextDouble();
            var    assemblyMethod = random.NextEnumValue <AssemblyMethod>();
            FailureMechanismSectionAssemblyResultWrapper expectedSectionOutput = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create();

            var failureMechanismType = random.NextEnumValue <ExportableFailureMechanismType>();

            // Call
            ExportableFailureMechanism exportableFailureMechanism =
                ExportableFailureMechanismFactory.CreateExportableFailureMechanism <TestFailureMechanism, TestFailureMechanismSectionResult>(
                    failureMechanism, assessmentSection, (fm, section) => new FailureMechanismAssemblyResultWrapper(probability, assemblyMethod),
                    (sr, fm, section) => expectedSectionOutput, failureMechanismType);

            // Assert
            Assert.AreEqual(failureMechanismType, exportableFailureMechanism.FailureMechanismType);
            Assert.AreEqual(failureMechanism.Code, exportableFailureMechanism.Code);

            ExportableFailureMechanismAssemblyResult exportableFailureMechanismAssembly = exportableFailureMechanism.FailureMechanismAssembly;

            Assert.AreEqual(probability, exportableFailureMechanismAssembly.Probability);
            Assert.AreEqual(ExportableAssemblyMethodFactory.Create(assemblyMethod), exportableFailureMechanismAssembly.AssemblyMethod);

            IEnumerable <ExportableFailureMechanismSection> exportableFailureMechanismSections = exportableFailureMechanism.SectionAssemblyResults
                                                                                                 .Select(sar => sar.FailureMechanismSection);

            ExportableFailureMechanismSectionTestHelper.AssertExportableFailureMechanismSections(failureMechanism.Sections, exportableFailureMechanismSections);

            ExportableFailureMechanismSectionAssemblyResultTestHelper.AssertExportableFailureMechanismSectionResults(
                expectedSectionOutput, exportableFailureMechanismSections, exportableFailureMechanism.SectionAssemblyResults);
        }
        public void Constructor_GetUseLengthEffectFuncNull_ThrowsArgumentNullException()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new TestNonAdoptableWithProfileProbabilityFailureMechanism();
            Func <NonAdoptableWithProfileProbabilityFailureMechanismSectionResult, FailureMechanismSectionAssemblyResultWrapper> performFailureMechanismSectionAssemblyFunc =
                sr => FailureMechanismSectionAssemblyResultWrapperTestFactory.Create();

            // Call
            void Call() => new NonAdoptableWithProfileProbabilityFailureMechanismResultView <TestNonAdoptableWithProfileProbabilityFailureMechanism>(
                failureMechanism.SectionResults, failureMechanism, assessmentSection,
                (fm, ass) => null, null, performFailureMechanismSectionAssemblyFunc);

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

            Assert.AreEqual("getUseLengthEffectFunc", exception.ParamName);
            mocks.VerifyAll();
        }
Пример #14
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();
        }
Пример #15
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();
        }
 private NonAdoptableWithProfileProbabilityFailureMechanismResultView <TestNonAdoptableWithProfileProbabilityFailureMechanism> ShowFailureMechanismResultsView(
     TestNonAdoptableWithProfileProbabilityFailureMechanism failureMechanism)
 {
     return(ShowFailureMechanismResultsView(failureMechanism, sr => FailureMechanismSectionAssemblyResultWrapperTestFactory.Create()));
 }