コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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]);
        }
コード例 #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);
        }
コード例 #7
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]);
        }
コード例 #8
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);
        }
コード例 #9
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>());
        }
コード例 #10
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);
            }
        }
コード例 #11
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]);
        }