Index: Core/Components/src/Core.Components.DotSpatial.Forms/IO/WmtsConnectionInfoReader.cs
===================================================================
diff -u -rcfb8cddfe064c4aa4a1843846968554c918ba58f -rdf1c6b4964f21984dab85a5f8becb0824a82800f
--- Core/Components/src/Core.Components.DotSpatial.Forms/IO/WmtsConnectionInfoReader.cs (.../WmtsConnectionInfoReader.cs) (revision cfb8cddfe064c4aa4a1843846968554c918ba58f)
+++ Core/Components/src/Core.Components.DotSpatial.Forms/IO/WmtsConnectionInfoReader.cs (.../WmtsConnectionInfoReader.cs) (revision df1c6b4964f21984dab85a5f8becb0824a82800f)
@@ -22,6 +22,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Xml;
using System.Xml.Linq;
using Core.Common.IO.Exceptions;
@@ -45,6 +46,7 @@
/// Reads the WMTS Connection info objects from .
///
/// The file path that contains the information.
+ /// The read information.
/// Thrown when is invalid.
/// Thrown when could not successfully be read.
/// A valid path:
@@ -57,8 +59,13 @@
public IEnumerable ReadWmtsConnectionInfos(string path)
{
filePath = path;
- ValidateFilePath();
+ IOUtils.ValidateFilePath(filePath);
+ if (!File.Exists(filePath))
+ {
+ return Enumerable.Empty();
+ }
+
try
{
return ReadWmtsConnectionInfos();
@@ -71,16 +78,6 @@
}
}
- private void ValidateFilePath()
- {
- IOUtils.ValidateFilePath(filePath);
- if (!File.Exists(filePath))
- {
- string message = new FileReaderErrorMessageBuilder(filePath).Build(CoreCommonUtilsResources.Error_File_does_not_exist);
- throw new CriticalFileReadException(message);
- }
- }
-
private IEnumerable ReadWmtsConnectionInfos()
{
var connectionInfos = new List();
Index: Core/Components/src/Core.Components.DotSpatial.Forms/Views/WmtsLocationControl.cs
===================================================================
diff -u -r751356bafde2d37d48cfd8876e45091793940093 -rdf1c6b4964f21984dab85a5f8becb0824a82800f
--- Core/Components/src/Core.Components.DotSpatial.Forms/Views/WmtsLocationControl.cs (.../WmtsLocationControl.cs) (revision 751356bafde2d37d48cfd8876e45091793940093)
+++ Core/Components/src/Core.Components.DotSpatial.Forms/Views/WmtsLocationControl.cs (.../WmtsLocationControl.cs) (revision df1c6b4964f21984dab85a5f8becb0824a82800f)
@@ -40,12 +40,14 @@
///
public partial class WmtsLocationControl : UserControl, IHasMapData
{
- private const string wmtsConnectionInfoFileName = "wmtsConnectionInfo.config";
private static readonly ILog log = LogManager.GetLogger(typeof(WmtsLocationControl));
+
+ private const string wmtsConnectionInfoFileName = "wmtsConnectionInfo.config";
private readonly List wmtsConnectionInfos;
- private readonly List capabilities;
private string wmtsConnectionInfoFilePath;
+ private readonly List capabilities;
+
///
/// Creates a new instance of .
///
@@ -124,7 +126,10 @@
var reader = new WmtsConnectionInfoReader();
return reader.ReadWmtsConnectionInfos(wmtsConnectionInfoFilePath);
}
- catch (CriticalFileReadException exception) {}
+ catch (CriticalFileReadException exception)
+ {
+ log.Error(exception.Message, exception);
+ }
return Enumerable.Empty();
}
@@ -135,7 +140,10 @@
var writer = new WmtsConnectionInfoWriter(wmtsConnectionInfoFilePath);
writer.WriteWmtsConnectionInfo(wmtsConnectionInfos);
}
- catch (CriticalFileWriteException exception) {}
+ catch (CriticalFileWriteException exception)
+ {
+ log.Error(exception.Message, exception);
+ }
}
private WmtsConnectionInfo TryCreateWmtsConnectionInfo(string wmtsConnectionName, string wmtsConnectionUrl)
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoReaderTest.cs
===================================================================
diff -u -r7b85dbce8bcc39e824c367468892764778527ce4 -rdf1c6b4964f21984dab85a5f8becb0824a82800f
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoReaderTest.cs (.../WmtsConnectionInfoReaderTest.cs) (revision 7b85dbce8bcc39e824c367468892764778527ce4)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoReaderTest.cs (.../WmtsConnectionInfoReaderTest.cs) (revision df1c6b4964f21984dab85a5f8becb0824a82800f)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
@@ -33,7 +34,7 @@
[TestFixture]
public class WmtsConnectionInfoReaderTest
{
- private static readonly string testPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Forms, "WmtsConnectionInfo");
+ private static readonly string testPath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.DotSpatial.Forms, "WmtsConnectionInfo");
[Test]
[TestCase("")]
@@ -86,19 +87,17 @@
}
[Test]
- public void ReadWmtsConnectionInfos_FileMissing_ThrowsCriticalFileReadException()
+ public void ReadWmtsConnectionInfos_FileMissing_ReturnsEmptyList()
{
// Setup
string filePath = Path.Combine(testPath, Path.GetRandomFileName());
var reader = new WmtsConnectionInfoReader();
// Call
- TestDelegate call = () => reader.ReadWmtsConnectionInfos(filePath);
+ IEnumerable readInfos = reader.ReadWmtsConnectionInfos(filePath);
// Assert
- var expectedMessage = $"Fout bij het lezen van bestand '{filePath}': het bestand bestaat niet.";
- string actualMessage = Assert.Throws(call).Message;
- Assert.AreEqual(expectedMessage, actualMessage);
+ Assert.IsEmpty(readInfos);
}
[Test]
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsLocationControlTest.cs
===================================================================
diff -u -r751356bafde2d37d48cfd8876e45091793940093 -rdf1c6b4964f21984dab85a5f8becb0824a82800f
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsLocationControlTest.cs (.../WmtsLocationControlTest.cs) (revision 751356bafde2d37d48cfd8876e45091793940093)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsLocationControlTest.cs (.../WmtsLocationControlTest.cs) (revision df1c6b4964f21984dab85a5f8becb0824a82800f)
@@ -318,6 +318,41 @@
[Test]
[Apartment(ApartmentState.STA)]
+ public void GivenInvalidWmtsConnectionInfos_WhenConstructed_ThenLogGenerated()
+ {
+ // Given
+ SettingsHelper.Instance = new TestSettingsHelper
+ {
+ ExpectedApplicationVersion = "WmtsConnectionInfosWithoutWmtsConnectionsElement",
+ ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath)
+ };
+
+ // When
+ Action action = () =>
+ {
+ using (var control = new WmtsLocationControl())
+ using (var form = new Form())
+ {
+ form.Controls.Add(control);
+
+ // Then
+ var comboBox = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject;
+ var dataSource = (List) comboBox.DataSource;
+ Assert.AreEqual(0, dataSource.Count);
+ }
+ };
+
+ string wmtsConnectionInfoConfig = Path.Combine(TestHelper.GetTestDataPath(
+ testPath,
+ "WmtsConnectionInfosWithoutWmtsConnectionsElement"),
+ "wmtsConnectionInfo.config");
+ var expectedMessage = $"Fout bij het lezen van bestand '{wmtsConnectionInfoConfig}': "
+ + "het bestand kon niet worden geopend. Mogelijk is het bestand corrupt of in gebruik door een andere applicatie.";
+ TestHelper.AssertLogMessageWithLevelIsGenerated(action, Tuple.Create(expectedMessage, LogLevelConstant.Error));
+ }
+
+ [Test]
+ [Apartment(ApartmentState.STA)]
public void GivenWmtsLocationControlAndAddLocationClicked_WhenDialogCanceled_ThenWmtsLocationsNotUpdated()
{
// Given
@@ -458,6 +493,68 @@
[Test]
[Apartment(ApartmentState.STA)]
+ public void GivenWmtsLocationControlAndAddLocationClicked_WhenConfigFileInUse_ThenWmtsLocationsNotUpdatedAndLoggenerated()
+ {
+ // Given
+ const string name = @"someName";
+ const string url = @"someUrl";
+
+ SettingsHelper.Instance = new TestSettingsHelper
+ {
+ ExpectedApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(testPath, "noConfig")
+ };
+
+ var mockRepository = new MockRepository();
+ var tileFactory = mockRepository.StrictMock();
+ tileFactory.Expect(tf => tf.GetWmtsTileSources(url)).Return(Enumerable.Empty());
+ mockRepository.ReplayAll();
+
+ DialogBoxHandler = (formName, wnd) =>
+ {
+ using (var formTester = new FormTester(formName))
+ {
+ var dialog = (WmtsConnectionDialog) formTester.TheObject;
+ var nameTextBox = (TextBox) new TextBoxTester("nameTextBox", dialog).TheObject;
+ var urlTextBox = (TextBox) new TextBoxTester("urlTextBox", dialog).TheObject;
+ var actionButton = new ButtonTester("actionButton", dialog);
+
+ nameTextBox.Text = name;
+ urlTextBox.Text = url;
+
+ actionButton.Click();
+ }
+ };
+
+ string configFilePath = Path.Combine(SettingsHelper.Instance.GetApplicationLocalUserSettingsDirectory(),
+ wmtsconnectioninfoConfigFile);
+ using (var fileDisposeHelper = new FileDisposeHelper(configFilePath))
+ using (new UseCustomTileSourceFactoryConfig(tileFactory))
+ using (var form = new Form())
+ using (var control = new WmtsLocationControl())
+ {
+ form.Controls.Add(control);
+ form.Show();
+
+ fileDisposeHelper.LockFiles();
+
+ var buttonAddLocation = new ButtonTester("addLocationButton", form);
+
+ // When
+ Action action = () => { buttonAddLocation.Click(); };
+
+ // Then
+ string exceptionMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{configFilePath}'.";
+ TestHelper.AssertLogMessageWithLevelIsGenerated(action, Tuple.Create(exceptionMessage, LogLevelConstant.Error));
+ var comboBox = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject;
+ var dataSource = (List) comboBox.DataSource;
+ Assert.AreEqual(1, dataSource.Count);
+ }
+
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ [Apartment(ApartmentState.STA)]
public void GivenWmtsLocationControlAndEditLocationClicked_WhenDialogCanceled_ThenWmtsLocationsNotUpdated()
{
// Given
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/WmtsConnectionInfosWithoutWmtsConnectionsElement.txt
===================================================================
diff -u
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/WmtsConnectionInfosWithoutWmtsConnectionsElement.txt (revision 0)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/WmtsConnectionInfosWithoutWmtsConnectionsElement.txt (revision df1c6b4964f21984dab85a5f8becb0824a82800f)
@@ -0,0 +1 @@
+
\ No newline at end of file
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/WmtsConnectionInfosZeroWmtsConnections.txt
===================================================================
diff -u
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/WmtsConnectionInfosZeroWmtsConnections.txt (revision 0)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/WmtsConnectionInfosZeroWmtsConnections.txt (revision df1c6b4964f21984dab85a5f8becb0824a82800f)
@@ -0,0 +1 @@
+
\ No newline at end of file
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoValidWmtsConnectionInfos.txt
===================================================================
diff -u
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoValidWmtsConnectionInfos.txt (revision 0)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoValidWmtsConnectionInfos.txt (revision df1c6b4964f21984dab85a5f8becb0824a82800f)
@@ -0,0 +1 @@
+Actueel Hoogtebestand Nederland (AHN1)https://geodata.nationaalgeoregister.nl/tiles/service/wmts/ahn1?request=GetCapabilitiesZeegraskarteringhttps://geodata.nationaalgeoregister.nl/zeegraskartering/wfs?request=GetCapabilities
\ No newline at end of file
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoValidWmtsConnectionInfosReversedOrder.txt
===================================================================
diff -u
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoValidWmtsConnectionInfosReversedOrder.txt (revision 0)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoValidWmtsConnectionInfosReversedOrder.txt (revision df1c6b4964f21984dab85a5f8becb0824a82800f)
@@ -0,0 +1 @@
+https://geodata.nationaalgeoregister.nl/tiles/service/wmts/ahn1?request=GetCapabilitiesActueel Hoogtebestand Nederland (AHN1)https://geodata.nationaalgeoregister.nl/zeegraskartering/wfs?request=GetCapabilitiesZeegraskartering
\ No newline at end of file
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoWmtsConnectionInfosOneEmptyUrl.txt
===================================================================
diff -u
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoWmtsConnectionInfosOneEmptyUrl.txt (revision 0)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoWmtsConnectionInfosOneEmptyUrl.txt (revision df1c6b4964f21984dab85a5f8becb0824a82800f)
@@ -0,0 +1 @@
+First namesecond namehttps://domain.com
\ No newline at end of file
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoWmtsConnectionInfosOneWithoutNameElement.txt
===================================================================
diff -u
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoWmtsConnectionInfosOneWithoutNameElement.txt (revision 0)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoWmtsConnectionInfosOneWithoutNameElement.txt (revision df1c6b4964f21984dab85a5f8becb0824a82800f)
@@ -0,0 +1 @@
+First URLsecond namehttps://domain.com
\ No newline at end of file
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoWmtsConnectionInfosOneWithoutUrlElement.txt
===================================================================
diff -u
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoWmtsConnectionInfosOneWithoutUrlElement.txt (revision 0)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfo/twoWmtsConnectionInfosOneWithoutUrlElement.txt (revision df1c6b4964f21984dab85a5f8becb0824a82800f)
@@ -0,0 +1 @@
+First namesecond namehttps://domain.com
\ No newline at end of file
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfosWithoutWmtsConnectionsElement/wmtsConnectionInfo.config
===================================================================
diff -u
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfosWithoutWmtsConnectionsElement/wmtsConnectionInfo.config (revision 0)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/test-data/WmtsConnectionInfosWithoutWmtsConnectionsElement/wmtsConnectionInfo.config (revision df1c6b4964f21984dab85a5f8becb0824a82800f)
@@ -0,0 +1 @@
+
\ No newline at end of file
Fisheye: Tag df1c6b4964f21984dab85a5f8becb0824a82800f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/test-data/WmtsConnectionInfo/WmtsConnectionInfosWithoutWmtsConnectionsElement.txt'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag df1c6b4964f21984dab85a5f8becb0824a82800f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/test-data/WmtsConnectionInfo/WmtsConnectionInfosZeroWmtsConnections.txt'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag df1c6b4964f21984dab85a5f8becb0824a82800f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/test-data/WmtsConnectionInfo/twoValidWmtsConnectionInfos.txt'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag df1c6b4964f21984dab85a5f8becb0824a82800f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/test-data/WmtsConnectionInfo/twoValidWmtsConnectionInfosReversedOrder.txt'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag df1c6b4964f21984dab85a5f8becb0824a82800f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/test-data/WmtsConnectionInfo/twoWmtsConnectionInfosOneEmptyUrl.txt'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag df1c6b4964f21984dab85a5f8becb0824a82800f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/test-data/WmtsConnectionInfo/twoWmtsConnectionInfosOneWithoutNameElement.txt'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag df1c6b4964f21984dab85a5f8becb0824a82800f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/test-data/WmtsConnectionInfo/twoWmtsConnectionInfosOneWithoutUrlElement.txt'.
Fisheye: No comparison available. Pass `N' to diff?