Index: Core/Common/src/Core.Common.Gui/FileFilterGenerator.cs =================================================================== diff -u -rb8912fd466037a40d06c19dc867f97cfeca71ac6 -rf0c03d04e24fe1af712271dd4bb9cd77c1cf4eae --- Core/Common/src/Core.Common.Gui/FileFilterGenerator.cs (.../FileFilterGenerator.cs) (revision b8912fd466037a40d06c19dc867f97cfeca71ac6) +++ Core/Common/src/Core.Common.Gui/FileFilterGenerator.cs (.../FileFilterGenerator.cs) (revision f0c03d04e24fe1af712271dd4bb9cd77c1cf4eae) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using Core.Common.Base.Properties; namespace Core.Common.Gui @@ -43,8 +44,14 @@ /// a specified file extension. /// /// The extension of the files to filter on. + /// Thrown when + /// is null. public FileFilterGenerator(string typeExtension) { + if (string.IsNullOrEmpty(typeExtension)) + { + throw new ArgumentException($@"Value required for the '{nameof(typeExtension)}'.", nameof(typeExtension)); + } extension = typeExtension; description = string.Format(Resources.FileFilterGenerator_Files_of_type_0_, typeExtension.ToUpperInvariant()); } @@ -56,8 +63,18 @@ /// The extension of the files to filter on. /// The description of files which have /// as their extension. + /// Thrown when + /// or is null. public FileFilterGenerator(string typeExtension, string typeDescription) { + if (string.IsNullOrEmpty(typeExtension)) + { + throw new ArgumentException($@"Value required for the '{nameof(typeExtension)}'.", nameof(typeExtension)); + } + if (string.IsNullOrEmpty(typeDescription)) + { + throw new ArgumentException($@"Value required for the '{nameof(typeDescription)}'.", nameof(typeDescription)); + } description = typeDescription; extension = typeExtension; } Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj =================================================================== diff -u -rd0b44ed460c4a13a28de62e705789f37f872ce77 -rf0c03d04e24fe1af712271dd4bb9cd77c1cf4eae --- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision d0b44ed460c4a13a28de62e705789f37f872ce77) +++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision f0c03d04e24fe1af712271dd4bb9cd77c1cf4eae) @@ -99,6 +99,7 @@ + Index: Core/Common/test/Core.Common.Gui.Test/FileFilterGeneratorTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Gui.Test/FileFilterGeneratorTest.cs (revision 0) +++ Core/Common/test/Core.Common.Gui.Test/FileFilterGeneratorTest.cs (revision f0c03d04e24fe1af712271dd4bb9cd77c1cf4eae) @@ -0,0 +1,204 @@ +// 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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 Core.Common.TestUtil; +using NUnit.Framework; + +namespace Core.Common.Gui.Test +{ + [TestFixture] + public class FileFilterGeneratorTest + { + [Test] + public void DefaultConstructor_DefaultFilter() + { + // Call + var generator = new FileFilterGenerator(); + + // Assert + Assert.AreEqual("Alle bestanden (*.*)|*.*", generator.Filter); + } + + [Test] + [TestCase(null)] + [TestCase("")] + public void Constructor_WithoutExtension_ThrowArgumentNullException(string extension) + { + // Call + TestDelegate test = () => new FileFilterGenerator(extension); + + // Assert + const string expectedMessage = "Value required for the 'typeExtension'."; + var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage( + test, + expectedMessage); + Assert.AreEqual("typeExtension", exception.ParamName); + } + + [Test] + [TestCase(null)] + [TestCase("")] + public void Constructor_WithoutExtensionWithDescription_ThrowArgumentNullException(string extension) + { + // Call + TestDelegate test = () => new FileFilterGenerator(extension, "description"); + + // Assert + const string expectedMessage = "Value required for the 'typeExtension'."; + var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage( + test, + expectedMessage); + Assert.AreEqual("typeExtension", exception.ParamName); + } + + [Test] + [TestCase(null)] + [TestCase("")] + public void Constructor_WithExtensionWithoutDescription_ThrowArgumentNullException(string description) + { + // Call + TestDelegate test = () => new FileFilterGenerator("txt", description); + + // Assert + const string expectedMessage = "Value required for the 'typeDescription'."; + var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage( + test, + expectedMessage); + Assert.AreEqual("typeDescription", exception.ParamName); + } + + [Test] + [TestCase("some filter")] + [TestCase("txt")] + public void Filter_WithExtension_ReturnsExpectedFilter(string extension) + { + // Setup + var generator = new FileFilterGenerator(extension); + + // Call + string filter = generator.Filter; + + // Assert + Assert.AreEqual($"{extension.ToUpperInvariant()}-bestanden (*.{extension})|*.{extension}", filter); + } + + [Test] + [TestCase("some filter", "some description")] + [TestCase("txt", "text file")] + public void Filter_WithExtensionWithDescription_ReturnsExpectedFilter(string extension, string description) + { + // Setup + var generator = new FileFilterGenerator(extension, description); + + // Call + string filter = generator.Filter; + + // Assert + Assert.AreEqual($"{description} (*.{extension})|*.{extension}", filter); + } + + [Test] + public void Equals_WithNull_ReturnsFalse() + { + // Setup + var generator = new FileFilterGenerator("txt", "descriptionA"); + + // Call + bool result = generator.Equals(null); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Equals_DiffentType_ReturnsFalse() + { + // Setup + var generator = new FileFilterGenerator("txt", "descriptionA"); + + // Call + bool result = generator.Equals("descriptionA (*.*)|*.*"); + + // Assert + Assert.IsFalse(result); + } + + [Test] + [TestCaseSource(nameof(GeneratorCombinations))] + public void Equals_DifferentScenarios_ReturnsExpectedResult(FileFilterGenerator generator, FileFilterGenerator otherGenerator, bool expectedEqual) + { + // Call + bool areEqualOne = generator.Equals(otherGenerator); + bool areEqualTwo = otherGenerator.Equals(generator); + + // Assert + Assert.AreEqual(expectedEqual, areEqualOne); + Assert.AreEqual(expectedEqual, areEqualTwo); + } + + [Test] + public void GetHashCode_FiltersAreEqual_FiltersHashesEqual() + { + // Setup + const string extension = "txt"; + const string description = "text files"; + + var generator = new FileFilterGenerator(extension, description); + var otherGenerator = new FileFilterGenerator(extension, description); + + // Call + int result = generator.GetHashCode(); + int otherResult = otherGenerator.GetHashCode(); + + // Assert + Assert.AreEqual(result, otherResult); + } + + private static TestCaseData[] GeneratorCombinations() + { + var generatorA = new FileFilterGenerator("txt", "descriptionA"); + var generatorB = new FileFilterGenerator("txt", "descriptionA"); + var generatorC = new FileFilterGenerator("ext", "descriptionA"); + var generatorD = new FileFilterGenerator("txt", "descriptionB"); + + return new[] + { + new TestCaseData(generatorA, generatorA, true) + { + TestName = "Equals_FileFilterGeneratorAFileFilterGeneratorA_True" + }, + new TestCaseData(generatorA, generatorB, true) + { + TestName = "Equals_FileFilterGeneratorAFileFilterGeneratorB_True" + }, + new TestCaseData(generatorA, generatorC, false) + { + TestName = "Equals_FileFilterGeneratorBFileFilterGeneratorC_False" + }, + new TestCaseData(generatorA, generatorD, false) + { + TestName = "Equals_FileFilterGeneratorAFileFilterGeneratorD_False" + } + }; + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilProfileTest.cs =================================================================== diff -u -r9cdd70c8d4ba76d93b72ef8c1b7df138fa73b0e4 -rf0c03d04e24fe1af712271dd4bb9cd77c1cf4eae --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilProfileTest.cs (.../StochasticSoilProfileTest.cs) (revision 9cdd70c8d4ba76d93b72ef8c1b7df138fa73b0e4) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilProfileTest.cs (.../StochasticSoilProfileTest.cs) (revision f0c03d04e24fe1af712271dd4bb9cd77c1cf4eae) @@ -180,7 +180,7 @@ { // Call bool areEqualOne = profile.Equals(otherProfile); - bool areEqualTwo = profile.Equals(otherProfile); + bool areEqualTwo = otherProfile.Equals(profile); // Assert Assert.AreEqual(expectedEqual, areEqualOne);