Example #1
0
        public void ReadWmtsConnectionInfos_FileWithoutWmtsConnectionInfos_ReturnsEmptyList()
        {
            // Setup
            string filePath = Path.Combine(testPath, "WmtsConnectionInfosZeroWmtsConnections.txt");
            var    reader   = new WmtsConnectionInfoReader();

            // Call
            WmtsConnectionInfo[] readConnectionInfos = reader.ReadWmtsConnectionInfos(filePath).ToArray();

            // Assert
            Assert.AreEqual(0, readConnectionInfos.Length);
        }
Example #2
0
        public void ReadWmtsConnectionInfos_FileMissing_ReturnsEmptyList()
        {
            // Setup
            string filePath = Path.Combine(testPath, Path.GetRandomFileName());
            var    reader   = new WmtsConnectionInfoReader();

            // Call
            IEnumerable <WmtsConnectionInfo> readInfos = reader.ReadWmtsConnectionInfos(filePath);

            // Assert
            CollectionAssert.IsEmpty(readInfos);
        }
Example #3
0
        public void ReadWmtsConnectionInfos_FilePathIsDirectory_ThrowArgumentException()
        {
            // Setup
            var reader = new WmtsConnectionInfoReader();

            // Call
            TestDelegate call = () => reader.ReadWmtsConnectionInfos("c:/");

            // Assert
            const string expectedMessage = "bestandspad mag niet verwijzen naar een lege bestandsnaam.";
            string       message         = Assert.Throws <ArgumentException>(call).Message;

            StringAssert.Contains(expectedMessage, message);
        }
Example #4
0
        public void ReadWmtsConnectionInfos_NoFilePath_ThrowArgumentException(string filePath)
        {
            // Setup
            var reader = new WmtsConnectionInfoReader();

            // Call
            TestDelegate call = () => reader.ReadWmtsConnectionInfos(filePath);

            // Assert
            const string expectedMessage = "bestandspad mag niet leeg of ongedefinieerd zijn.";
            string       message         = Assert.Throws <ArgumentException>(call).Message;

            StringAssert.Contains(expectedMessage, message);
        }
Example #5
0
        public void ReadWmtsConnectionInfos_FileMissingOneNameElement_SkipdAndReadsRestOfFile()
        {
            // Setup
            string filePath = Path.Combine(testPath, "twoWmtsConnectionInfosOneWithoutNameElement.txt");
            var    reader   = new WmtsConnectionInfoReader();

            // Call
            WmtsConnectionInfo[] readConnectionInfos = reader.ReadWmtsConnectionInfos(filePath).ToArray();

            // Assert
            Assert.AreEqual(1, readConnectionInfos.Length);
            var expectedWmtsConnectionInfo = new WmtsConnectionInfo(@"second name", @"https://domain.com");

            AssertAreEqual(expectedWmtsConnectionInfo, readConnectionInfos[0]);
        }
Example #6
0
        public void ReadWmtsConnectionInfos_FilePathHasInvalidPathCharacter_ThrowArgumentException()
        {
            // Setup
            char[] invalidPathChars = Path.GetInvalidPathChars();
            string filePath         = "c:/_.config".Replace('_', invalidPathChars[0]);
            var    reader           = new WmtsConnectionInfoReader();

            // Call
            TestDelegate call = () => reader.ReadWmtsConnectionInfos(filePath);

            // Assert
            string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': "
                                     + "er zitten ongeldige tekens in het bestandspad. Alle tekens in het bestandspad moeten geldig zijn.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, expectedMessage);
        }
Example #7
0
        public void ReadDefaultWmtsConnectionInfos_Always_ReturnsExpectedWmtsConnectionInfos()
        {
            // Setup
            var reader = new WmtsConnectionInfoReader();

            // Call
            ReadOnlyCollection <WmtsConnectionInfo> readConnectionInfos = reader.ReadDefaultWmtsConnectionInfos();

            // Assert
            Assert.AreEqual(2, readConnectionInfos.Count);
            var firstExpected  = new WmtsConnectionInfo(@"ESRI luchtfoto", @"http://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/WMTS?");
            var secondExpected = new WmtsConnectionInfo(@"PDOK", @"https://geodata.nationaalgeoregister.nl/tiles/service/wmts/ahn2?request=GetCapabilities");

            AssertAreEqual(firstExpected, readConnectionInfos[0]);
            AssertAreEqual(secondExpected, readConnectionInfos[1]);
        }
