// 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.Linq;
using Core.Common.TestUtil;
using NUnit.Framework;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HydraRing.Data;
namespace Ringtoets.HeightStructures.Service.Test
{
[TestFixture]
public class HeightStructuresCalculationServiceTest
{
[Test]
public void Validate_Always_LogStartAndEndOfValidatingInputs()
{
// Setup
const string name = "";
HeightStructuresCalculation heightStructuresCalculation = new HeightStructuresCalculation
{
Name = name
};
// Call
Action call = () => HeightStructuresCalculationService.Validate(heightStructuresCalculation);
// Assert
TestHelper.AssertLogMessages(call, messages =>
{
var msgs = messages.ToArray();
StringAssert.StartsWith(String.Format("Validatie van '{0}' gestart om: ", name), msgs.First());
StringAssert.StartsWith(String.Format("Validatie van '{0}' beëindigd om: ", name), msgs.Last());
});
}
[Test]
public void Validate_InValidCalculationInput_LogsErrorAndReturnsFalse()
{
// Setup
const string name = "";
HeightStructuresCalculation calculation = new HeightStructuresCalculation
{
Name = name
};
// Call
bool isValid = false;
Action call = () => isValid = HeightStructuresCalculationService.Validate(calculation);
// Assert
TestHelper.AssertLogMessages(call, messages =>
{
var msgs = messages.ToArray();
Assert.AreEqual(3, msgs.Length);
StringAssert.StartsWith(String.Format("Validatie van '{0}' gestart om: ", name), msgs.First());
StringAssert.StartsWith("Validatie mislukt: Er is geen hydraulische randvoorwaarde locatie geselecteerd.", msgs[1]);
StringAssert.StartsWith(String.Format("Validatie van '{0}' beëindigd om: ", name), msgs.Last());
});
Assert.IsFalse(isValid);
}
[Test]
public void Validate_ValidCalculationInput_ReturnsTrue()
{
// Setup
const string name = "";
HeightStructuresCalculation calculation = new HeightStructuresCalculation
{
Name = name,
InputParameters =
{
HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "name", 2, 2)
}
};
// Call
bool isValid = false;
Action call = () => isValid = HeightStructuresCalculationService.Validate(calculation);
// Assert
TestHelper.AssertLogMessages(call, messages =>
{
var msgs = messages.ToArray();
Assert.AreEqual(2, msgs.Length);
StringAssert.StartsWith(String.Format("Validatie van '{0}' gestart om: ", name), msgs.First());
StringAssert.StartsWith(String.Format("Validatie van '{0}' beëindigd om: ", name), msgs.Last());
});
Assert.IsTrue(isValid);
}
}
}