// 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.Linq; using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.ClosingStructures.Data; using Ringtoets.ClosingStructures.Forms.PresentationObjects; using Ringtoets.ClosingStructures.Plugin; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Forms.PresentationObjects; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.ClosingStructures.Forms.Test.TreeNodeInfos { [TestFixture] public class ClosingStructuresCalculationContextTreeNodeInfoTest { private IGui guiMock; private TreeNodeInfo info; private MockRepository mocks; private ClosingStructuresPlugin plugin; [SetUp] public void SetUp() { mocks = new MockRepository(); guiMock = mocks.Stub(); plugin = new ClosingStructuresPlugin() { Gui = guiMock }; info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(ClosingStructuresCalculationContext)); } [TearDown] public void TearDown() { plugin.Dispose(); mocks.VerifyAll(); } [Test] public void Initialized_Always_ExpectedPropertiesSet() { // Setup mocks.ReplayAll(); // Assert Assert.AreEqual(typeof(ClosingStructuresCalculationContext), info.TagType); Assert.IsNotNull(info.Text); Assert.IsNotNull(info.Image); Assert.IsNotNull(info.EnsureVisibleOnCreate); Assert.IsNotNull(info.ChildNodeObjects); Assert.IsNotNull(info.ContextMenuStrip); Assert.IsNotNull(info.CanRename); Assert.IsNotNull(info.OnNodeRenamed); Assert.IsNotNull(info.CanRemove); Assert.IsNotNull(info.OnNodeRemoved); Assert.IsNotNull(info.CanDrag); Assert.IsNull(info.ForeColor); Assert.IsNull(info.CanCheck); Assert.IsNull(info.IsChecked); Assert.IsNull(info.OnNodeChecked); Assert.IsNull(info.CanDrop); Assert.IsNull(info.CanInsert); Assert.IsNull(info.OnDrop); } [Test] public void Image_Always_ReturnsCalculationIcon() { // Setup mocks.ReplayAll(); // Call var image = info.Image(null); // Assert TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculationIcon, image); } [Test] public void ChildNodeObjects_CalculationWithoutOutput_ReturnCollectionWithEmptyOutputObject() { var assessmentSectionMock = mocks.Stub(); mocks.ReplayAll(); var failureMechanism = new ClosingStructuresFailureMechanism(); var calculation = new ClosingStructuresCalculation(); var calculationContext = new ClosingStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); // Call var children = info.ChildNodeObjects(calculationContext).ToArray(); // Assert Assert.AreEqual(3, children.Length); var commentContext = children[0] as CommentContext; Assert.IsNotNull(commentContext); Assert.AreSame(calculationContext.WrappedData, commentContext.WrappedData); var ClosingStructuresInputContext = children[1] as ClosingStructuresInputContext; Assert.IsNotNull(ClosingStructuresInputContext); Assert.AreSame(calculationContext.WrappedData.InputParameters, ClosingStructuresInputContext.WrappedData); var emptyOutput = children[2] as EmptyProbabilityAssessmentOutput; Assert.IsNotNull(emptyOutput); } [Test] public void ChildNodeObjects_CalculationWithOutput_ReturnCollectionWithOutputObject() { var assessmentSectionMock = mocks.Stub(); mocks.ReplayAll(); var failureMechanism = new ClosingStructuresFailureMechanism(); var calculation = new ClosingStructuresCalculation { Output = new TestClosingStructuresOutput() }; var calculationContext = new ClosingStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); // Call var children = info.ChildNodeObjects(calculationContext).ToArray(); // Assert Assert.AreEqual(3, children.Length); var commentContext = children[0] as CommentContext; Assert.IsNotNull(commentContext); Assert.AreSame(calculationContext.WrappedData, commentContext.WrappedData); var ClosingStructuresInputContext = children[1] as ClosingStructuresInputContext; Assert.IsNotNull(ClosingStructuresInputContext); Assert.AreSame(calculationContext.WrappedData.InputParameters, ClosingStructuresInputContext.WrappedData); var output = children[2] as ProbabilityAssessmentOutput; Assert.IsNotNull(output); } private class TestClosingStructuresOutput : ProbabilityAssessmentOutput { public TestClosingStructuresOutput() : base(0, 0, 0, 0, 0) { } } } }