// 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.Linq;
using Core.Common.Base.Geometry;
using Core.Components.Chart.Data;
using NUnit.Framework;
using Ringtoets.MacroStabilityInwards.Data;
using Ringtoets.MacroStabilityInwards.Data.SoilProfile;
using Ringtoets.MacroStabilityInwards.Primitives;
namespace Ringtoets.MacroStabilityInwards.Forms.TestUtil
{
///
/// Class for asserting chart data in the macro stability
/// inwards views.
///
public static class MacroStabilityInwardsViewChartDataAssert
{
///
/// Asserts whether corresponds to .
///
/// The original .
/// The actual .
/// Thrown when
/// does not correspond to .
public static void AssertSurfaceLineChartData(MacroStabilityInwardsSurfaceLine original, ChartData actual)
{
Assert.IsInstanceOf(actual);
var surfaceLineChartData = (ChartLineData) actual;
Assert.AreEqual(original.Points.Length, surfaceLineChartData.Points.Length);
Assert.AreEqual(original.Name, actual.Name);
CollectionAssert.AreEqual(original.LocalGeometry, surfaceLineChartData.Points);
}
///
/// Asserts whether corresponds to ,
/// and .
///
/// The
/// that should be represented as series in .
/// The expected name of .
/// Indicator whether areas should be present.
/// The actual .
/// Thrown when does not correspond
/// to , or
/// .
public static void AssertSoilProfileChartData(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfileUnderSurface,
string expectedName,
bool mapDataShouldContainAreas,
ChartData actual)
{
Assert.IsInstanceOf(actual);
var soilProfileChartData = (ChartDataCollection) actual;
MacroStabilityInwardsSoilLayer2D[] layers = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfileUnderSurface?.Layers).ToArray();
int expectedLayerCount = layers.Length;
Assert.AreEqual(expectedLayerCount, soilProfileChartData.Collection.Count());
Assert.AreEqual(expectedName, soilProfileChartData.Name);
for (var i = 0; i < expectedLayerCount; i++)
{
var chartMultipleAreaData = soilProfileChartData.Collection.ElementAt(i) as ChartMultipleAreaData;
Assert.IsNotNull(chartMultipleAreaData);
Assert.AreEqual(layers.ElementAt(i).Data.MaterialName, chartMultipleAreaData.Name);
Assert.AreEqual(mapDataShouldContainAreas, chartMultipleAreaData.Areas.Any());
}
}
///
/// Asserts whether corresponds to .
///
/// The original .
/// The expected visibility of the chart data.
/// The actual .
/// Thrown when
/// does not correspond to .
public static void AssertWaternetChartData(MacroStabilityInwardsWaternet original, bool expectedVisibility, ChartDataCollection actual)
{
ChartData[] waternetChartData = actual.Collection.ToArray();
MacroStabilityInwardsWaternetLine[] waternetLines = original.WaternetLines.ToArray();
MacroStabilityInwardsPhreaticLine[] phreaticLines = original.PhreaticLines.ToArray();
CollectionAssert.IsNotEmpty(waternetLines);
CollectionAssert.IsNotEmpty(phreaticLines);
Assert.AreEqual(waternetLines.Length + phreaticLines.Length, waternetChartData.Length);
for (var i = 0; i < waternetChartData.Length; i++)
{
if (i < phreaticLines.Length)
{
var phreaticLineChartData = (ChartLineData) waternetChartData[i];
Assert.AreEqual(phreaticLines[i].Name, phreaticLineChartData.Name);
Assert.AreEqual(phreaticLines[i].Geometry, phreaticLineChartData.Points);
Assert.AreEqual(expectedVisibility, phreaticLineChartData.IsVisible);
}
else
{
var waternetLineChartData = (ChartMultipleAreaData) waternetChartData[i];
MacroStabilityInwardsWaternetLine waternetLine = waternetLines[i - waternetLines.Length];
Assert.AreEqual(waternetLine.Name, waternetLineChartData.Name);
Assert.IsTrue(waternetLineChartData.HasData);
Assert.AreEqual(expectedVisibility, waternetLineChartData.IsVisible);
}
}
}
///
/// Asserts whether corresponds to .
///
/// The original .
/// The actual .
/// Thrown when
/// does not correspond to .
public static void AssertGridChartData(MacroStabilityInwardsGrid original, ChartPointData actual)
{
var expectedPoints = new[]
{
new Point2D(original.XLeft, original.ZBottom),
new Point2D(original.XRight, original.ZBottom),
new Point2D(original.XLeft, original.ZTop),
new Point2D(original.XRight, original.ZTop)
};
CollectionAssert.AreEqual(expectedPoints, actual.Points);
}
///
/// Asserts whether contains no waternet chart data.
///
/// The actual .
/// The index of the waternet zones chart data under extreme
/// circumstances in the .
/// The index of the waternet zones chart data under daily
/// circumstances in the .
/// Thrown when a waternet layer is present.
public static void AssertEmptyWaternetChartData(ChartDataCollection chartDataCollection,
int waternetZonesExtremeIndex,
int waternetZonesDailyIndex)
{
var waternetExtremeData = (ChartDataCollection) chartDataCollection.Collection.ElementAt(waternetZonesExtremeIndex);
var waternetDailyData = (ChartDataCollection) chartDataCollection.Collection.ElementAt(waternetZonesDailyIndex);
CollectionAssert.IsEmpty(waternetExtremeData.Collection);
CollectionAssert.IsEmpty(waternetDailyData.Collection);
Assert.AreEqual("Zones extreem", waternetExtremeData.Name);
Assert.AreEqual("Zones dagelijks", waternetDailyData.Name);
}
}
}