// 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.Base.IO; using Core.Common.Gui; using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Plugin; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Plugin.FileImporter; using Ringtoets.Piping.Primitives; using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; namespace Ringtoets.Piping.Plugin.Test.UpdateInfos { [TestFixture] public class RingtoetsPipingSurfaceLinesContextUpdateInfoTest { private UpdateInfo updateInfo; private PipingPlugin plugin; [SetUp] public void SetUp() { plugin = new PipingPlugin(); updateInfo = plugin.GetUpdateInfos().First(i => i.DataType == typeof(RingtoetsPipingSurfaceLinesContext)); } [TearDown] public void TearDown() { plugin.Dispose(); } [Test] public void Name_Always_ReturnExpectedName() { // Call string name = updateInfo.Name; // Assert Assert.AreEqual("Profielschematisaties", name); } [Test] public void Category_Always_ReturnExpectedCategory() { // Call string category = updateInfo.Category; // Assert Assert.AreEqual("Algemeen", category); } [Test] public void Image_Always_ReturnExpectedIcon() { // Call Image image = updateInfo.Image; // Assert TestHelper.AssertImagesAreEqual(PipingFormsResources.PipingSurfaceLineIcon, image); } [Test] public void IsEnabled_ReferenceLineNull_ReturnFalse() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); assessmentSection.ReferenceLine = null; mocks.ReplayAll(); var failureMechanism = new PipingFailureMechanism(); var surfaceLines = new RingtoetsPipingSurfaceLineCollection(); var context = new RingtoetsPipingSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection); // Call bool isEnabled = updateInfo.IsEnabled(context); // Assert Assert.IsFalse(isEnabled); mocks.VerifyAll(); } [Test] public void IsEnabled_ReferenceLineSet_ReturnTrue() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); assessmentSection.ReferenceLine = new ReferenceLine(); mocks.ReplayAll(); var failureMechanism = new PipingFailureMechanism(); var surfaceLines = new RingtoetsPipingSurfaceLineCollection(); var context = new RingtoetsPipingSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection); // Call bool isEnabled = updateInfo.IsEnabled(context); // Assert Assert.IsTrue(isEnabled); mocks.VerifyAll(); } [Test] public void FileFilterGenerator_Always_ReturnExpectedFileFilter() { // Call string fileFilter = updateInfo.FileFilterGenerator.Filter; // Assert Assert.AreEqual("Profielschematisaties Kommagescheiden bestand (*.csv)|*.csv", fileFilter); } [Test] public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); assessmentSection.ReferenceLine = new ReferenceLine(); var mainWindow = mocks.Stub(); var gui = mocks.Stub(); gui.Stub(g => g.MainWindow).Return(mainWindow); mocks.ReplayAll(); plugin.Gui = gui; var failureMechanism = new PipingFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new PipingCalculationScenario(new GeneralPipingInput())); var surfaceLines = new RingtoetsPipingSurfaceLineCollection(); var context = new RingtoetsPipingSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection); // Call bool requiresUpdateConfirmation = updateInfo.VerifyUpdates(context); // Assert Assert.IsTrue(requiresUpdateConfirmation); mocks.VerifyAll(); } [Test] public void CurrentPath_SurfaceLineCollectionHasPathSet_ReturnsExpectedPath() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); assessmentSection.ReferenceLine = new ReferenceLine(); mocks.ReplayAll(); const string expectedFilePath = "some/path"; var surfaceLines = new RingtoetsPipingSurfaceLineCollection(); surfaceLines.AddRange(new[] { new RingtoetsPipingSurfaceLine() }, expectedFilePath); var failureMechanism = new PipingFailureMechanism(); var context = new RingtoetsPipingSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection); // Call string currentPath = updateInfo.CurrentPath(context); // Assert Assert.AreEqual(expectedFilePath, currentPath); mocks.VerifyAll(); } [Test] public void CreateFileImporter_ValidInput_ReturnFileImporter() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); assessmentSection.ReferenceLine = new ReferenceLine(); var failureMechanism = new PipingFailureMechanism(); var surfaceLines = new RingtoetsPipingSurfaceLineCollection(); var importTarget = new RingtoetsPipingSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection); // Call IFileImporter importer = updateInfo.CreateFileImporter(importTarget, ""); // Assert Assert.IsInstanceOf(importer); mocks.VerifyAll(); } } }