// 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 System.Collections.Generic;
using System.Linq;
using Core.Common.Gui;
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 UpdateEntryAndExitPointsOfCalculationsChangeHandlerTest
{
[Test]
public void Constructor_WithoutCalculations_ThrowsArgumentNullException()
{
// Setup
var mockRepository = new MockRepository();
var inquiryHandler = mockRepository.StrictMock();
mockRepository.ReplayAll();
// Call
TestDelegate test = () => new UpdateEntryAndExitPointsOfCalculationsChangeHandler(null, string.Empty, inquiryHandler);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("calculations", paramName);
mockRepository.VerifyAll();
}
[Test]
public void Constructor_WithoutInquiryHandler_ThrowsArgumentNullException()
{
// Call
TestDelegate test = () => new UpdateEntryAndExitPointsOfCalculationsChangeHandler(Enumerable.Empty(), string.Empty, null);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("inquiryHandler", paramName);
}
[Test]
public void Constructor_WithoutQuery_ThrowsArgumentNullException()
{
// Setup
var mockRepository = new MockRepository();
var inquiryHandler = mockRepository.StrictMock();
mockRepository.ReplayAll();
// Call
TestDelegate test = () => new UpdateEntryAndExitPointsOfCalculationsChangeHandler(Enumerable.Empty(), null, inquiryHandler);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("query", paramName);
}
[Test]
public void Constructor_WithParameters_ImplementsExpectedInterface()
{
// Setup
var mockRepository = new MockRepository();
var inquiryHandler = mockRepository.StrictMock();
mockRepository.ReplayAll();
// Call
var handler = new UpdateEntryAndExitPointsOfCalculationsChangeHandler(Enumerable.Empty(), string.Empty, inquiryHandler);
// Assert
Assert.IsInstanceOf(handler);
mockRepository.VerifyAll();
}
[Test]
public void RequireConfirmation_WithCalculationWithoutOutput_ReturnFalse()
{
// Setup
var mockRepository = new MockRepository();
var inquiryHandler = mockRepository.StrictMock();
mockRepository.ReplayAll();
IEnumerable calculations = new List
{
new PipingCalculationScenario(new GeneralPipingInput())
};
var handler = new UpdateEntryAndExitPointsOfCalculationsChangeHandler(calculations, string.Empty, inquiryHandler);
// Call
bool requireConfirmation = handler.RequireConfirmation();
// Assert
Assert.IsFalse(requireConfirmation);
mockRepository.VerifyAll();
}
[Test]
public void RequireConfirmation_CalculationsWithoutAndWithOutput_ReturnTrue()
{
// Setup
var mockRepository = new MockRepository();
var inquiryHandler = mockRepository.StrictMock();
mockRepository.ReplayAll();
IEnumerable calculations = new List
{
new PipingCalculationScenario(new GeneralPipingInput())
{
Output = new TestPipingOutput()
},
new PipingCalculationScenario(new GeneralPipingInput())
};
var handler = new UpdateEntryAndExitPointsOfCalculationsChangeHandler(calculations, string.Empty, inquiryHandler);
// Call
bool requireConfirmation = handler.RequireConfirmation();
// Assert
Assert.IsTrue(requireConfirmation);
mockRepository.VerifyAll();
}
[Test]
[TestCase("I am a query", true)]
[TestCase("I am a query", false)]
[TestCase("", true)]
[TestCase("", false)]
[TestCase(" ", true)]
[TestCase(" ", false)]
public void InquireConfirmation_Always_ShowsConfirmationDialogReturnResultOfInquiry(string message, bool expectedResult)
{
// Setup
var mockRepository = new MockRepository();
var inquiryHandler = mockRepository.StrictMock();
inquiryHandler.Expect(ih => ih.InquireContinuation(message)).Return(expectedResult);
mockRepository.ReplayAll();
var handler = new UpdateEntryAndExitPointsOfCalculationsChangeHandler(Enumerable.Empty(), message, inquiryHandler);
// Call
bool result = handler.InquireConfirmation();
// Assert
Assert.AreEqual(expectedResult, result);
mockRepository.VerifyAll();
}
}
}