Example #8
0
        public void ReadWmtsConnectionInfos_FileWithTwoWmtsConnectionInfosReversedOrder_ReturnsExpectedWmtsConnectionInfos()
        {
            // Setup
            string filePath = Path.Combine(testPath, "twoValidWmtsConnectionInfosReversedOrder.txt");
            var    reader   = new WmtsConnectionInfoReader();

            // Call
            WmtsConnectionInfo[] readConnectionInfos = reader.ReadWmtsConnectionInfos(filePath).ToArray();

            // Assert
            Assert.AreEqual(2, readConnectionInfos.Length);
            var firstExpected  = new WmtsConnectionInfo(@"Actueel Hoogtebestand Nederland (AHN1)", @"https://geodata.nationaalgeoregister.nl/tiles/service/wmts/ahn1?request=GetCapabilities");
            var secondExpected = new WmtsConnectionInfo(@"Zeegraskartering", @"https://geodata.nationaalgeoregister.nl/zeegraskartering/wfs?request=GetCapabilities");

            AssertAreEqual(firstExpected, readConnectionInfos[0]);
            AssertAreEqual(secondExpected, readConnectionInfos[1]);
        }
Example #9
0
        public void ReadWmtsConnectionInfos_FileWithoutWmtsConnectionsElement_ThrowsCriticalFileReadException()
        {
            // Setup
            string filePath = Path.Combine(testPath, "WmtsConnectionInfosWithoutWmtsConnectionsElement.txt");
            var    reader   = new WmtsConnectionInfoReader();

            // Call
            TestDelegate call = () => reader.ReadWmtsConnectionInfos(filePath);

            // Assert
            var    exception       = Assert.Throws <CriticalFileReadException>(call);
            string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': het bestand "
                                     + "kon niet worden geopend. Mogelijk is het bestand corrupt "
                                     + "of in gebruik door een andere applicatie.";

            Assert.AreEqual(expectedMessage, exception.Message);
            Assert.IsInstanceOf <XmlException>(exception.InnerException);
        }
Example #10
0
        private IEnumerable <WmtsConnectionInfo> GetSavedWmtsConnectionInfos()
        {
            var reader = new WmtsConnectionInfoReader();

            if (!File.Exists(wmtsConnectionInfoFilePath))
            {
                return(reader.ReadDefaultWmtsConnectionInfos());
            }

            try
            {
                return(reader.ReadWmtsConnectionInfos(wmtsConnectionInfoFilePath));
            }
            catch (CriticalFileReadException exception)
            {
                log.Error(exception.Message, exception);
            }

            return(Enumerable.Empty <WmtsConnectionInfo>());
        }
Example #11
0
        public void ReadWmtsConnectionInfos_FileLocked_ThrowsCriticalFileReadException()
        {
            // Setup
            string filePath = TestHelper.GetScratchPadPath(nameof(ReadWmtsConnectionInfos_FileLocked_ThrowsCriticalFileReadException));
            var    reader   = new WmtsConnectionInfoReader();

            using (var fileDisposeHelper = new FileDisposeHelper(filePath))
            {
                fileDisposeHelper.LockFiles();

                // Call
                TestDelegate call = () => reader.ReadWmtsConnectionInfos(filePath);

                // Assert
                var    exception       = Assert.Throws <CriticalFileReadException>(call);
                string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': het bestand "
                                         + "kon niet worden geopend. Mogelijk is het bestand corrupt "
                                         + "of in gebruik door een andere applicatie.";
                Assert.AreEqual(expectedMessage, exception.Message);
                Assert.IsInstanceOf <IOException>(exception.InnerException);
            }
        }
Example #12
0
        public void ReadWmtsConnectionInfos_FileEmptyUrlElement_WarnsAndReadsRestOfFile()
        {
            // Setup
            string filePath = Path.Combine(testPath, "twoWmtsConnectionInfosOneEmptyUrl.txt");
            var    reader   = new WmtsConnectionInfoReader();

            WmtsConnectionInfo[] readConnectionInfos = null;

            // Call
            Action action = () => readConnectionInfos = reader.ReadWmtsConnectionInfos(filePath).ToArray();

            // Assert
            string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': het is niet mogelijk om WMTS connectie 'First name' aan te maken met URL ''.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(action, Tuple.Create(expectedMessage, LogLevelConstant.Warn));

            Assert.IsNotNull(readConnectionInfos);
            Assert.AreEqual(1, readConnectionInfos.Length);
            var expectedWmtsConnectionInfo = new WmtsConnectionInfo(@"second name", @"https://domain.com");

            AssertAreEqual(expectedWmtsConnectionInfo, readConnectionInfos[0]);
        }