// 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.Base.Plugin; using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.Gui.Commands; using Core.Common.Gui.Plugin; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionInwards.Forms.PropertyClasses; using Ringtoets.GrassCoverErosionInwards.Forms.Views; namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test { [TestFixture] public class GrassCoverErosionInwardsGuiPluginTest { [Test] public void DefaultConstructor_ExpectedValues() { // call using (var grassCoverErosionInwardsGuiPlugin = new GrassCoverErosionInwardsGuiPlugin()) { // assert Assert.IsInstanceOf(grassCoverErosionInwardsGuiPlugin); } } [Test] public void GetPropertyInfos_ReturnsSupportedPropertyClasses() { // setup using (var guiPlugin = new GrassCoverErosionInwardsGuiPlugin()) { // call var mocks = new MockRepository(); mocks.ReplayAll(); PropertyInfo[] propertyInfos = guiPlugin.GetPropertyInfos().ToArray(); // assert Assert.AreEqual(4, propertyInfos.Length); var failureMechanismContextProperties = propertyInfos.Single(pi => pi.DataType == typeof(GrassCoverErosionInwardsFailureMechanismContext)); Assert.AreEqual(typeof(GrassCoverErosionInwardsFailureMechanismContextProperties), failureMechanismContextProperties.PropertyObjectType); Assert.IsNull(failureMechanismContextProperties.AdditionalDataCheck); Assert.IsNull(failureMechanismContextProperties.GetObjectPropertiesData); Assert.IsNull(failureMechanismContextProperties.AfterCreate); var calculationContextProperties = propertyInfos.Single(pi => pi.DataType == typeof(GrassCoverErosionInwardsCalculationContext)); Assert.AreEqual(typeof(GrassCoverErosionInwardsCalculationContextProperties), calculationContextProperties.PropertyObjectType); Assert.IsNull(calculationContextProperties.AdditionalDataCheck); Assert.IsNull(calculationContextProperties.GetObjectPropertiesData); Assert.IsNull(calculationContextProperties.AfterCreate); var inputContextProperties = propertyInfos.Single(pi => pi.DataType == typeof(GrassCoverErosionInwardsInputContext)); Assert.AreEqual(typeof(GrassCoverErosionInwardsInputContextProperties), inputContextProperties.PropertyObjectType); Assert.IsNull(inputContextProperties.AdditionalDataCheck); Assert.IsNull(inputContextProperties.GetObjectPropertiesData); Assert.IsNull(inputContextProperties.AfterCreate); var outputContextProperties = propertyInfos.Single(pi => pi.DataType == typeof(ProbabilisticOutput)); Assert.AreEqual(typeof(GrassCoverErosionInwardsOutputProperties), outputContextProperties.PropertyObjectType); Assert.IsNull(outputContextProperties.AdditionalDataCheck); Assert.IsNull(outputContextProperties.GetObjectPropertiesData); Assert.IsNull(outputContextProperties.AfterCreate); mocks.VerifyAll(); } } [Test] public void GetTreeNodeInfos_ReturnsSupportedTreeNodeInfos() { // setup var mocks = new MockRepository(); var applicationCore = new ApplicationCore(); var guiStub = mocks.Stub(); guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); Expect.Call(guiStub.ApplicationCore).Return(applicationCore).Repeat.Any(); mocks.ReplayAll(); using (var guiPlugin = new GrassCoverErosionInwardsGuiPlugin { Gui = guiStub }) { // call TreeNodeInfo[] treeNodeInfos = guiPlugin.GetTreeNodeInfos().ToArray(); // assert Assert.AreEqual(7, treeNodeInfos.Length); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(GrassCoverErosionInwardsFailureMechanismContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(GrassCoverErosionInwardsCalculationGroupContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(GrassCoverErosionInwardsCalculationContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(FailureMechanismSectionResultContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(GrassCoverErosionInwardsInputContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(EmptyProbabilisticOutput))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(ProbabilisticOutput))); } mocks.VerifyAll(); } [Test] public void GetViewInfos_ReturnsSupportedViewInfos() { // Setup var mocks = new MockRepository(); var applicationCore = new ApplicationCore(); var guiStub = mocks.Stub(); guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); guiStub.Stub(g => g.ApplicationCore).Return(applicationCore); mocks.ReplayAll(); using (var guiPlugin = new GrassCoverErosionInwardsGuiPlugin { Gui = guiStub }) { // Call ViewInfo[] viewInfos = guiPlugin.GetViewInfos().ToArray(); // Assert Assert.AreEqual(1, viewInfos.Length); Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(GrassCoverErosionInwardsFailureMechanismResultView))); } } } }