// 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;
using System.Data.SQLite;
using System.IO;
using Core.Common.TestUtil;
using NUnit.Framework;
using Ringtoets.HydraRing.Calculation.Exceptions;
using Ringtoets.HydraRing.Calculation.Readers;
namespace Ringtoets.HydraRing.Calculation.Test.Readers
{
[TestFixture]
public class HydraRingDatabaseReaderTest
{
private const string validDatabase = "ValidDatabase";
private const string invalidDatabase = "InvalidDatabase";
private const string emptyWorkingDirectory = "EmptyWorkingDirectory";
private const string emptyDatabase = "EmptyDatabase";
private const string query = "SELECT * FROM IterateToGivenBetaConvergence " +
"WHERE OuterIterationId = (SELECT MAX(OuterIterationId) FROM IterateToGivenBetaConvergence);";
private static readonly string testDirectory = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.Calculation,
Path.Combine("Readers", nameof(HydraRingDatabaseReader)));
[Test]
public void Constructor_ExpectedValues()
{
// Setup
string directory = Path.Combine(testDirectory, validDatabase);
// Call
using (var reader = new HydraRingDatabaseReader(directory, "", 0))
{
// Assert
Assert.IsInstanceOf(reader);
}
}
[Test]
public void Constructor_WorkingDirectoryNull_ThrowArgumentNullException()
{
// Call
TestDelegate test = () => new HydraRingDatabaseReader(null, "", 0);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("workingDirectory", exception.ParamName);
}
[Test]
public void Constructor_QueryNull_ThrowArgumentNullException()
{
// Setup
string directory = Path.Combine(testDirectory, validDatabase);
// Call
TestDelegate test = () => new HydraRingDatabaseReader(directory, null, 0);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("query", exception.ParamName);
}
[Test]
[TestCaseSource(typeof(InvalidPathHelper), nameof(InvalidPathHelper.InvalidPaths))]
public void Constructor_WithInvalidWorkingDirectoryPath_ThrowsArgumentException(string invalidPath)
{
// Call
TestDelegate test = () => new HydraRingDatabaseReader(invalidPath, "", 0);
// Assert
Assert.Throws(test);
}
[Test]
[TestCase(emptyWorkingDirectory)]
[TestCase(invalidDatabase)]
public void Constructor_EmptyWorkingDirectoryOrInvalidDatabase_ThrowSQLiteException(string path)
{
// Setup
string directory = Path.Combine(testDirectory, path);
// Call
TestDelegate test = () =>
{
using (new HydraRingDatabaseReader(directory, query, 0)) {}
};
// Assert
Assert.Throws(test);
}
[Test]
public void Execute_EmptyDatabase_ThrowHydraRingDatabaseReaderException()
{
// Setup
string directory = Path.Combine(testDirectory, emptyDatabase);
using (var reader = new HydraRingDatabaseReader(directory, query, 0))
{
// Call
TestDelegate test = () => reader.ReadLine();
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("Er is geen resultaat gevonden in de Hydra-Ring uitvoerdatabase.", exception.Message);
}
}
}
}