// 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.Drawing;
using System.Linq;
using Core.Components.Chart.Data;
using Core.Components.Chart.Styles;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.MacroStabilityInwards.Data.SoilProfile;
using Ringtoets.MacroStabilityInwards.Forms.Factories;
using Ringtoets.MacroStabilityInwards.Primitives;
namespace Ringtoets.MacroStabilityInwards.Forms.Test.Factories
{
[TestFixture]
public class MacroStabilityInwardsChartDataFactoryTest
{
[Test]
public void CreateWaternetZonesExtremeChartDataCollection_ReturnsEmptyChartDataCollection()
{
// Call
ChartDataCollection data = MacroStabilityInwardsChartDataFactory.CreateWaternetZonesExtremeChartDataCollection();
// Assert
CollectionAssert.IsEmpty(data.Collection);
Assert.AreEqual("Zones extreem", data.Name);
}
[Test]
public void CreateWaternetZonesDailyChartDataCollection_ReturnsEmptyChartDataCollection()
{
// Call
ChartDataCollection data = MacroStabilityInwardsChartDataFactory.CreateWaternetZonesDailyChartDataCollection();
// Assert
CollectionAssert.IsEmpty(data.Collection);
Assert.AreEqual("Zones dagelijks", data.Name);
}
[Test]
public void CreateWaternetZoneChartData_NameNull_ThrowsArgumentNullException()
{
// Call
TestDelegate call = () => MacroStabilityInwardsChartDataFactory.CreateWaternetZoneChartData(null);
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("name", exception.ParamName);
}
[Test]
public void CreateWaternetZoneChartData_ReturnsEmptyChartAreaData()
{
// Setup
const string name = "zone";
// Call
ChartMultipleAreaData data = MacroStabilityInwardsChartDataFactory.CreateWaternetZoneChartData(name);
// Assert
CollectionAssert.IsEmpty(data.Areas);
Assert.AreEqual(name, data.Name);
AssertEqualStyle(data.Style, Color.FromArgb(60, Color.DeepSkyBlue), Color.Empty, 0);
}
[Test]
public void CreatePhreaticLineChartData_NameNull_ThrowsArgumentNullException()
{
// Call
TestDelegate call = () => MacroStabilityInwardsChartDataFactory.CreatePhreaticLineChartData(null);
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("name", exception.ParamName);
}
[Test]
public void CreatePhreaticLineChartData_ReturnsEmptyChartLineData()
{
// Setup
const string name = "zone";
// Call
ChartLineData data = MacroStabilityInwardsChartDataFactory.CreatePhreaticLineChartData(name);
// Assert
CollectionAssert.IsEmpty(data.Points);
Assert.AreEqual(name, data.Name);
AssertEqualStyle(data.Style, Color.Blue, 2, ChartLineDashStyle.Solid);
}
[Test]
public void CreateShoulderBaseInsideChartData_ReturnsChartPointDataWithExpectedStyling()
{
// Call
ChartPointData data = MacroStabilityInwardsChartDataFactory.CreateShoulderBaseInsideChartData();
// Assert
Assert.IsFalse(data.HasData);
Assert.AreEqual("Insteek binnenberm", data.Name);
AssertEqualStyle(data.Style, Color.BlueViolet, 8, Color.SeaGreen, 1, ChartPointSymbol.Triangle);
}
[Test]
public void CreateDikeTopAtPolderChartData_ReturnsChartPointDataWithExpectedStyling()
{
// Call
ChartPointData data = MacroStabilityInwardsChartDataFactory.CreateDikeTopAtPolderChartData();
// Assert
Assert.IsFalse(data.HasData);
Assert.AreEqual("Kruin binnentalud", data.Name);
AssertEqualStyle(data.Style, Color.LightSkyBlue, 8, Color.SeaGreen, 1, ChartPointSymbol.Triangle);
}
[Test]
public void CreateShoulderTopInsideChartData_ReturnsChartPointDataWithExpectedStyling()
{
// Call
ChartPointData data = MacroStabilityInwardsChartDataFactory.CreateShoulderTopInsideChartData();
// Assert
Assert.IsFalse(data.HasData);
Assert.AreEqual("Kruin binnenberm", data.Name);
AssertEqualStyle(data.Style, Color.DeepSkyBlue, 8, Color.SeaGreen, 1, ChartPointSymbol.Triangle);
}
[Test]
public void CreateSurfaceLevelInsideChartData_ReturnsChartPointDataWithExpectedStyling()
{
// Call
ChartPointData data = MacroStabilityInwardsChartDataFactory.CreateSurfaceLevelInsideChartData();
// Assert
Assert.IsFalse(data.HasData);
Assert.AreEqual("Maaiveld binnenwaarts", data.Name);
AssertEqualStyle(data.Style, Color.ForestGreen, 8, Color.Black, 1, ChartPointSymbol.Square);
}
[Test]
public void CreateSurfaceLevelOutsideChartData_ReturnsChartPointDataWithExpectedStyling()
{
// Call
ChartPointData data = MacroStabilityInwardsChartDataFactory.CreateSurfaceLevelOutsideChartData();
// Assert
Assert.IsFalse(data.HasData);
Assert.AreEqual("Maaiveld buitenwaarts", data.Name);
AssertEqualStyle(data.Style, Color.LightSeaGreen, 8, Color.Black, 1, ChartPointSymbol.Square);
}
[Test]
public void CreateDikeTopAtRiverChartData_ReturnsChartPointDataWithExpectedStyling()
{
// Call
ChartPointData data = MacroStabilityInwardsChartDataFactory.CreateDikeTopAtRiverChartData();
// Assert
Assert.IsFalse(data.HasData);
Assert.AreEqual("Kruin buitentalud", data.Name);
AssertEqualStyle(data.Style, Color.LightSteelBlue, 8, Color.SeaGreen, 1, ChartPointSymbol.Triangle);
}
[Test]
public void CreateRightGridChartData_ReturnsChartPointDataWithExpectedStyling()
{
// Call
ChartPointData data = MacroStabilityInwardsChartDataFactory.CreateRightGridChartData();
// Assert
Assert.IsFalse(data.HasData);
Assert.AreEqual("Rechter grid", data.Name);
AssertEqualStyle(data.Style, Color.Black, 6, Color.Black, 2, ChartPointSymbol.Plus);
}
[Test]
public void CreateLeftGridChartData_ReturnsChartPointDataWithExpectedStyling()
{
// Call
ChartPointData data = MacroStabilityInwardsChartDataFactory.CreateLeftGridChartData();
// Assert
Assert.IsFalse(data.HasData);
Assert.AreEqual("Linker grid", data.Name);
AssertEqualStyle(data.Style, Color.Black, 6, Color.Black, 2, ChartPointSymbol.Plus);
}
[Test]
public void CreateSoilLayerChartData_SoilProfileNull_ThrowsArgumentNullException()
{
// Call
TestDelegate test = () => MacroStabilityInwardsChartDataFactory.CreateSoilLayerChartData(0, null);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("soilProfile", paramName);
}
[Test]
[TestCase("A", 0)]
[TestCase("B", 3)]
[TestCase("Random", 5)]
public void CreateSoilLayerChartData_ValidSoilProfileAndSoilLayerIndex_ReturnsEmptyChartDataCollectionWithExpectedStyling(string name, int soilLayerIndex)
{
// Setup
var mocks = new MockRepository();
var soilLayer = mocks.Stub();
soilLayer.Stub(sl => sl.Data).Return(new MacroStabilityInwardsSoilLayerData
{
MaterialName = name,
Color = Color.Aquamarine
});
List layers = Enumerable.Repeat(mocks.Stub(), soilLayerIndex)
.ToList();
layers.Add(soilLayer);
var profile = mocks.Stub>();
profile.Stub(p => p.Layers).Return(layers);
mocks.ReplayAll();
// Call
ChartMultipleAreaData data = MacroStabilityInwardsChartDataFactory.CreateSoilLayerChartData(soilLayerIndex, profile);
// Assert
CollectionAssert.IsEmpty(data.Areas);
Assert.AreEqual($"{soilLayerIndex + 1} {name}", data.Name);
AssertEqualStyle(data.Style, soilLayer.Data.Color, Color.Black, 1);
mocks.VerifyAll();
}
[Test]
public void CreateHolesChartData_ValidSoilProfileWithHoles_ReturnsChartDataWithExpectedStylingAndAreas()
{
// Call
ChartMultipleAreaData holesChartData = MacroStabilityInwardsChartDataFactory.CreateHolesChartData();
// Assert
Assert.AreEqual("Binnenringen", holesChartData.Name);
AssertEqualStyle(holesChartData.Style, Color.White, Color.Black, 1);
}
[Test]
public void UpdateSurfaceLineChartDataName_SurfaceLineNull_NameSetToDefaultSurfaceLineName()
{
// Setup
var chartData = new ChartLineData("test name");
// Call
MacroStabilityInwardsChartDataFactory.UpdateSurfaceLineChartDataName(chartData, null);
// Assert
Assert.AreEqual("Profielschematisatie", chartData.Name);
}
[Test]
public void UpdateSurfaceLineChartDataName_SurfaceLine_NameSetToSurfaceLineName()
{
// Setup
var chartData = new ChartLineData("test name");
var surfaceLine = new MacroStabilityInwardsSurfaceLine("surface line name");
// Call
MacroStabilityInwardsChartDataFactory.UpdateSurfaceLineChartDataName(chartData, surfaceLine);
// Assert
Assert.AreEqual("surface line name", chartData.Name);
}
[Test]
public void UpdateSoilProfileChartDataName_WithoutSoilProfile_NameSetToDefaultSoilProfileName()
{
// Setup
var chartData = new ChartDataCollection("test name");
// Call
MacroStabilityInwardsChartDataFactory.UpdateSoilProfileChartDataName(chartData, null);
// Assert
Assert.AreEqual("Ondergrondschematisatie", chartData.Name);
}
[Test]
public void UpdateSoilProfileChartDataName_WithSoilProfile_NameSetToSoilProfileName()
{
// Setup
var chartData = new ChartDataCollection("test name");
var soilProfile = new MacroStabilityInwardsSoilProfile1D("soil profile name", 2.0,
new[]
{
new MacroStabilityInwardsSoilLayer1D(3.2)
});
// Call
MacroStabilityInwardsChartDataFactory.UpdateSoilProfileChartDataName(chartData, soilProfile);
// Assert
Assert.AreEqual("soil profile name", chartData.Name);
}
[TestCase(-1)]
[TestCase(2)]
[TestCase(3)]
public void CreateSoilLayerChartData_InvalidSoilLayerIndex_ThrowsArgumentOutOfRangeException(int soilLayerIndex)
{
// Setup
var layers = new[]
{
new MacroStabilityInwardsSoilLayer1D(0),
new MacroStabilityInwardsSoilLayer1D(1)
};
var profile = new MacroStabilityInwardsSoilProfile1D("name", -1.0, layers);
// Call
TestDelegate test = () => MacroStabilityInwardsChartDataFactory.CreateSoilLayerChartData(soilLayerIndex, profile);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("soilLayerIndex", paramName);
}
private static void AssertEqualStyle(ChartPointStyle pointStyle, Color fillColor, int size, Color strokeColor, int strokeThickness, ChartPointSymbol symbol)
{
Assert.AreEqual(fillColor, pointStyle.Color);
Assert.AreEqual(size, pointStyle.Size);
Assert.AreEqual(strokeColor, pointStyle.StrokeColor);
Assert.AreEqual(strokeThickness, pointStyle.StrokeThickness);
Assert.AreEqual(symbol, pointStyle.Symbol);
Assert.IsTrue(pointStyle.IsEditable);
}
private static void AssertEqualStyle(ChartAreaStyle areaStyle, Color fillColor, Color strokeColor, int width)
{
Assert.AreEqual(fillColor, areaStyle.FillColor);
Assert.AreEqual(strokeColor, areaStyle.StrokeColor);
Assert.AreEqual(width, areaStyle.StrokeThickness);
Assert.IsFalse(areaStyle.IsEditable);
}
private static void AssertEqualStyle(ChartLineStyle lineStyle, Color color, int width, ChartLineDashStyle dashStyle)
{
Assert.AreEqual(color, lineStyle.Color);
Assert.AreEqual(width, lineStyle.Width);
Assert.AreEqual(dashStyle, lineStyle.DashStyle);
}
}
}