public void ShouldCloseMethod_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); ICalculatableFailureMechanism failureMechanism = GetFailureMechanismWithCalculation(); assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] { failureMechanism }); mocks.ReplayAll(); using (IView view = GetView(GetCalculation())) { // Call bool closeForData = ShouldCloseMethod(view, assessmentSection); // Assert Assert.IsFalse(closeForData); } mocks.VerifyAll(); }
private static void AssertDataGridViewRow(ICalculatableFailureMechanism expectedFailureMechanism, DataGridViewCellCollection cells) { Assert.AreEqual(false, cells[isSelectedIndex].Value); Assert.AreEqual(expectedFailureMechanism.Name, cells[failureMechanismNameIndex].Value); Assert.AreEqual(expectedFailureMechanism.InAssembly, cells[inAssemblyIndex].Value); Assert.AreEqual(expectedFailureMechanism.Sections.Any(), cells[hasSectionsIndex].Value); Assert.AreEqual(expectedFailureMechanism.Calculations.Count(), cells[numberOfCalculationsIndex].Value); }
private static void ClearAllCalculationOutputInFailureMechanism(ICalculatableFailureMechanism failureMechanism) { if (MessageBox.Show(Resources.FailureMechanism_ContextMenuStrip_Are_you_sure_clear_all_output, BaseResources.Confirm, MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } foreach (ICalculation calc in failureMechanism.Calculations.Where(c => c.HasOutput)) { calc.ClearOutput(); calc.NotifyObservers(); } }
public void ShouldCloseMethod_ViewNotCorrespondingWithRemovedFailureMechanism_ReturnsFalse() { // Setup ICalculatableFailureMechanism failureMechanism = GetFailureMechanismWithCalculation(); using (IView view = GetView(GetCalculation())) { // Call bool closeForData = ShouldCloseMethod(view, failureMechanism); // Assert Assert.IsFalse(closeForData); } }
/// <summary> /// Creates a <see cref="FailureMechanismEntity"/> based on the information of the <see cref="ICalculatableFailureMechanism"/>. /// </summary> /// <param name="mechanism">The failure mechanism to create a database entity for.</param> /// <param name="type">The type of the failure mechanism that is being created.</param> /// <param name="registry">The object keeping track of create operations.</param> /// <returns>A new <see cref="FailureMechanismEntity"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="registry"/> is <c>null</c>.</exception> internal static FailureMechanismEntity Create(this ICalculatableFailureMechanism mechanism, FailureMechanismType type, PersistenceRegistry registry) { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } var entity = Create <FailureMechanismEntity>(mechanism, registry); entity.FailureMechanismType = (short)type; entity.CalculationsInputComments = mechanism.CalculationsInputComments.Body.DeepClone(); return(entity); }
/// <summary> /// Initializes a new instance of the <see cref="ForeshoreProfilesContext"/> class. /// </summary> /// <param name="foreshoreProfiles">The observable list of <see cref="ForeshoreProfile"/> objects.</param> /// <param name="parentFailureMechanism">The parent failure mechanism</param> /// <param name="parentAssessmentSection">The parent assessment section.</param> /// <exception cref="ArgumentNullException">Thrown when any input argument is <c>null</c>.</exception> public ForeshoreProfilesContext(ForeshoreProfileCollection foreshoreProfiles, ICalculatableFailureMechanism parentFailureMechanism, IAssessmentSection parentAssessmentSection) : base(foreshoreProfiles) { if (parentAssessmentSection == null) { throw new ArgumentNullException(nameof(parentAssessmentSection)); } if (parentFailureMechanism == null) { throw new ArgumentNullException(nameof(parentFailureMechanism)); } ParentAssessmentSection = parentAssessmentSection; ParentFailureMechanism = parentFailureMechanism; }
public void UpdateForeshoreProfilesWithImportedData_SupportedFailureMechanism_CalculationUpdatedAndReturnsAffectedData( ICalculatableFailureMechanism failureMechanism, ForeshoreProfileCollection foreshoreProfiles) { // Setup ICalculation <ICalculationInput>[] calculationsWithForeshoreProfiles = failureMechanism.Calculations .Cast <ICalculation <ICalculationInput> >() .Where(calc => ((IHasForeshoreProfile)calc.InputParameters).ForeshoreProfile != null) .ToArray(); ICalculation <ICalculationInput>[] calculationsWithOutput = calculationsWithForeshoreProfiles.Where(calc => calc.HasOutput) .ToArray(); // Precondition CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfiles); CollectionAssert.IsNotEmpty(calculationsWithOutput); var strategy = new ForeshoreProfileReplaceDataStrategy(failureMechanism, foreshoreProfiles); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(Enumerable.Empty <ForeshoreProfile>(), sourceFilePath); // Assert Assert.IsFalse(calculationsWithOutput.All(calc => calc.HasOutput)); Assert.IsTrue(calculationsWithForeshoreProfiles.All(calc => ((IHasForeshoreProfile)calc.InputParameters) .ForeshoreProfile == null)); CollectionAssert.IsEmpty(foreshoreProfiles); IEnumerable <IObservable> expectedAffectedObjects = calculationsWithForeshoreProfiles.Select(calc => calc.InputParameters) .Concat(new IObservable[] { foreshoreProfiles } .Concat(calculationsWithOutput)); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); }
/// <summary> /// Creates a new instance of <see cref="FailureMechanismCalculationChangeHandler"/>. /// </summary> /// <param name="failureMechanism">Failure mechanism for which to handle changes.</param> /// <param name="query">The query which should be displayed when inquiring for a confirmation.</param> /// <param name="inquiryHandler">Object responsible for inquiring required data.</param> /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception> public FailureMechanismCalculationChangeHandler(ICalculatableFailureMechanism failureMechanism, string query, IInquiryHelper inquiryHandler) { if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } if (query == null) { throw new ArgumentNullException(nameof(query)); } if (inquiryHandler == null) { throw new ArgumentNullException(nameof(inquiryHandler)); } FailureMechanism = failureMechanism; this.query = query; this.inquiryHandler = inquiryHandler; }
/// <summary> /// Assembles the section based on the input arguments. /// </summary> /// <typeparam name="TStructuresInput">The type of structures input contained by the calculation.</typeparam> /// <param name="sectionResult">The section result to assemble.</param> /// <param name="failureMechanism">The <see cref="IFailureMechanism"/> the section result belongs to.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> the section belongs to.</param> /// <returns>A <see cref="FailureMechanismSectionAssemblyResultWrapper"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any argument is <c>null</c>.</exception> /// <exception cref="AssemblyException">Thrown when the section could not be assembled.</exception> public static FailureMechanismSectionAssemblyResultWrapper AssembleSection <TStructuresInput>(AdoptableFailureMechanismSectionResult sectionResult, ICalculatableFailureMechanism failureMechanism, IAssessmentSection assessmentSection) where TStructuresInput : IStructuresCalculationInput <StructureBase>, new() { if (sectionResult == null) { throw new ArgumentNullException(nameof(sectionResult)); } if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } StructuresCalculationScenario <TStructuresInput>[] calculationScenarios = failureMechanism.Calculations .OfType <StructuresCalculationScenario <TStructuresInput> >() .ToArray(); return(FailureMechanismSectionAssemblyResultFactory.AssembleSection( sectionResult, assessmentSection, () => sectionResult.GetInitialFailureMechanismResultProbability(calculationScenarios))); }
public void UpdateForeshoreProfilesWithImportedData_SupportedFailureMechanisms_UpdatesAffectedCalculationAndReturnsAffectedData( ICalculatableFailureMechanism failureMechanism, ForeshoreProfileCollection foreshoreProfiles, ForeshoreProfile unaffectedForeshoreProfile) { // Setup ForeshoreProfile profileToBeUpdated = foreshoreProfiles[0]; ForeshoreProfile profileToUpdateFrom = DeepCloneAndModify(profileToBeUpdated); ForeshoreProfile profileToBeRemoved = foreshoreProfiles[1]; var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles); ICalculation <ICalculationInput>[] calculationsWithUpdatedForeshoreProfile = failureMechanism.Calculations .Cast <ICalculation <ICalculationInput> >() .Where(calc => ReferenceEquals(GetForeshoreProfile(calc), profileToBeUpdated)) .ToArray(); ICalculation <ICalculationInput>[] calculationsWithUpdatedForeshoreProfileWithOutputs = calculationsWithUpdatedForeshoreProfile.Where(calc => calc.HasOutput) .ToArray(); ICalculation <ICalculationInput>[] calculationsWithRemovedForeshoreProfile = failureMechanism.Calculations .Cast <ICalculation <ICalculationInput> >() .Where(calc => ReferenceEquals(GetForeshoreProfile(calc), profileToBeRemoved)) .ToArray(); ICalculation <ICalculationInput>[] calculationsWithRemovedForeshoreProfileWithOutputs = calculationsWithRemovedForeshoreProfile.Where(calc => calc.HasOutput) .ToArray(); ICalculation <ICalculationInput>[] calculationsWithUnaffectedForeshoreProfile = failureMechanism.Calculations .Cast <ICalculation <ICalculationInput> >() .Where(calc => ReferenceEquals(GetForeshoreProfile(calc), unaffectedForeshoreProfile)) .ToArray(); ICalculation <ICalculationInput>[] calculationsWithUnaffectedForeshoreProfileAndOutput = failureMechanism.Calculations .Cast <ICalculation <ICalculationInput> >() .Where(calc => ReferenceEquals(GetForeshoreProfile(calc), unaffectedForeshoreProfile)) .ToArray(); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(new[] { profileToUpdateFrom, new TestForeshoreProfile(unaffectedForeshoreProfile.Name, unaffectedForeshoreProfile.Id) }, sourceFilePath); // Assert Assert.IsTrue(calculationsWithUnaffectedForeshoreProfileAndOutput.All(calc => calc.HasOutput)); Assert.IsTrue(calculationsWithUnaffectedForeshoreProfile.All(calc => ReferenceEquals(GetForeshoreProfile(calc), unaffectedForeshoreProfile))); Assert.IsTrue(calculationsWithUpdatedForeshoreProfile.All(calc => !calc.HasOutput)); Assert.IsTrue(calculationsWithUpdatedForeshoreProfile.All(calc => ReferenceEquals(GetForeshoreProfile(calc), profileToBeUpdated))); Assert.IsTrue(calculationsWithRemovedForeshoreProfile.All(calc => !calc.HasOutput)); Assert.IsTrue(calculationsWithRemovedForeshoreProfile.All(calc => GetForeshoreProfile(calc) == null)); var expectedAffectedObjects = new List <IObservable> { foreshoreProfiles, profileToBeUpdated }; expectedAffectedObjects.AddRange(calculationsWithUpdatedForeshoreProfileWithOutputs); expectedAffectedObjects.AddRange(calculationsWithRemovedForeshoreProfileWithOutputs); expectedAffectedObjects.AddRange(calculationsWithUpdatedForeshoreProfile.Select(calc => calc.InputParameters)); expectedAffectedObjects.AddRange(calculationsWithRemovedForeshoreProfile.Select(calc => calc.InputParameters)); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); }
/// <summary> /// Adds an item to the <see cref="ContextMenuStrip"/>, which clears the output of all calculations in the failure mechanism. /// </summary> /// <param name="failureMechanism">The failure mechanism to clear the output for.</param> /// <returns>The <see cref="RiskeerContextMenuBuilder"/> itself.</returns> public RiskeerContextMenuBuilder AddClearAllCalculationOutputInFailureMechanismItem(ICalculatableFailureMechanism failureMechanism) { contextMenuBuilder.AddCustomItem(RiskeerContextMenuItemFactory.CreateClearAllCalculationOutputInFailureMechanismItem(failureMechanism)); return(this); }
/// <summary> /// Creates a <see cref="StrictContextMenuItem"/> which is bound to the action of clearing the output of all calculations in a failure mechanism. /// </summary> /// <param name="failureMechanism">The failure mechanism to clear the output for.</param> /// <returns>The created <see cref="StrictContextMenuItem"/>.</returns> public static StrictContextMenuItem CreateClearAllCalculationOutputInFailureMechanismItem(ICalculatableFailureMechanism failureMechanism) { var clearAllItem = new StrictContextMenuItem( Resources.Clear_all_output, Resources.Clear_all_output_ToolTip, Resources.ClearIcon, (o, args) => ClearAllCalculationOutputInFailureMechanism(failureMechanism)); if (!failureMechanism.Calculations.Any(c => c.HasOutput)) { clearAllItem.Enabled = false; clearAllItem.ToolTipText = Resources.CalculationGroup_ClearOutput_No_calculation_with_output_to_clear; } return(clearAllItem); }
/// <summary> /// Creates a new instance of <see cref="CalculatableFailureMechanismMergeDataRow"/>. /// </summary> /// <param name="failureMechanism">The wrapped <see cref="ICalculatableFailureMechanism"/>.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="failureMechanism"/> /// is <c>null</c>.</exception> public CalculatableFailureMechanismMergeDataRow(ICalculatableFailureMechanism failureMechanism) : base(failureMechanism) { this.failureMechanism = failureMechanism; }