// Copyright (C) Stichting Deltares 2017. 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; 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 Core.Common.Utils; using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.MacroStabilityInwards.Data; using Ringtoets.MacroStabilityInwards.Data.TestUtil; using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; using Ringtoets.MacroStabilityInwards.IO.Importers; using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil; using FormsResources = Ringtoets.MacroStabilityInwards.Forms.Properties.Resources; namespace Ringtoets.MacroStabilityInwards.Plugin.Test.UpdateInfos { [TestFixture] public class StochasticSoilModelCollectionContextUpdateInfoTest : NUnitFormTest { private UpdateInfo updateInfo; private MacroStabilityInwardsPlugin plugin; public override void Setup() { plugin = new MacroStabilityInwardsPlugin(); updateInfo = plugin.GetUpdateInfos().First(i => i.DataType == typeof(StochasticSoilModelCollectionContext)); } public override void TearDown() { plugin.Dispose(); } [Test] public void Name_Always_ReturnExpectedName() { // Call string name = updateInfo.Name; // Assert Assert.AreEqual("Stochastische ondergrondmodellen", 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(FormsResources.SoilProfileIcon, image); } [Test] public void IsEnabled_SoilModelCollectionSourcePathNull_ReturnFalse() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var stochasticSoilModel = new StochasticSoilModelCollection(); var context = new StochasticSoilModelCollectionContext(stochasticSoilModel, failureMechanism, assessmentSection); // Call bool isEnabled = updateInfo.IsEnabled(context); // Assert Assert.IsFalse(isEnabled); mocks.VerifyAll(); } [Test] public void IsEnabled_SoilModelCollectionSourcePathSet_ReturnTrue() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var stochasticSoilModel = new StochasticSoilModelCollection(); stochasticSoilModel.AddRange(Enumerable.Empty(), "some/path"); var context = new StochasticSoilModelCollectionContext(stochasticSoilModel, failureMechanism, assessmentSection); // Call bool isEnabled = updateInfo.IsEnabled(context); // Assert Assert.IsTrue(isEnabled); mocks.VerifyAll(); } [Test] public void FileFilterGenerator_Always_ReturnExpectedFileFilter() { // Call FileFilterGenerator fileFilterGenerator = updateInfo.FileFilterGenerator; // Assert Assert.AreEqual("D-Soil Model bestand (*.soil)|*.soil", fileFilterGenerator.Filter); } [Test] public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); var mainWindow = mocks.Stub(); var gui = mocks.Stub(); gui.Stub(g => g.MainWindow).Return(mainWindow); mocks.ReplayAll(); plugin.Gui = gui; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput())); var stochasticSoilModelCollection = new StochasticSoilModelCollection(); var context = new StochasticSoilModelCollectionContext(stochasticSoilModelCollection, failureMechanism, assessmentSection); // Call bool updatesVerified = updateInfo.VerifyUpdates(context); // Assert Assert.IsTrue(updatesVerified); mocks.VerifyAll(); } [Test] [TestCase(true)] [TestCase(false)] public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed) { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); var mainWindow = mocks.Stub(); var gui = mocks.Stub(); gui.Stub(g => g.MainWindow).Return(mainWindow); mocks.ReplayAll(); plugin.Gui = gui; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var calculationWithOutput = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) { Output = new TestMacroStabilityInwardsOutput() }; failureMechanism.CalculationsGroup.Children.Add(calculationWithOutput); var stochasticSoilModelCollection = new StochasticSoilModelCollection(); var context = new StochasticSoilModelCollectionContext(stochasticSoilModelCollection, failureMechanism, assessmentSection); string textBoxMessage = null; DialogBoxHandler = (name, wnd) => { var helper = new MessageBoxTester(wnd); textBoxMessage = helper.Text; if (isActionConfirmed) { helper.ClickOk(); } else { helper.ClickCancel(); } }; // Call bool updatesVerified = updateInfo.VerifyUpdates(context); // Assert string expectedInquiryMessage = "Als ondergrondschematisaties wijzigen door het bijwerken, " + "dan worden de resultaten van berekeningen die deze ondergrondschematisaties gebruiken " + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; Assert.AreEqual(expectedInquiryMessage, textBoxMessage); Assert.AreEqual(isActionConfirmed, updatesVerified); mocks.VerifyAll(); } [Test] public void CurrentPath_StochasticSoilModelCollectionHasPathSet_ReturnsExpectedPath() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); const string expectedFilePath = "some/path"; var stochasticSoilModelCollection = new StochasticSoilModelCollection(); stochasticSoilModelCollection.AddRange(new[] { new TestStochasticSoilModel() }, expectedFilePath); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var context = new StochasticSoilModelCollectionContext(stochasticSoilModelCollection, failureMechanism, assessmentSection); // Call string currentPath = updateInfo.CurrentPath(context); // Assert Assert.AreEqual(expectedFilePath, currentPath); mocks.VerifyAll(); } [Test] public void CreateFileImporter_Always_ReturnFileImporter() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var importTarget = new StochasticSoilModelCollectionContext(failureMechanism.StochasticSoilModels, failureMechanism, assessmentSection); // Call IFileImporter importer = updateInfo.CreateFileImporter(importTarget, ""); // Assert Assert.IsInstanceOf(importer); mocks.VerifyAll(); } } }