// 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.Collections.Generic;
using System.Linq;
using Core.Common.Data.TestUtil;
using NUnit.Framework;
using Ringtoets.Common.Data.IllustrationPoints;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.Data.TestUtil.IllustrationPoints;
namespace Ringtoets.Common.Data.Test.IllustrationPoints
{
[TestFixture]
public class GeneralResultTest
{
[Test]
public void Constructor_GoverningWindDirectionNull_ThrowsArgumentNullException()
{
// Call
TestDelegate call = () =>
new GeneralResult(null,
Enumerable.Empty(),
Enumerable.Empty());
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("governingWindDirection", exception.ParamName);
}
[Test]
public void Constructor_StochastNull_ThrowsArgumentNullException()
{
// Setup
WindDirection windDirection = WindDirectionTestFactory.CreateTestWindDirection();
// Call
TestDelegate call = () =>
new GeneralResult(windDirection,
null,
Enumerable.Empty());
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("stochasts", exception.ParamName);
}
[Test]
public void Constructor_TopLevelIllustrationPointsNull_ThrowsArgumentNullException()
{
// Setup
WindDirection windDirection = WindDirectionTestFactory.CreateTestWindDirection();
// Call
TestDelegate call = () =>
new GeneralResult(windDirection,
Enumerable.Empty(),
null);
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("topLevelIllustrationPoints", exception.ParamName);
}
[Test]
public void Constructor_ValidArguments_ReturnsExpectedProperties()
{
// Setup
WindDirection windDirection = WindDirectionTestFactory.CreateTestWindDirection();
IEnumerable stochasts = Enumerable.Empty();
IEnumerable topLevelIllustrationPoints =
Enumerable.Empty();
// Call
var generalResult = new GeneralResult(windDirection,
stochasts,
topLevelIllustrationPoints);
// Assert
Assert.IsInstanceOf(generalResult);
Assert.AreSame(windDirection, generalResult.GoverningWindDirection);
Assert.AreSame(topLevelIllustrationPoints, generalResult.TopLevelIllustrationPoints);
Assert.AreSame(stochasts, generalResult.Stochasts);
}
[Test]
public void Constructor_StochastNotUnique_ThrowArgumentException()
{
// Setup
WindDirection windDirection = WindDirectionTestFactory.CreateTestWindDirection();
var stochasts = new[]
{
new Stochast("unique", 0, 0),
new Stochast("non-unique", 0, 0),
new Stochast("non-unique", 0, 0),
new Stochast("nonunique", 0, 0),
new Stochast("nonunique", 0, 0)
};
IEnumerable topLevelIllustrationPoints =
Enumerable.Empty();
// Call
TestDelegate test = () => new GeneralResult(windDirection,
stochasts,
topLevelIllustrationPoints);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("Een of meerdere stochasten hebben dezelfde naam. " +
"Het uitlezen van illustratiepunten wordt overgeslagen.",
exception.Message);
}
[Test]
public void Constructor_IllustrationPointsNotUnique_ThrowArgumentException()
{
// Setup
WindDirection windDirection = WindDirectionTestFactory.CreateTestWindDirection();
IEnumerable stochasts = Enumerable.Empty();
IEnumerable topLevelIllustrationPoints = new[]
{
new TopLevelIllustrationPoint(new WindDirection("N", 0.5), "not unique"),
new TopLevelIllustrationPoint(new WindDirection("N", 0.5), "not unique")
};
// Call
TestDelegate test = () => new GeneralResult(windDirection,
stochasts,
topLevelIllustrationPoints);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("Een of meerdere illustratiepunten hebben dezelfde sluitscenario en windrichting. " +
"Het uitlezen van illustratiepunten wordt overgeslagen.",
exception.Message);
}
[Test]
public void Clone_Always_ReturnNewInstanceWithCopiedValues()
{
// Setup
var random = new Random(21);
var original = new GeneralResult(WindDirectionTestFactory.CreateTestWindDirection(),
new[]
{
new Stochast("Random name 1",
random.NextDouble(),
random.NextDouble()),
new Stochast("Random name 2",
random.NextDouble(),
random.NextDouble())
},
new[]
{
new TestTopLevelIllustrationPoint("situation 1"),
new TestTopLevelIllustrationPoint("situation 2")
});
// Call
object clone = original.Clone();
// Assert
CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones);
}
private class TopLevelIllustrationPoint : TopLevelIllustrationPointBase
{
public TopLevelIllustrationPoint(WindDirection windDirection, string closingSituation)
: base(windDirection, closingSituation) {}
}
}
}