// Copyright (C) Stichting Deltares 2021. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI 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 Deltares.Dam.Data; using Deltares.Dam.Forms; using Deltares.Standard.Reflection; using NUnit.Framework; namespace Deltares.Dam.Tests.Forms { [TestFixture] public class DamContextTest { [Test] public void GetColumnNamedFilters_WithArgumentNotScenarioType_ReturnsNull() { // Setup var context = new DamContext(); // Call var filter = context.GetColumnNamedFilters(typeof(object)); // Assert Assert.IsNull(filter); } [Test] public void GetColumnNamedFilter_WithScenarioArgument_ReturnsExpectedKeys() { // Setup var context = new DamContext(); // Call var columnNamedFilters = context.GetColumnNamedFilters(typeof(Scenario)); // Assert CollectionAssert.AreEqual(new[] { "InsideStabilityScenarioCategory", "PipingScenarioCategory", "PlLineSchematizationScenarioCategory" }, columnNamedFilters); } [Test] [TestCaseSource(nameof(GetFilterOptions))] public void GetFilteredColumns_WithValidArgument_GetsFilteredColumnNames(string filterValue, IEnumerable expectedColumnNames) { // Setup var context = new DamContext(); // Call var filteredColumnNames = context.GetFilteredColumns(typeof(Scenario), filterValue); // Assert CollectionAssert.AreEquivalent(expectedColumnNames, filteredColumnNames); } [Test] [TestCaseSource(nameof(GetUnsupportedFilterArguments))] public void GetFilteredColumns_WithUnsupportedArguments_ReturnsNull(Type argumentType, string filterValue) { // Setup var context = new DamContext(); // Call var filteredColumnNames = context.GetFilteredColumns(argumentType, filterValue); // Assert Assert.IsNull(filteredColumnNames); } private static IEnumerable GetFilterOptions() { yield return new TestCaseData("InsideStabilityScenarioCategory", new[] { StaticReflection.GetMemberName(x => x.LocationScenarioID), StaticReflection.GetMemberName(x => x.RiverLevel), StaticReflection.GetMemberName(x => x.DikeTableHeight), StaticReflection.GetMemberName(x => x.RequiredSafetyFactorStabilityInnerSlope), StaticReflection.GetMemberName(x => x.HeadPl3), StaticReflection.GetMemberName(x => x.HeadPl4), StaticReflection.GetMemberName(x => x.PolderLevel), StaticReflection.GetMemberName(x => x.HeadPl2) }) .SetName("InsideStabilityScenarioCategory"); yield return new TestCaseData("PipingScenarioCategory", new[] { StaticReflection.GetMemberName(x => x.LocationScenarioID), StaticReflection.GetMemberName(x => x.RiverLevel), StaticReflection.GetMemberName(x => x.DikeTableHeight), StaticReflection.GetMemberName(x => x.RequiredSafetyFactorPiping), StaticReflection.GetMemberName(x => x.HeadPl3), StaticReflection.GetMemberName(x => x.HeadPl4), StaticReflection.GetMemberName(x => x.PolderLevel), StaticReflection.GetMemberName(x => x.HeadPl2) }) .SetName("PipingScenarioCategory"); yield return new TestCaseData("PlLineSchematizationScenarioCategory", new[] { StaticReflection.GetMemberName(x => x.LocationScenarioID), StaticReflection.GetMemberName(x => x.RiverLevel), StaticReflection.GetMemberName(x => x.PlLineOffsetBelowDikeTopAtRiver), StaticReflection.GetMemberName(x => x.PlLineOffsetBelowDikeTopAtPolder), StaticReflection.GetMemberName(x => x.PlLineOffsetBelowShoulderBaseInside), StaticReflection.GetMemberName(x => x.PlLineOffsetBelowDikeToeAtPolder), StaticReflection.GetMemberName(x => x.PlLineOffsetBelowDikeCrestMiddle), StaticReflection.GetMemberName(x => x.PlLineOffsetFactorBelowShoulderCrest), StaticReflection.GetMemberName(x => x.UsePlLineOffsetBelowDikeCrestMiddle), StaticReflection.GetMemberName(x => x.UsePlLineOffsetFactorBelowShoulderCrest), StaticReflection.GetMemberName(x => x.PolderLevel) }) .SetName("PlLineSchematizationScenarioCategory"); } private static IEnumerable GetUnsupportedFilterArguments() { yield return new TestCaseData(typeof(object), "PlLineSchematizationScenarioCategory") .SetName("Unsupported type"); yield return new TestCaseData(typeof(Scenario), string.Empty) .SetName("Unsupported value"); } } }