コード例 #1
0
        public void WriteWmtsConnectionInfo_ValidWmtsConnectionInfo_SavesWmtsConnectionInfoToFile()
        {
            // Setup
            string filePath = TestHelper.GetScratchPadPath(nameof(WriteWmtsConnectionInfo_ValidWmtsConnectionInfo_SavesWmtsConnectionInfoToFile));
            var    wmtsConfigurationWriter = new WmtsConnectionInfoWriter(filePath);

            var wmtsConnectionInfos = new[]
            {
                new WmtsConnectionInfo("name1", "url1"),
                new WmtsConnectionInfo("name2", "url2")
            };

            using (new FileDisposeHelper(filePath))
            {
                // Call
                wmtsConfigurationWriter.WriteWmtsConnectionInfo(wmtsConnectionInfos);

                // Assert
                string actualContent   = GetFileContent(filePath);
                string expectedContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                                         "<WmtsConnections>" + Environment.NewLine +
                                         "  <WmtsConnection>" + Environment.NewLine +
                                         "    <Name>name1</Name>" + Environment.NewLine +
                                         "    <URL>url1</URL>" + Environment.NewLine +
                                         "  </WmtsConnection>" + Environment.NewLine +
                                         "  <WmtsConnection>" + Environment.NewLine +
                                         "    <Name>name2</Name>" + Environment.NewLine +
                                         "    <URL>url2</URL>" + Environment.NewLine +
                                         "  </WmtsConnection>" + Environment.NewLine +
                                         "</WmtsConnections>";
                Assert.AreEqual(expectedContent, actualContent);
            }
        }
コード例 #2
0
        public void WriteWmtsConnectionInfo_InvalidDirectoryRights_ThrowCriticalFileWriteException()
        {
            // Setup
            string directoryPath = TestHelper.GetScratchPadPath(nameof(WriteWmtsConnectionInfo_InvalidDirectoryRights_ThrowCriticalFileWriteException));

            Directory.CreateDirectory(directoryPath);
            string filePath = Path.Combine(directoryPath, Path.GetRandomFileName());
            var    wmtsConfigurationWriter = new WmtsConnectionInfoWriter(filePath);

            try
            {
                using (new DirectoryPermissionsRevoker(directoryPath, FileSystemRights.Write))
                {
                    // Call
                    TestDelegate call = () => wmtsConfigurationWriter.WriteWmtsConnectionInfo(Enumerable.Empty <WmtsConnectionInfo>());

                    // Assert
                    string message         = Assert.Throws <CriticalFileWriteException>(call).Message;
                    string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.";
                    Assert.AreEqual(expectedMessage, message);
                }
            }
            finally
            {
                DirectoryHelper.TryDelete(directoryPath);
            }
        }
コード例 #3
0
 private void SaveWmtsConnectionInfos()
 {
     try
     {
         var writer = new WmtsConnectionInfoWriter(wmtsConnectionInfoFilePath);
         writer.WriteWmtsConnectionInfo(wmtsConnectionInfos);
     }
     catch (CriticalFileWriteException exception)
     {
         log.Error(exception.Message, exception);
     }
 }
コード例 #4
0
        public void WriteWmtsConnectionInfo_WmtsConnectionInfosNull_ThrowArgumentNullException()
        {
            // Setup
            string filePath = TestHelper.GetScratchPadPath(nameof(WriteWmtsConnectionInfo_WmtsConnectionInfosNull_ThrowArgumentNullException));
            var    wmtsConfigurationWriter = new WmtsConnectionInfoWriter(filePath);

            // Call
            TestDelegate call = () => wmtsConfigurationWriter.WriteWmtsConnectionInfo(null);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(call).ParamName;

            Assert.AreEqual("wmtsConnectionInfos", paramName);
        }
コード例 #5
0
        public void WriteWmtsConnectionInfo_DirectoryDoesNotExist_CreatesDirectoryAndFile()
        {
            // Setup
            string directoryPath           = TestHelper.GetScratchPadPath(nameof(WriteWmtsConnectionInfo_DirectoryDoesNotExist_CreatesDirectoryAndFile));
            string filePath                = Path.Combine(directoryPath, Path.GetRandomFileName());
            var    wmtsConfigurationWriter = new WmtsConnectionInfoWriter(filePath);

            try
            {
                // Call
                wmtsConfigurationWriter.WriteWmtsConnectionInfo(Enumerable.Empty <WmtsConnectionInfo>());

                // Assert
                Assert.IsTrue(File.Exists(filePath));
            }
            finally
            {
                DirectoryHelper.TryDelete(directoryPath);
            }
        }