Index: Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs =================================================================== diff -u -rdf4c00ab0791a8733465352ba143372e180bae3b -r6f08c10d29c1338113ab7c2c5eb19d6f2aa0fd30 --- Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision df4c00ab0791a8733465352ba143372e180bae3b) +++ Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision 6f08c10d29c1338113ab7c2c5eb19d6f2aa0fd30) @@ -102,7 +102,8 @@ { GetViewName = (view, context) => context.WrappedData.Name, Image = RiskeerCommonFormsResources.FailureMechanismIcon, - CreateInstance = context => new StabilityPointStructuresFailurePathView(context.WrappedData, context.Parent) + CreateInstance = context => new StabilityPointStructuresFailurePathView(context.WrappedData, context.Parent), + CloseForData = CloseFailurePathViewForData }; yield return new ViewInfo< @@ -286,6 +287,16 @@ #region ViewInfos + private static bool CloseFailurePathViewForData(StabilityPointStructuresFailurePathView view, object dataToCloseFor) + { + var assessmentSection = dataToCloseFor as IAssessmentSection; + var failureMechanism = dataToCloseFor as StabilityPointStructuresFailureMechanism; + + return assessmentSection != null + ? ReferenceEquals(view.AssessmentSection, assessmentSection) + : ReferenceEquals(view.FailureMechanism, failureMechanism); + } + private static bool CloseFailureMechanismResultViewForData(StabilityPointStructuresFailureMechanismResultView view, object dataToCloseFor) { StabilityPointStructuresFailureMechanism failureMechanism = null; Index: Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Plugin.Test/ViewInfos/StabilityPointStructuresFailurePathViewInfoTest.cs =================================================================== diff -u -r37079ed26ef3699cfc8d94f55f8b867ffb933663 -r6f08c10d29c1338113ab7c2c5eb19d6f2aa0fd30 --- Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Plugin.Test/ViewInfos/StabilityPointStructuresFailurePathViewInfoTest.cs (.../StabilityPointStructuresFailurePathViewInfoTest.cs) (revision 37079ed26ef3699cfc8d94f55f8b867ffb933663) +++ Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Plugin.Test/ViewInfos/StabilityPointStructuresFailurePathViewInfoTest.cs (.../StabilityPointStructuresFailurePathViewInfoTest.cs) (revision 6f08c10d29c1338113ab7c2c5eb19d6f2aa0fd30) @@ -93,8 +93,78 @@ } [Test] + public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var otherAssessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var view = new StabilityPointStructuresFailurePathView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, otherAssessmentSection); + + // Assert + Assert.IsFalse(closeForData); + + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var view = new StabilityPointStructuresFailurePathView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var otherStabilityPointStructuresFailureMechanism = new StabilityPointStructuresFailureMechanism(); + + var view = new StabilityPointStructuresFailurePathView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, otherStabilityPointStructuresFailureMechanism); + + // Assert + Assert.IsFalse(closeForData); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var view = new StabilityPointStructuresFailurePathView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsTrue(closeForData); + } + + [Test] [Apartment(ApartmentState.STA)] - public void CreateInstance_WithContext_ReturnStabilityPointStructuresFailureMechanismView() + public void CreateInstance_WithContext_ReturnStabilityPointStructuresFailurePathView() { // Setup var assessmentSection = new AssessmentSectionStub();