// Copyright (C) Stichting Deltares 2016. 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.Drawing; using System.Linq; using Core.Common.Gui.Plugin; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Forms.PresentationObjects; using Ringtoets.HeightStructures.Forms.Views; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.HeightStructures.Plugin.Test.ViewInfos { [TestFixture] public class HeightStructuresScenariosViewInfoTest { private HeightStructuresPlugin plugin; private ViewInfo info; private MockRepository mocks; [SetUp] public void SetUp() { plugin = new HeightStructuresPlugin(); info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(HeightStructuresScenariosView)); mocks = new MockRepository(); } [TearDown] public void TearDown() { plugin.Dispose(); } [Test] public void Initialized_Always_ExpectedPropertiesSet() { // Assert Assert.AreEqual(typeof(HeightStructuresScenariosContext), info.DataType); Assert.AreEqual(typeof(CalculationGroup), info.ViewDataType); } [Test] public void GetViewName_Always_ReturnViewName() { // Setup using (var view = new HeightStructuresScenariosView()) { var viewData = new CalculationGroup(); // Call string viewName = info.GetViewName(view, viewData); // Assert Assert.AreEqual("Scenario's", viewName); } } [Test] public void GetViewData_Always_ReturnWrappedData() { // Setup var calculationGroup = new CalculationGroup(); var failureMechanism = new HeightStructuresFailureMechanism(); var context = new HeightStructuresScenariosContext(calculationGroup, failureMechanism); // Call object viewData = info.GetViewData(context); // Assert Assert.AreSame(calculationGroup, viewData); } [Test] public void Image_Always_ReturnScenariosIcon() { // Call Image image = info.Image; // Assert TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ScenariosIcon, image); } [Test] public void CloseForData_AssessmentSectionRemovedWithoutFailureMechanism_ReturnFalse() { // Setup using (var view = new HeightStructuresScenariosView { Data = new CalculationGroup() }) { var assessmentSection = mocks.Stub(); assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new IFailureMechanism[0]); mocks.ReplayAll(); // Call bool closeForData = info.CloseForData(view, assessmentSection); // Assert Assert.IsFalse(closeForData); mocks.VerifyAll(); } } [Test] public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnFalse() { // Setup using (var view = new HeightStructuresScenariosView { Data = new CalculationGroup() }) { var unrelatedFailureMechanism = new HeightStructuresFailureMechanism(); var assessmentSection = mocks.Stub(); assessmentSection.Expect(asm => asm.GetFailureMechanisms()).Return(new[] { unrelatedFailureMechanism }); mocks.ReplayAll(); // Precondition Assert.AreNotSame(view.Data, unrelatedFailureMechanism.CalculationsGroup); // Call bool closeForData = info.CloseForData(view, assessmentSection); // Assert Assert.IsFalse(closeForData); mocks.VerifyAll(); } } [Test] public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnTrue() { // Setup var relatedFailureMechanism = new HeightStructuresFailureMechanism(); using (var view = new HeightStructuresScenariosView { Data = relatedFailureMechanism.CalculationsGroup }) { var assessmentSection = mocks.Stub(); assessmentSection.Expect(asm => asm.GetFailureMechanisms()).Return(new[] { relatedFailureMechanism }); mocks.ReplayAll(); // Precondition Assert.AreSame(view.Data, relatedFailureMechanism.CalculationsGroup); // Call bool closeForData = info.CloseForData(view, assessmentSection); // Assert Assert.IsTrue(closeForData); mocks.VerifyAll(); } } [Test] public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnFalse() { // Setup using (var view = new HeightStructuresScenariosView { Data = new CalculationGroup() }) { // Call bool closeForData = info.CloseForData(view, new HeightStructuresFailureMechanism()); // Assert Assert.IsFalse(closeForData); } } [Test] public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnTrue() { // Setup var correspondingFailureMechanism = new HeightStructuresFailureMechanism(); using (var view = new HeightStructuresScenariosView { Data = correspondingFailureMechanism.CalculationsGroup }) { // Call bool closeForData = info.CloseForData(view, correspondingFailureMechanism); // Assert Assert.IsTrue(closeForData); } } [Test] public void CloseForData_AssessmentSectionRemovedWithoutHeightStructuresFailureMechanism_ReturnsFalse() { // Setup var assessmentSectionMock = mocks.StrictMock(); assessmentSectionMock.Expect(asm => asm.GetFailureMechanisms()).Return(new IFailureMechanism[0]); mocks.ReplayAll(); var view = new HeightStructuresScenariosView { Data = new CalculationGroup() }; // Call bool closeForData = info.CloseForData(view, assessmentSectionMock); // Assert Assert.IsFalse(closeForData); mocks.VerifyAll(); } [Test] public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() { // Setup var assessmentSectionMock = mocks.StrictMock(); assessmentSectionMock.Expect(asm => asm.GetFailureMechanisms()).Return(new[] { new HeightStructuresFailureMechanism() }); mocks.ReplayAll(); var view = new HeightStructuresScenariosView { Data = new CalculationGroup() }; // Call bool closeForData = info.CloseForData(view, assessmentSectionMock); // Assert Assert.IsFalse(closeForData); mocks.VerifyAll(); } [Test] public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() { // Setup var assessmentSectionMock = mocks.StrictMock(); var failureMechanism = new HeightStructuresFailureMechanism(); assessmentSectionMock.Expect(asm => asm.GetFailureMechanisms()).Return(new[] { failureMechanism }); mocks.ReplayAll(); var view = new HeightStructuresScenariosView { Data = failureMechanism.CalculationsGroup }; // Call bool closeForData = info.CloseForData(view, assessmentSectionMock); // Assert Assert.IsTrue(closeForData); mocks.VerifyAll(); } [Test] public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() { // Setup var view = new HeightStructuresScenariosView(); var failureMechanism = new HeightStructuresFailureMechanism(); view.Data = new CalculationGroup(); // Call bool closeForData = info.CloseForData(view, failureMechanism); // Assert Assert.IsFalse(closeForData); } [Test] public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() { // Setup var view = new HeightStructuresScenariosView(); var failureMechanism = new HeightStructuresFailureMechanism(); view.Data = failureMechanism.CalculationsGroup; // Call bool closeForData = info.CloseForData(view, failureMechanism); // Assert Assert.IsTrue(closeForData); } [Test] public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() { // Setup var assessmentSectionMock = mocks.StrictMock(); mocks.ReplayAll(); var view = new HeightStructuresScenariosView(); var failureMechanism = new HeightStructuresFailureMechanism(); var failureMechanismContext = new HeightStructuresFailureMechanismContext(new HeightStructuresFailureMechanism(), assessmentSectionMock); view.Data = failureMechanism.CalculationsGroup; // Call bool closeForData = info.CloseForData(view, failureMechanismContext); // Assert Assert.IsFalse(closeForData); mocks.VerifyAll(); } [Test] public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() { // Setup var assessmentSectionStub = mocks.Stub(); mocks.ReplayAll(); var view = new HeightStructuresScenariosView(); var failureMechanism = new HeightStructuresFailureMechanism(); var failureMechanismContext = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSectionStub); view.Data = failureMechanism.CalculationsGroup; // Call bool closeForData = info.CloseForData(view, failureMechanismContext); // Assert Assert.IsTrue(closeForData); mocks.VerifyAll(); } [Test] public void AfterCreate_Always_SetsSpecificPropertiesToView() { // Setup using (var view = new HeightStructuresScenariosView()) { var group = new CalculationGroup(); var failureMechanism = new HeightStructuresFailureMechanism(); var context = new HeightStructuresScenariosContext(group, failureMechanism); // Call info.AfterCreate(view, context); // Assert Assert.AreSame(failureMechanism, view.FailureMechanism); } } } }