using System; using System.Linq; using Core.Common.Base.Plugin; using Core.Common.Controls.TreeView; using Core.Common.Gui; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.NodePresenters; using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Forms.PropertyClasses; using GuiPluginResources = Ringtoets.Piping.Plugin.Properties.Resources; namespace Ringtoets.Piping.Plugin.Test { [TestFixture] public class PipingGuiPluginTest { [Test] [STAThread] // For creation of XAML UI component (PipingRibbon) public void DefaultConstructor_ExpectedValues() { // call using (var ringtoetsGuiPlugin = new PipingGuiPlugin()) { // assert Assert.IsInstanceOf(ringtoetsGuiPlugin); Assert.IsInstanceOf(ringtoetsGuiPlugin.RibbonCommandHandler); } } [Test] public void GetPropertyInfos_ReturnsSupportedPropertyClasses() { // setup using (var guiPlugin = new PipingGuiPlugin()) { // call PropertyInfo[] propertyInfos = guiPlugin.GetPropertyInfos().ToArray(); // assert Assert.AreEqual(6, propertyInfos.Length); var pipingCalculationContextProperties = propertyInfos.Single(pi => pi.ObjectType == typeof(PipingCalculationContext)); Assert.AreEqual(typeof(PipingCalculationContextProperties), pipingCalculationContextProperties.PropertyType); Assert.IsNull(pipingCalculationContextProperties.AdditionalDataCheck); Assert.IsNull(pipingCalculationContextProperties.GetObjectPropertiesData); Assert.IsNull(pipingCalculationContextProperties.AfterCreate); var pipingCalculationGroupProperties = propertyInfos.Single(pi => pi.ObjectType == typeof(PipingCalculationGroupContext)); Assert.AreEqual(typeof(PipingCalculationGroupContextProperties), pipingCalculationGroupProperties.PropertyType); Assert.IsNull(pipingCalculationGroupProperties.AdditionalDataCheck); Assert.IsNull(pipingCalculationGroupProperties.GetObjectPropertiesData); Assert.IsNull(pipingCalculationGroupProperties.AfterCreate); var pipingInputContextProperties = propertyInfos.Single(pi => pi.ObjectType == typeof(PipingInputContext)); Assert.AreEqual(typeof(PipingInputContextProperties), pipingInputContextProperties.PropertyType); Assert.IsNull(pipingInputContextProperties.AdditionalDataCheck); Assert.IsNull(pipingInputContextProperties.GetObjectPropertiesData); Assert.IsNull(pipingInputContextProperties.AfterCreate); var pipingOutputProperties = propertyInfos.Single(pi => pi.ObjectType == typeof(PipingOutput)); Assert.AreEqual(typeof(PipingOutputProperties), pipingOutputProperties.PropertyType); Assert.IsNull(pipingOutputProperties.AdditionalDataCheck); Assert.IsNull(pipingOutputProperties.GetObjectPropertiesData); Assert.IsNull(pipingOutputProperties.AfterCreate); var pipingSurfaceLineProperties = propertyInfos.Single(pi => pi.ObjectType == typeof(RingtoetsPipingSurfaceLine)); Assert.AreEqual(typeof(RingtoetsPipingSurfaceLineProperties), pipingSurfaceLineProperties.PropertyType); Assert.IsNull(pipingSurfaceLineProperties.AdditionalDataCheck); Assert.IsNull(pipingSurfaceLineProperties.GetObjectPropertiesData); Assert.IsNull(pipingSurfaceLineProperties.AfterCreate); var pipingSoilProfileProperties = propertyInfos.Single(pi => pi.ObjectType == typeof(PipingSoilProfile)); Assert.AreEqual(typeof(PipingSoilProfileProperties), pipingSoilProfileProperties.PropertyType); Assert.IsNull(pipingSoilProfileProperties.AdditionalDataCheck); Assert.IsNull(pipingSoilProfileProperties.GetObjectPropertiesData); Assert.IsNull(pipingSoilProfileProperties.AfterCreate); } } [Test] public void GetProjectTreeViewNodePresenters_ReturnsSupportedNodePresenters() { // setup var mocks = new MockRepository(); var applicationCore = new ApplicationCore(); var guiStub = mocks.Stub(); guiStub.Stub(g => g.CommandHandler).Return(mocks.Stub()); var contextMenuProviderMock = mocks.DynamicMock(); Expect.Call(guiStub.ApplicationCore).Return(applicationCore).Repeat.Any(); Expect.Call(guiStub.ContextMenuProvider).Return(contextMenuProviderMock).Repeat.Any(); mocks.ReplayAll(); using (var guiPlugin = new PipingGuiPlugin { Gui = guiStub }) { // call ITreeNodePresenter[] nodePresenters = guiPlugin.GetProjectTreeViewNodePresenters().ToArray(); // assert Assert.AreEqual(11, nodePresenters.Length); Assert.IsTrue(nodePresenters.Any(np => np is PipingSurfaceLineCollectionNodePresenter)); Assert.IsTrue(nodePresenters.Any(np => np is PipingSurfaceLineNodePresenter)); Assert.IsTrue(nodePresenters.Any(np => np is PipingSoilProfileCollectionNodePresenter)); Assert.IsTrue(nodePresenters.Any(np => np is PipingSoilProfileNodePresenter)); Assert.IsTrue(nodePresenters.Any(np => np is PipingCalculationContextNodePresenter)); Assert.IsTrue(nodePresenters.Any(np => np is PipingCalculationGroupContextNodePresenter)); Assert.IsTrue(nodePresenters.Any(np => np is PipingInputContextNodePresenter)); Assert.IsTrue(nodePresenters.Any(np => np is PipingFailureMechanismNodePresenter)); Assert.IsTrue(nodePresenters.Any(np => np is PipingOutputNodePresenter)); Assert.IsTrue(nodePresenters.Any(np => np is EmptyPipingOutputNodePresenter)); Assert.IsTrue(nodePresenters.Any(np => np is EmptyPipingCalculationReportNodePresenter)); } mocks.VerifyAll(); } } }