// Copyright (C) Stichting Deltares 2024. 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.IO; using Deltares.Maps; using NUnit.Framework; namespace Deltares.Dam.Tests { [TestFixture] public class GeometryFileTest { private string existingFile; [Test] public void FileReturnsValidFullPath() { const string fileName = "test.tst"; var file = new MockFile("", fileName); string expected = Path.Combine(Directory.GetCurrentDirectory(), fileName); Assert.That(file.FullPath, Is.EqualTo(expected)); file = new MockFile(fileName); Assert.That(file.FullPath, Is.EqualTo(expected)); } [Test] public void FileReturnsTheFileNameWithoutExtension() { var file = new MockFile(string.Empty, "test.tst"); Assert.That(file.NameWithoutExtension, Is.EqualTo("test")); } [Test] public void FileReturnsOnlyTheLocation() { var file = new MockFile("", "test.tst"); Assert.That(file.DirectoryName, Is.EqualTo(Directory.GetCurrentDirectory())); } [Test] public void FileReturnsOnlyTheExtension() { var file = new MockFile(string.Empty, "test.tst"); Assert.That(file.FileExtension, Is.EqualTo(".tst")); } [Test] public void FileReturnsOnlyTheName() { var file = new MockFile("", "test.tst"); Assert.That(file.FileName, Is.EqualTo("test.tst")); file = new MockFile("test.tst"); Assert.That(file.FileName, Is.EqualTo("test.tst")); } [Test] public void FileReturnsFalseIfNotExists() { var file = new MockFile(string.Empty, "test.tst"); Assert.That(file.Exists, Is.False); file = new MockFile("test.tst"); Assert.That(file.Exists, Is.False); } [Test] public void FileReturnsTrueIfFileExists() { var file = new MockFile(existingFile); Assert.That(file.Exists, Is.True); } [Test] public void FileReturnsCorrectFullPathOnExistingFile() { string location = Directory.GetCurrentDirectory(); var file = new MockFile(location, existingFile); Assert.That(file.FullPath, Is.EqualTo(location + "\\" + existingFile)); } [Test] public void FileReturnsCorrectFullPathOnExistingFileUsingToString() { string location = Directory.GetCurrentDirectory(); var file = new MockFile(location, existingFile); Assert.That(file.ToString(), Is.EqualTo(location + "\\" + existingFile)); } [Test] public void FileReturnsIsValidReturnsTrueOnExistingFile() { string location = Directory.GetCurrentDirectory(); var file = new MockFile(location, existingFile); Assert.That(file.IsValid, Is.True); } #region Mock private class MockFile : FileLocation { private const string Extension = ".tst"; public MockFile(string fileLocation, string fileName) : base(fileLocation, fileName, Extension) {} public MockFile(string fileName) : base(fileName, Extension) {} } #endregion #region Setup [SetUp] public void FixtureSetup() { existingFile = Guid.NewGuid() + ".tst"; using (StreamWriter f = File.CreateText(existingFile)) {} } [TearDown] public void FixtureTearDown() { File.Delete(existingFile); } [SetUp] public void TestSetup() {} [TearDown] public void TestTearDown() {} #endregion } }