// 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;
using Core.Common.Gui;
using NUnit.Extensions.Forms;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.IO;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.KernelWrapper.TestUtil;
using Ringtoets.Piping.Plugin.ChangeHandlers;
namespace Ringtoets.Piping.Plugin.Test.ChangeHandlers
{
[TestFixture]
public class StochasticSoilModelChangeHandlerTest : NUnitFormTest
{
[Test]
public void Constructor_WithoutFailureMechanism_ThrowsArgumentNullException()
{
// Setup
var mockRepository = new MockRepository();
var inquiryHandler = mockRepository.StrictMock();
mockRepository.ReplayAll();
// Call
TestDelegate test = () => new StochasticSoilModelChangeHandler(null, inquiryHandler);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("failureMechanism", paramName);
mockRepository.VerifyAll();
}
[Test]
public void Constructor_WithoutInquiryHandler_ThrowsArgumentNullException()
{
// Call
TestDelegate test = () => new StochasticSoilModelChangeHandler(new PipingFailureMechanism(), null);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("inquiryHandler", paramName);
}
[Test]
public void Constructor_WithParameters_ImplementsExpectedInterface()
{
// Setup
var mockRepository = new MockRepository();
var inquiryHandler = mockRepository.StrictMock();
mockRepository.ReplayAll();
// Call
var handler = new StochasticSoilModelChangeHandler(new PipingFailureMechanism(), inquiryHandler);
// Assert
Assert.IsInstanceOf(handler);
mockRepository.VerifyAll();
}
[Test]
public void RequireConfirmation_FailureMechanismWithCalculationWithoutOutput_ReturnFalse()
{
// Setup
var mockRepository = new MockRepository();
var inquiryHandler = mockRepository.StrictMock();
mockRepository.ReplayAll();
var failureMechanism = new PipingFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(new PipingCalculationScenario(new GeneralPipingInput()));
var handler = new StochasticSoilModelChangeHandler(failureMechanism, inquiryHandler);
// Call
bool requireConfirmation = handler.RequireConfirmation();
// Assert
Assert.IsFalse(requireConfirmation);
mockRepository.VerifyAll();
}
[Test]
public void RequireConfirmation_FailureMechanismWithCalculationWithOutput_ReturnTrue()
{
// Setup
var mockRepository = new MockRepository();
var inquiryHandler = mockRepository.StrictMock();
mockRepository.ReplayAll();
var failureMechanism = new PipingFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(new PipingCalculationScenario(new GeneralPipingInput())
{
Output = new TestPipingOutput()
});
var handler = new StochasticSoilModelChangeHandler(failureMechanism, inquiryHandler);
// Call
bool requireConfirmation = handler.RequireConfirmation();
// Assert
Assert.IsTrue(requireConfirmation);
mockRepository.VerifyAll();
}
[Test]
[TestCase(true)]
[TestCase(false)]
public void InquireConfirmation_Always_ShowsConfirmationDialogReturnResultOfInquiry(bool expectedResult)
{
// Setup
string message = "Wanneer ondergrondschematisaties wijzigen als gevolg van het bijwerken, " +
"zullen de resultaten van berekeningen die deze ondergrondschematisaties gebruiken, worden " +
$"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";
var mockRepository = new MockRepository();
var inquiryHandler = mockRepository.StrictMock();
inquiryHandler.Expect(ih => ih.InquireContinuation(message)).Return(expectedResult);
mockRepository.ReplayAll();
var handler = new StochasticSoilModelChangeHandler(new PipingFailureMechanism(), inquiryHandler);
// Call
bool result = handler.InquireConfirmation();
// Assert
Assert.AreEqual(expectedResult, result);
mockRepository.VerifyAll();
}
}
}