Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r50b203a8d5c805fc548fb6b92c70a847190da6a5 -r2227f1d3a31b15a6d05c5385898d5da4b79dcdea --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 50b203a8d5c805fc548fb6b92c70a847190da6a5) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 2227f1d3a31b15a6d05c5385898d5da4b79dcdea) @@ -227,7 +227,13 @@ public override void Activate() { base.Activate(); + + if (Gui == null) + { + throw new InvalidOperationException("Gui cannot be null"); + } assessmentSectionFromFileCommandHandler = new AssessmentSectionFromFileCommandHandler(Gui.MainWindow, Gui, Gui.DocumentViewController); + } /// Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj =================================================================== diff -u -rd510069b9f0375adf108e8c9ffdb7668e7bb11f4 -r2227f1d3a31b15a6d05c5385898d5da4b79dcdea --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision d510069b9f0375adf108e8c9ffdb7668e7bb11f4) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 2227f1d3a31b15a6d05c5385898d5da4b79dcdea) @@ -76,6 +76,7 @@ + Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/RingtoetsProjectTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/RingtoetsProjectTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/RingtoetsProjectTreeNodeInfoTest.cs (revision 2227f1d3a31b15a6d05c5385898d5da4b79dcdea) @@ -0,0 +1,204 @@ +// 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.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Plugin; +using GuiResources = Core.Common.Gui.Properties.Resources; + +namespace Ringtoets.Integration.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class RingtoetsProjectTreeNodeInfoTest + { + private MockRepository mockRepository; + + [SetUp] + public void SetUp() + { + mockRepository = new MockRepository(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Setup + using (var plugin = new RingtoetsPlugin()) + { + var info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(RingtoetsProject), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + } + + [Test] + public void Text_Always_ReturnsName() + { + // Setup + var testName = "ttt"; + var project = new RingtoetsProject(testName); + + using (var plugin = new RingtoetsPlugin()) + { + var info = GetInfo(plugin); + + // Call + var text = info.Text(project); + + // Assert + Assert.AreEqual(testName, text); + } + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var project = new RingtoetsProject(); + + using (var plugin = new RingtoetsPlugin()) + { + var info = GetInfo(plugin); + + // Call + var image = info.Image(project); + + // Assert + TestHelper.AssertImagesAreEqual(GuiResources.ProjectIcon, image); + } + } + + [Test] + public void ChildNodeObjects_Always_ReturnsChildsOnData() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var project = new RingtoetsProject(); + project.AssessmentSections.Add(assessmentSection); + + using (var plugin = new RingtoetsPlugin()) + { + var info = GetInfo(plugin); + // Call + + var objects = info.ChildNodeObjects(project); + + // Assert + Assert.AreEqual(1, objects.Length); + var actualAssessmentSection = (AssessmentSection) objects[0]; + Assert.AreSame(assessmentSection, actualAssessmentSection); + } + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + var guiMock = mockRepository.StrictMultiMock(); + var menuBuilderMock = mockRepository.StrictMock(); + guiMock.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + guiMock.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(null, treeViewControl)).Return(menuBuilderMock); + mockRepository.ReplayAll(); + + using (var plugin = new RingtoetsPlugin()) + { + var info = GetInfo(plugin); + plugin.Gui = guiMock; + + // Call + info.ContextMenuStrip(null, null, treeViewControl); + } + } + // Assert + mockRepository.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_ContextMenuItemAddAssessmentSectionEnabled() + { + // Setup + var guiMock = mockRepository.StrictMock(); + guiMock.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + guiMock.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + + var project = new RingtoetsProject(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(project, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + mockRepository.ReplayAll(); + + using (var plugin = new RingtoetsPlugin()) + { + var info = GetInfo(plugin); + + plugin.Gui = guiMock; + + // Call + var contextMenu = info.ContextMenuStrip(project, null, treeViewControl); + + const string expectedItemText = "&Nieuw traject..."; + const string expectedItemTooltip = "Voeg een nieuw traject toe aan het project."; + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 0, expectedItemText, expectedItemTooltip, GuiResources.PlusIcon); + } + } + // Assert + mockRepository.VerifyAll(); // Expect no calls on arguments + } + + private static TreeNodeInfo GetInfo(RingtoetsPlugin plugin) + { + return plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(RingtoetsProject)); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs =================================================================== diff -u -r50b203a8d5c805fc548fb6b92c70a847190da6a5 -r2227f1d3a31b15a6d05c5385898d5da4b79dcdea --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision 50b203a8d5c805fc548fb6b92c70a847190da6a5) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision 2227f1d3a31b15a6d05c5385898d5da4b79dcdea) @@ -30,6 +30,7 @@ using Core.Common.Gui; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Forms.ViewHost; using Core.Common.Gui.Plugin; using Core.Common.Gui.Settings; using Core.Common.TestUtil; @@ -452,5 +453,47 @@ Assert.AreEqual(1, importers.Count(i => i is FailureMechanismSectionsImporter)); } } + + [Test] + public void Activate_WithoutGui_ThrowsInvalidOperationException() + { + // Setup + using (var plugin = new RingtoetsPlugin()) + { + // Call + TestDelegate test = () => plugin.Activate(); + + // Assert + Assert.Throws(test); + } + } + + [Test] + public void Activate_WithGui_DoesNotThrowException() + { + // Setup + var mockRepository = new MockRepository(); + var mainWindowMock = mockRepository.StrictMock(); + var documentViewControllerMock = mockRepository.StrictMock(); + var guiMock = mockRepository.StrictMock(); + guiMock.Expect(g => g.MainWindow).Return(mainWindowMock); + guiMock.Expect(g => g.DocumentViewController).Return(documentViewControllerMock); + guiMock.Expect(g => g.ProjectOpened += null).IgnoreArguments(); + guiMock.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + mockRepository.ReplayAll(); + + using (var plugin = new RingtoetsPlugin()) + { + plugin.Gui = guiMock; + + // Call + TestDelegate test = () => plugin.Activate(); + + // Assert + Assert.DoesNotThrow(test); + } + + mockRepository.VerifyAll(); + } } } \ No newline at end of file