// 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 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.IO; using Core.Common.Base.Storage; using Core.Common.IO.Exceptions; using Core.Common.IO.Readers; using Core.Common.TestUtil; using NUnit.Framework; namespace Application.Ringtoets.Migration.Test { [TestFixture] public class RingtoetsDatabaseSourceFileTest { [Test] public void Constructor_NonExistingPath_ThrowsCriticalFileReadException() { // Setup string filename = Path.GetRandomFileName(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, filename); // Call TestDelegate test = () => { using (new RingtoetsDatabaseSourceFile(filePath)) {} }; // Assert var exception = Assert.Throws(test); Assert.AreEqual($"Fout bij het lezen van bestand '{filePath}': {"het bestand bestaat niet."}", exception.Message); } [Test] [TestCase(null)] [TestCase("")] public void Constructor_FileNullOrEmpty_ThrowsCriticalFileReadException(string filePath) { // Call TestDelegate test = () => { using (new RingtoetsDatabaseSourceFile(filePath)) {} }; // Assert var exception = Assert.Throws(test); Assert.AreEqual($"Fout bij het lezen van bestand '{filePath}': {"bestandspad mag niet leeg of ongedefinieerd zijn."}", exception.Message); } [Test] public void Constructor_ValidPath_ExpectedProperties() { // Setup string filename = Path.GetRandomFileName(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, filename); // Call using (new FileDisposeHelper(filePath)) using (var file = new RingtoetsDatabaseSourceFile(filePath)) { // Assert Assert.IsInstanceOf(file); } } [Test] public void GetVersion_EmptyFile_ThrowsStorageValidationException() { // Setup string filename = Path.GetRandomFileName(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, filename); using (new FileDisposeHelper(filePath)) using (var file = new RingtoetsDatabaseSourceFile(filePath)) { // Call TestDelegate call = () => file.GetVersion(); // Assert string message = Assert.Throws(call).Message; Assert.AreEqual($"Het bestand '{filePath}' is moet een geldig Ringtoets database bestand zijn.", message); } } [Test] public void GetVersion_EmptyRingtoetsDatabaseFile_ReturnsEmpty() { // Setup string filePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "EmptyDatabase.rtd"); using (var file = new RingtoetsDatabaseSourceFile(filePath)) { // Call string version = file.GetVersion(); // Assert Assert.AreEqual(string.Empty, version); } } } }