Index: Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj =================================================================== diff -u -raeb0c6618ebf88db04e417b47693c704c7151181 -rcfb8cddfe064c4aa4a1843846968554c918ba58f --- Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj (.../Core.Components.DotSpatial.Forms.csproj) (revision aeb0c6618ebf88db04e417b47693c704c7151181) +++ Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj (.../Core.Components.DotSpatial.Forms.csproj) (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -70,6 +70,8 @@ + + @@ -88,13 +90,46 @@ Resources.resx + + + + Form + + + WmtsConnectionDialog.cs + + + + + + + UserControl + + + WmtsLocationControl.cs + {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base False + + {9A2D67E6-26AC-4D17-B11A-2B4372F2F572} + Core.Common.Controls + False + + + {E344867E-9AC9-44C8-88A5-8185681679A9} + Core.Common.IO + False + + + {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} + Core.Common.Utils + False + {aa47e858-a2a7-470e-8b2d-c76ae8ed9ccd} Core.Components.DotSpatial @@ -124,7 +159,16 @@ Resources.Designer.cs Designer + + WmtsConnectionDialog.cs + + + WmtsLocationControl.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + 2 + + + + Top, Left, Right + + + + 79, 3 + + + 6, 3, 6, 3 + + + 50, 4 + + + 288, 20 + + + 1 + + + nameTextBox + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel2 + + + 0 + + + Top, Left, Right + + + 79, 29 + + + 6, 3, 6, 3 + + + 50, 4 + + + 288, 20 + + + 2 + + + urlTextBox + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel2 + + + 1 + + + True + + + 3, 6 + + + 3, 6, 3, 0 + + + 67, 13 + + + 5 + + + Omschrijving + + + nameLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel2 + + + 2 + + + True + + + 3, 32 + + + 3, 6, 3, 0 + + + 29, 13 + + + 6 + + + URL + + + 17, 17 + + + URL naar het WMTS dataservice inclusief 'capabilities'. + + + urlLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel2 + + + 3 + + + Fill + + + 0, 0 + + + 3 + + + 373, 113 + + + 0 + + + tableLayoutPanel2 + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="nameTextBox" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="urlTextBox" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="nameLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="urlLabel" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,Percent,100" /></TableLayoutSettings> + + + True + + + 295, 3 + + + 75, 23 + + + 4 + + + Annuleren + + + cancelButton + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + flowLayoutPanel1 + + + 0 + + + 214, 3 + + + 75, 23 + + + 3 + + + Toevoegen + + + actionButton + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + flowLayoutPanel1 + + + 1 + + + Bottom + + + 0, 113 + + + Yes + + + 373, 29 + + + 2 + + + flowLayoutPanel1 + + + System.Windows.Forms.FlowLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + 6, 13 + + + 373, 142 + + + Nieuwe WMTS locatie toevoegen + + + urlToolTip + + + System.Windows.Forms.ToolTip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + WmtsConnectionDialog + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file Index: Core/Components/src/Core.Components.DotSpatial.Forms/Views/WmtsLocationControl.Designer.cs =================================================================== diff -u --- Core/Components/src/Core.Components.DotSpatial.Forms/Views/WmtsLocationControl.Designer.cs (revision 0) +++ Core/Components/src/Core.Components.DotSpatial.Forms/Views/WmtsLocationControl.Designer.cs (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -0,0 +1,140 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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. + +namespace Core.Components.DotSpatial.Forms.Views +{ + partial class WmtsLocationControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WmtsLocationControl)); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); + this.urlLocationLabel = new System.Windows.Forms.Label(); + this.urlLocationComboBox = new System.Windows.Forms.ComboBox(); + this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel(); + this.connectToButton = new System.Windows.Forms.Button(); + this.addLocationButton = new System.Windows.Forms.Button(); + this.editLocationButton = new System.Windows.Forms.Button(); + this.dataGridViewControl = new Core.Common.Controls.DataGrid.DataGridViewControl(); + this.tableLayoutPanel1.SuspendLayout(); + this.tableLayoutPanel2.SuspendLayout(); + this.flowLayoutPanel2.SuspendLayout(); + this.SuspendLayout(); + // + // tableLayoutPanel1 + // + resources.ApplyResources(this.tableLayoutPanel1, "tableLayoutPanel1"); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel2, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.dataGridViewControl, 0, 2); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + // + // tableLayoutPanel2 + // + resources.ApplyResources(this.tableLayoutPanel2, "tableLayoutPanel2"); + this.tableLayoutPanel2.Controls.Add(this.urlLocationLabel, 0, 0); + this.tableLayoutPanel2.Controls.Add(this.urlLocationComboBox, 1, 0); + this.tableLayoutPanel2.Name = "tableLayoutPanel2"; + // + // urlLocationLabel + // + resources.ApplyResources(this.urlLocationLabel, "urlLocationLabel"); + this.urlLocationLabel.Name = "urlLocationLabel"; + // + // urlLocationComboBox + // + resources.ApplyResources(this.urlLocationComboBox, "urlLocationComboBox"); + this.urlLocationComboBox.FormattingEnabled = true; + this.urlLocationComboBox.Name = "urlLocationComboBox"; + // + // flowLayoutPanel2 + // + resources.ApplyResources(this.flowLayoutPanel2, "flowLayoutPanel2"); + this.flowLayoutPanel2.Controls.Add(this.connectToButton); + this.flowLayoutPanel2.Controls.Add(this.addLocationButton); + this.flowLayoutPanel2.Controls.Add(this.editLocationButton); + this.flowLayoutPanel2.Name = "flowLayoutPanel2"; + // + // connectToButton + // + resources.ApplyResources(this.connectToButton, "connectToButton"); + this.connectToButton.Name = "connectToButton"; + this.connectToButton.UseVisualStyleBackColor = true; + // + // addButton + // + resources.ApplyResources(this.addLocationButton, "addLocationButton"); + this.addLocationButton.Name = "addLocationButton"; + this.addLocationButton.UseVisualStyleBackColor = true; + // + // editButton + // + resources.ApplyResources(this.editLocationButton, "editLocationButton"); + this.editLocationButton.Name = "editLocationButton"; + this.editLocationButton.UseVisualStyleBackColor = true; + // + // dataGridView + // + this.dataGridViewControl.Dock = System.Windows.Forms.DockStyle.Fill; + resources.ApplyResources(this.dataGridViewControl, "dataGridViewControl"); + this.dataGridViewControl.Name = "dataGridViewControl"; + // + // WmtsLayerControl + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.tableLayoutPanel1); + this.Name = "WmtsLayerControl"; + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.tableLayoutPanel2.ResumeLayout(false); + this.tableLayoutPanel2.PerformLayout(); + this.flowLayoutPanel2.ResumeLayout(false); + this.flowLayoutPanel2.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private Core.Common.Controls.DataGrid.DataGridViewControl dataGridViewControl; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2; + private System.Windows.Forms.Label urlLocationLabel; + private System.Windows.Forms.ComboBox urlLocationComboBox; + private System.Windows.Forms.Button connectToButton; + private System.Windows.Forms.Button addLocationButton; + private System.Windows.Forms.Button editLocationButton; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; + } +} Index: Core/Components/src/Core.Components.DotSpatial.Forms/Views/WmtsLocationControl.cs =================================================================== diff -u --- Core/Components/src/Core.Components.DotSpatial.Forms/Views/WmtsLocationControl.cs (revision 0) +++ Core/Components/src/Core.Components.DotSpatial.Forms/Views/WmtsLocationControl.cs (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -0,0 +1,190 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.Views; +using Core.Components.DotSpatial.Forms.Properties; + +namespace Core.Components.DotSpatial.Forms.Views +{ + /// + /// This class represents a where WMTS locations can be administrated. + /// + public partial class WmtsLocationControl : UserControl, IView + { + private readonly List wmtsConnectionInfos; + private IEnumerable capabilities; + + /// + /// Creates a new instance of . + /// + public WmtsLocationControl() + { + wmtsConnectionInfos = new List(); + + InitializeComponent(); + InitializeDataGridView(); + InitializeComboBoxDataSource(); + InitializeEventHandlers(); + } + + public object Data + { + get + { + return capabilities; + } + set + { + capabilities = value as IEnumerable; + UpdateDataGridViewDataSource(); + } + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + private WmtsConnectionInfo TryCreateWmtsConnectionInfo(string wmtsConnectionName, string wmtsConnectionUrl) + { + try + { + return new WmtsConnectionInfo(wmtsConnectionName, wmtsConnectionUrl); + } + catch (ArgumentException) + { + return null; + } + } + + #region DataGridView + + private void InitializeDataGridView() + { + dataGridViewControl.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewControl.MultiSelect = false; + + dataGridViewControl.AddTextBoxColumn(nameof(WmtsCapabilityRow.Id), Resources.WmtsCapability_MapLayer_Id, + true); + dataGridViewControl.AddTextBoxColumn(nameof(WmtsCapabilityRow.Format), Resources.WmtsCapability_MapLayer_Format, + true); + dataGridViewControl.AddTextBoxColumn(nameof(WmtsCapabilityRow.Title), Resources.WmtsCapability_MapLayer_Title, + true); + dataGridViewControl.AddTextBoxColumn(nameof(WmtsCapabilityRow.CoordinateSystem), Resources.WmtsCapability_MapLayer_CoordinateSystem, + true); + } + + private void UpdateDataGridViewDataSource() + { + dataGridViewControl.SetDataSource(capabilities?.ToArray()); + } + + #endregion + + #region ComboBox + + private void InitializeComboBoxDataSource() + { + urlLocationComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + urlLocationComboBox.Sorted = true; + UpdateComboBoxDataSource(); + } + + private void UpdateComboBoxDataSource() + { + object selectedItem = urlLocationComboBox.SelectedItem; + urlLocationComboBox.DataSource = null; + urlLocationComboBox.DataSource = wmtsConnectionInfos; + urlLocationComboBox.DisplayMember = nameof(WmtsConnectionInfo.Name); + urlLocationComboBox.ValueMember = nameof(WmtsConnectionInfo.Url); + + urlLocationComboBox.SelectedItem = selectedItem; + } + + #endregion + + #region Event handlers + + private void InitializeEventHandlers() + { + addLocationButton.Click += AddLocationButtonOnClick; + editLocationButton.Click += EditLocationButtonOnClick; + } + + private void AddLocationButtonOnClick(object sender, EventArgs eventArgs) + { + Form controlForm = FindForm(); + using (var dialog = new WmtsConnectionDialog(controlForm)) + { + if (dialog.ShowDialog() != DialogResult.OK) + { + return; + } + + WmtsConnectionInfo createdWmtsConnectionInfos = TryCreateWmtsConnectionInfo(dialog.WmtsConnectionName, + dialog.WmtsConnectionUrl); + if (createdWmtsConnectionInfos != null) + { + wmtsConnectionInfos.Add(createdWmtsConnectionInfos); + UpdateComboBoxDataSource(); + } + } + } + + private void EditLocationButtonOnClick(object sender, EventArgs eventArgs) + { + var selectedWmtsConnectionInfo = urlLocationComboBox.SelectedItem as WmtsConnectionInfo; + if (selectedWmtsConnectionInfo == null) + { + return; + } + Form controlForm = FindForm(); + using (var dialog = new WmtsConnectionDialog(controlForm, selectedWmtsConnectionInfo)) + { + if (dialog.ShowDialog() != DialogResult.OK) + { + return; + } + + WmtsConnectionInfo createdWmtsConnectionInfos = TryCreateWmtsConnectionInfo(dialog.WmtsConnectionName, + dialog.WmtsConnectionUrl); + if (createdWmtsConnectionInfos != null) + { + wmtsConnectionInfos.Remove(selectedWmtsConnectionInfo); + wmtsConnectionInfos.Add(createdWmtsConnectionInfos); + UpdateComboBoxDataSource(); + + urlLocationComboBox.SelectedItem = createdWmtsConnectionInfos; + } + } + } + + #endregion + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.DotSpatial.Forms/Views/WmtsLocationControl.resx =================================================================== diff -u --- Core/Components/src/Core.Components.DotSpatial.Forms/Views/WmtsLocationControl.resx (revision 0) +++ Core/Components/src/Core.Components.DotSpatial.Forms/Views/WmtsLocationControl.resx (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -0,0 +1,390 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + 1 + + + True + + + 2 + + + True + + + + 3, 6 + + + + 3, 6, 3, 0 + + + 73, 13 + + + 0 + + + Locatie (URL) + + + urlLocationLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel2 + + + 0 + + + Fill + + + 82, 3 + + + 396, 21 + + + 1 + + + urlLocationComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel2 + + + 1 + + + Fill + + + 3, 3 + + + 1 + + + 481, 27 + + + 2 + + + tableLayoutPanel2 + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="urlLocationLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="urlLocationComboBox" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="Percent,100" /></TableLayoutSettings> + + + True + + + True + + + 3, 3 + + + 102, 23 + + + 0 + + + Verbinding maken + + + connectToButton + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + flowLayoutPanel2 + + + 0 + + + True + + + 111, 3 + + + 115, 23 + + + 1 + + + Locatie toevoegen... + + + addLocationButton + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + flowLayoutPanel2 + + + 1 + + + True + + + 232, 3 + + + 116, 23 + + + 2 + + + Locatie aanpassen... + + + editLocationButton + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + flowLayoutPanel2 + + + 2 + + + 3, 36 + + + 351, 29 + + + 2 + + + flowLayoutPanel2 + + + System.Windows.Forms.FlowLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 1 + + + Fill + + + 3, 71 + + + 481, 146 + + + 0 + + + dataGridViewControl + + + System.Windows.Forms.DataGridView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 2 + + + Fill + + + 0, 0 + + + 3 + + + 487, 220 + + + 0 + + + tableLayoutPanel1 + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="tableLayoutPanel2" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="flowLayoutPanel2" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="dataGridView" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,Percent,100,Absolute,20" /></TableLayoutSettings> + + + True + + + 6, 13 + + + 487, 220 + + + WmtsLayerControl + + + System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file Index: Core/Components/src/Core.Components.DotSpatial.Forms/WmtsCapability.cs =================================================================== diff -u --- Core/Components/src/Core.Components.DotSpatial.Forms/WmtsCapability.cs (revision 0) +++ Core/Components/src/Core.Components.DotSpatial.Forms/WmtsCapability.cs (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -0,0 +1,103 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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 Core.Components.Gis.Data; + +namespace Core.Components.DotSpatial.Forms +{ + /// + /// Class representing a capability coming from a Web Map Tile Service (WMTS). + /// + public class WmtsCapability + { + /// + /// Creates a new instance of . + /// + /// The id of the WMTS capability. + /// The type of image format of the WMTS capability. + /// The title of the WMTS capability. + /// The coordinate system of the WMTS capability. + /// Thrown when any of the input parameters is null. + /// Thrown when is not stated as a MIME-type. + public WmtsCapability(string id, string format, string title, string coordinateSystem) + { + if (id == null) + { + throw new ArgumentNullException(nameof(id)); + } + if (format == null) + { + throw new ArgumentNullException(nameof(format)); + } + if (title == null) + { + throw new ArgumentNullException(nameof(title)); + } + if (coordinateSystem == null) + { + throw new ArgumentNullException(nameof(coordinateSystem)); + } + if (!format.StartsWith("image/")) + { + throw new ArgumentException(@"Specified image format is not a MIME type.", nameof(format)); + } + + Id = id; + Format = format; + Title = title; + CoordinateSystem = coordinateSystem; + } + + /// + /// Gets the id of the WMTS capability. + /// + public string Id { get;} + + /// + /// Gets the image format of the WMTS capability. + /// + public string Format { get; } + + /// + /// Gets the title of the WMTS capability. + /// + public string Title { get; } + + /// + /// Gets the coordinate system of the WMTS capability. + /// + public string CoordinateSystem { get; } + + /// + /// Creates a new instance of based upon the local properties. + /// + /// The name of the source (for visualization purposes only). + /// The URL to the capabilities of the WMTS. + /// The newly created . + /// Thrown when + /// or is null. + public WmtsMapData ToWmtsMapdata(string displayName, string sourceCapabilitiesUrl) + { + return new WmtsMapData(displayName, sourceCapabilitiesUrl, Id, Format); + } + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.DotSpatial.Forms/WmtsConnectionInfo.cs =================================================================== diff -u --- Core/Components/src/Core.Components.DotSpatial.Forms/WmtsConnectionInfo.cs (revision 0) +++ Core/Components/src/Core.Components.DotSpatial.Forms/WmtsConnectionInfo.cs (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -0,0 +1,64 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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; + +namespace Core.Components.DotSpatial.Forms +{ + /// + /// This class defines properties for a WMTS connection. + /// + public class WmtsConnectionInfo + { + /// + /// Creates a new instance of . + /// + /// The name associated with the . + /// The WMTS URL. + /// Thrown when is null. + /// Thrown when is null, + /// , or consists exclusively of white-space characters. + public WmtsConnectionInfo(string name, string url) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + if (string.IsNullOrWhiteSpace(url)) + { + throw new ArgumentException($@"{nameof(url)} must have a value.", nameof(url)); + } + + Name = name; + Url = url; + } + + /// + /// Gets the name associated with the URL. + /// + public string Name { get; } + + /// + /// Gets the URL. + /// + public string Url { get; } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj =================================================================== diff -u -raeb0c6618ebf88db04e417b47693c704c7151181 -rcfb8cddfe064c4aa4a1843846968554c918ba58f --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj (.../Core.Components.DotSpatial.Forms.Test.csproj) (revision aeb0c6618ebf88db04e417b47693c704c7151181) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj (.../Core.Components.DotSpatial.Forms.Test.csproj) (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -71,15 +71,24 @@ + + Properties\GlobalAssembly.cs + + + + + + + @@ -94,6 +103,14 @@ {3BBFD65B-B277-4E50-AE6D-BD24C3434609} Core.Common.Base + + {9A2D67E6-26AC-4D17-B11A-2B4372F2F572} + Core.Common.Controls + + + {E344867E-9AC9-44C8-88A5-8185681679A9} + Core.Common.IO + {d749ee4c-ce50-4c17-bf01-9a953028c126} Core.Common.TestUtil Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoReaderTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoReaderTest.cs (revision 0) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoReaderTest.cs (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -0,0 +1,265 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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 System.Linq; +using System.Xml; +using Core.Common.IO.Exceptions; +using Core.Common.TestUtil; +using Core.Components.DotSpatial.Forms.IO; +using NUnit.Framework; + +namespace Core.Components.DotSpatial.Forms.Test.IO +{ + [TestFixture] + public class WmtsConnectionInfoReaderTest + { + private static readonly string testPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Forms, "WmtsConnectionInfo"); + + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + 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(call).Message; + StringAssert.Contains(expectedMessage, message); + } + + [Test] + 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(call).Message; + StringAssert.Contains(expectedMessage, message); + } + + [Test] + public void ReadWmtsConnectionInfos_FilePathHasInvalidPathCharacter_ThrowArgumentException() + { + // Setup + char[] invalidFileNameChars = Path.GetInvalidFileNameChars(); + string invalidCharacter = invalidFileNameChars[0].ToString(); + var filePath = "c:/_.config".Replace("_", invalidCharacter); + var reader = new WmtsConnectionInfoReader(); + + // Call + TestDelegate call = () => reader.ReadWmtsConnectionInfos(filePath); + + // Assert + const string expectedMessage = "Fout bij het lezen van bestand 'c:/\".config': bestandspad " + + "mag niet de volgende tekens bevatten: \", <, >, " + + "|, \0, , , , , , , \a, \b, \t, \n, \v, \f, \r, " + + ", , , , , , , , , , , , , , , , , , :, *, ?, \\, /"; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] + public void ReadWmtsConnectionInfos_FileMissing_ThrowsCriticalFileReadException() + { + // Setup + string filePath = Path.Combine(testPath, Path.GetRandomFileName()); + var reader = new WmtsConnectionInfoReader(); + + // Call + TestDelegate call = () => 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); + } + + [Test] + public void ReadWmtsConnectionInfos_FileWithTwoWmtsConnectionInfos_ReturnsExpectedWmtsConnectionInfos() + { + // Setup + string filePath = Path.Combine(testPath, "twoValidWmtsConnectionInfos.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]); + } + + [Test] + 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]); + } + + [Test] + 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); + } + + [Test] + 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(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(exception.InnerException); + } + + [Test] + 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]); + } + + [Test] + public void ReadWmtsConnectionInfos_FileMissingOneUrlElement_SkipdAndReadsRestOfFile() + { + // Setup + string filePath = Path.Combine(testPath, "twoWmtsConnectionInfosOneWithoutUrlElement.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]); + } + + [Test] + 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]); + } + + [Test] + public void ReadWmtsConnectionInfos_FileLocked_ThrowsCriticalFileReadException() + { + // Setup + string filePath = Path.Combine(testPath, Path.GetRandomFileName()); + var reader = new WmtsConnectionInfoReader(); + + using (var fileDisposeHelper = new FileDisposeHelper(filePath)) + { + fileDisposeHelper.LockFiles(); + + // Call + TestDelegate call = () => reader.ReadWmtsConnectionInfos(filePath); + + // Assert + var exception = Assert.Throws(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(exception.InnerException); + } + } + + private static void AssertAreEqual(WmtsConnectionInfo expected, WmtsConnectionInfo actual) + { + Assert.AreEqual(expected.Name, actual.Name); + Assert.AreEqual(expected.Url, actual.Url); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoTest.cs (revision 0) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoTest.cs (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -0,0 +1,67 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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 Core.Common.TestUtil; +using NUnit.Framework; + +namespace Core.Components.DotSpatial.Forms.Test.IO +{ + [TestFixture] + public class WmtsConnectionInfoTest + { + [Test] + public void Constructor_NameNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new WmtsConnectionInfo(null, "url"); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("name", paramName); + } + + [Test] + public void Constructor_UrlNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new WmtsConnectionInfo("name", null); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "url must have a value."); + } + + [Test] + public void Constructor_ValidParameters_ExpectedProperties() + { + // Setup + const string name = "name"; + const string url = "url"; + + // Call + var connectionInfo = new WmtsConnectionInfo(name, url); + + // Assert + Assert.AreEqual(name, connectionInfo.Name); + Assert.AreEqual(url, connectionInfo.Url); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoWriterTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoWriterTest.cs (revision 0) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoWriterTest.cs (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -0,0 +1,163 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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 System.Linq; +using System.Security.AccessControl; +using Core.Common.IO.Exceptions; +using Core.Common.TestUtil; +using Core.Components.DotSpatial.Forms.IO; +using NUnit.Framework; + +namespace Core.Components.DotSpatial.Forms.Test.IO +{ + [TestFixture] + public class WmtsConnectionInfoWriterTest + { + private static readonly string testPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Forms, "WmtsConnectionInfo"); + + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void Constructor_NoFilePath_ThrowArgumentException(string filePath) + { + // Call + TestDelegate call = () => new WmtsConnectionInfoWriter(filePath); + + // Assert + const string expectedMessage = "bestandspad mag niet leeg of ongedefinieerd zijn."; + string message = Assert.Throws(call).Message; + StringAssert.Contains(expectedMessage, message); + } + + [Test] + public void Constructor_FilePathIsDirectory_ThrowArgumentException() + { + // Call + TestDelegate call = () => new WmtsConnectionInfoWriter("c:/"); + + // Assert + const string expectedMessage = "bestandspad mag niet verwijzen naar een lege bestandsnaam."; + string message = Assert.Throws(call).Message; + StringAssert.Contains(expectedMessage, message); + } + + [Test] + public void Constructor_FilePathHasInvalidPathCharacter_ThrowArgumentException() + { + // Setup + char[] invalidFileNameChars = Path.GetInvalidFileNameChars(); + string invalidCharacter = invalidFileNameChars[0].ToString(); + var filePath = "c:/_.config".Replace("_", invalidCharacter); + + // Call + TestDelegate call = () => new WmtsConnectionInfoWriter(filePath); + + // Assert + const string expectedMessage = "Fout bij het lezen van bestand 'c:/\".config': bestandspad " + + "mag niet de volgende tekens bevatten: \", <, >, " + + "|, \0, , , , , , , \a, \b, \t, \n, \v, \f, \r, " + + ", , , , , , , , , , , , , , , , , , :, *, ?, \\, /"; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] + public void WriteWmtsConnectionInfo_InvalidDirectoryRights_ThrowCriticalFileWriteException() + { + // Setup + string directoryPath = Path.Combine(testPath, "InvalidDirectoryRights"); + 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()); + + // Assert + string message = Assert.Throws(call).Message; + var expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'."; + Assert.AreEqual(expectedMessage, message); + } + } + finally + { + Directory.Delete(directoryPath, true); + } + } + + [Test] + public void WriteWmtsConnectionInfo_WmtsConnectionInfosNull_ThrowArgumentNullException() + { + // Setup + string filePath = Path.Combine(testPath, Path.GetRandomFileName()); + var wmtsConfigurationWriter = new WmtsConnectionInfoWriter(filePath); + + // Call + TestDelegate call = () => wmtsConfigurationWriter.WriteWmtsConnectionInfo(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("wmtsConnectionInfos", paramName); + } + + [Test] + public void WriteWmtsConnectionInfo_ValidWmtsConnectionInfo_SavesWmtsConnectionInfoToFile() + { + // Setup + string filePath = Path.Combine(testPath, Path.GetRandomFileName()); + 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 = "" + + "name1url1" + + "name2url2" + + ""; + Assert.AreEqual(expectedContent, actualContent); + } + } + + private static string GetFileContent(string filePath) + { + using (var reader = new StreamReader(filePath)) + { + return reader.ReadToEnd(); + } + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsCapabilityRowTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsCapabilityRowTest.cs (revision 0) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsCapabilityRowTest.cs (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -0,0 +1,62 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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 Core.Components.DotSpatial.Forms.Views; +using NUnit.Framework; + +namespace Core.Components.DotSpatial.Forms.Test.Views +{ + [TestFixture] + public class WmtsCapabilityRowTest + { + [Test] + public void Constructor_WmtsCapabilityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new WmtsCapabilityRow(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("wmtsCapability", paramName); + } + + [Test] + public void Constructor_ValidWmtsCapability_ExpectedProperties() + { + // Setup + const string id = "laag1(abc)"; + const string format = "image/png"; + const string title = "Eerste kaartlaag"; + const string coordinateSystem = "Coördinatenstelsel"; + var wmtsCapability = new WmtsCapability(id, format, title, coordinateSystem); + + // Call + var row = new WmtsCapabilityRow(wmtsCapability); + + // Assert + Assert.AreEqual(id, row.Id); + Assert.AreEqual(format, row.Format); + Assert.AreEqual(title, row.Title); + Assert.AreEqual(coordinateSystem, row.CoordinateSystem); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsCapabilityTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsCapabilityTest.cs (revision 0) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsCapabilityTest.cs (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -0,0 +1,184 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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 Core.Common.TestUtil; +using Core.Components.Gis.Data; +using NUnit.Framework; + +namespace Core.Components.DotSpatial.Forms.Test.Views +{ + public class WmtsCapabilityTest + { + [Test] + public void Constructor_IdNull_ThrowsArgumentNullException() + { + // Setup + const string format = "image/png"; + const string title = "Eerste kaartlaag"; + const string coordinateSystem = "Coördinatenstelsel"; + + // Call + TestDelegate call = () => new WmtsCapability(null, format, title, coordinateSystem); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("id", paramName); + } + + [Test] + public void Constructor_FormatNull_ThrowsArgumentNullException() + { + // Setup + const string id = "laag1(abc)"; + const string title = "Eerste kaartlaag"; + const string coordinateSystem = "Coördinatenstelsel"; + + // Call + TestDelegate call = () => new WmtsCapability(id, null, title, coordinateSystem); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("format", paramName); + } + + [Test] + public void Constructor_TitleNull_ThrowsArgumentNullException() + { + // Setup + const string id = "laag1(abc)"; + const string format = "image/png"; + const string coordinateSystem = "Coördinatenstelsel"; + + // Call + TestDelegate call = () => new WmtsCapability(id, format, null, coordinateSystem); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("title", paramName); + } + + [Test] + public void Constructor_CoordinateSystemNull_ThrowsArgumentNullException() + { + // Setup + const string id = "laag1(abc)"; + const string format = "image/png"; + const string title = "Eerste kaartlaag"; + + // Call + TestDelegate call = () => new WmtsCapability(id, format, title, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("coordinateSystem", paramName); + } + + [Test] + public void Constructor_FormatNotMIMEType_ThrowsArgumentException() + { + // Setup + const string id = "laag1(abc)"; + const string format = "some string"; + const string title = "Eerste kaartlaag"; + const string coordinateSystem = "Coördinatenstelsel"; + + // Call + TestDelegate call = () => new WmtsCapability(id, format, title, coordinateSystem); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Specified image format is not a MIME type."); + } + + [Test] + public void Constructor_ValidProperties_ExpectedProperties() + { + // Setup + const string id = "laag1(abc)"; + const string format = "image/png"; + const string title = "Eerste kaartlaag"; + const string coordinateSystem = "Coördinatenstelsel"; + + // Call + var wmtsCapability = new WmtsCapability(id, format, title, coordinateSystem); + + // Assert + Assert.AreEqual(id, wmtsCapability.Id); + Assert.AreEqual(format, wmtsCapability.Format); + Assert.AreEqual(title, wmtsCapability.Title); + Assert.AreEqual(coordinateSystem, wmtsCapability.CoordinateSystem); + } + + + [Test] + public void ToWmtsMapData_DisplayNameNull_ThrowsArgumentNullException() + { + // Setup + var wmtsCapability = new WmtsCapability("laag1(abc)", "image/png", "Eerste kaartlaag", "Coördinatenstelsel"); + const string sourceCapabilitiesUrl = "sourceCapabilitiesUrl"; + + // Call + TestDelegate call = () => wmtsCapability.ToWmtsMapdata(null, sourceCapabilitiesUrl); + + // Assert + Assert.Throws(call); + } + + [Test] + public void ToWmtsMapData_CapabilitiesUrlNull_ThrowsArgumentNullException() + { + // Setup + var wmtsCapability = new WmtsCapability("laag1(abc)", "image/png", "Eerste kaartlaag", "Coördinatenstelsel"); + const string displayName = "displayName"; + + // Call + TestDelegate call = () => wmtsCapability.ToWmtsMapdata(displayName, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sourceCapabilitiesUrl", paramName); + } + + [Test] + public void ToWmtsMapData_ValidParameters_ReturnsNewWmtsMapData() + { + // Setup + const string id = "laag1(abc)"; + const string format = "image/png"; + const string title = "Eerste kaartlaag"; + const string coordinateSystem = "Coördinatenstelsel"; + const string displayName = "displayName"; + const string sourceCapabilitiesUrl = "sourceCapabilitiesUrl"; + + var wmtsCapability = new WmtsCapability(id, format, title, coordinateSystem); + + // Call + WmtsMapData mapData = wmtsCapability.ToWmtsMapdata(displayName, sourceCapabilitiesUrl); + + // Assert + Assert.IsInstanceOf(mapData); + Assert.AreEqual(displayName, mapData.Name); + Assert.AreEqual(sourceCapabilitiesUrl, mapData.SourceCapabilitiesUrl); + } + + + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsConnectionDialogTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsConnectionDialogTest.cs (revision 0) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsConnectionDialogTest.cs (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -0,0 +1,335 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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.Threading; +using System.Windows.Forms; +using Core.Common.Controls.Dialogs; +using Core.Components.DotSpatial.Forms.Views; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Components.DotSpatial.Forms.Test.Views +{ + [TestFixture] + public class WmtsConnectionDialogTest : NUnitFormTest + { + [Test] + public void Constructor_WithoutDialogParent_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new WmtsConnectionDialog(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("dialogParent", paramName); + } + + [Test] + public void WmtsConnectionInfoConstructor_WithoutDialogParent_ThrowsArgumentNullException() + { + // Setup + var info = new WmtsConnectionInfo("name", "url"); + + // Call + TestDelegate test = () => new WmtsConnectionDialog(null, info); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("dialogParent", paramName); + } + + [Test] + public void WmtsConnectionInfoConstructor_WithoutWmtsConnectionInfo_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var dialogParent = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => new WmtsConnectionDialog(dialogParent, null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("wmtsConnectionInfo", paramName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_WithDialogParent_ExpectedProperties() + { + // Setup + var mocks = new MockRepository(); + var dialogParent = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + using (var dialog = new WmtsConnectionDialog(dialogParent)) + { + // Assert + Assert.IsInstanceOf(dialog); + Assert.IsNull(dialog.WmtsConnectionName); + Assert.IsNull(dialog.WmtsConnectionUrl); + + Assert.AreEqual("Nieuwe WMTS locatie toevoegen", dialog.Text); + + var nameLabel = new LabelTester("nameLabel", dialog); + Assert.AreEqual("Omschrijving", nameLabel.Text); + + var urlLabel = new LabelTester("urlLabel", dialog); + Assert.AreEqual("URL", urlLabel.Text); + + var actionButton = (Button) new ButtonTester("actionButton", dialog).TheObject; + Assert.AreEqual("Toevoegen", actionButton.Text); + Assert.IsFalse(actionButton.Enabled); + + var cancelButton = new ButtonTester("cancelButton", dialog); + Assert.AreEqual("Annuleren", cancelButton.Text); + + var nameTextBox = new TextBoxTester("nameTextBox", dialog); + Assert.IsEmpty(nameTextBox.Text); + + var urlTextBox = new TextBoxTester("urlTextBox", dialog); + Assert.IsEmpty(urlTextBox.Text); + } + + mocks.VerifyAll(); + } + + [Test] + public void WmtsConnectionInfoConstructor_WithDialogParent_ExpectedProperties() + { + // Setup + var mocks = new MockRepository(); + var dialogParent = mocks.StrictMock(); + mocks.ReplayAll(); + const string connectionName = @"name"; + const string connectionUrl = @"url"; + var info = new WmtsConnectionInfo(connectionName, connectionUrl); + + // Call + using (var dialog = new WmtsConnectionDialog(dialogParent, info)) + { + // Assert + Assert.IsInstanceOf(dialog); + Assert.IsNull(dialog.WmtsConnectionName); + Assert.IsNull(dialog.WmtsConnectionUrl); + + Assert.AreEqual("WMTS locatie aanpassen", dialog.Text); + + var nameLabel = new LabelTester("nameLabel", dialog); + Assert.AreEqual("Omschrijving", nameLabel.Text); + + var urlLabel = new LabelTester("urlLabel", dialog); + Assert.AreEqual("URL", urlLabel.Text); + + var actionButton = (Button) new ButtonTester("actionButton", dialog).TheObject; + Assert.AreEqual("Bewerken", actionButton.Text); + Assert.IsTrue(actionButton.Enabled); + + var cancelButton = new ButtonTester("cancelButton", dialog); + Assert.AreEqual("Annuleren", cancelButton.Text); + + var nameTextBox = new TextBoxTester("nameTextBox", dialog); + Assert.AreEqual(connectionName, nameTextBox.Text); + + var urlTextBox = new TextBoxTester("urlTextBox", dialog); + Assert.AreEqual(connectionUrl, urlTextBox.Text); + } + + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void ShowDialog_DefaultProperties() + { + // Setup + DialogBoxHandler = (name, wnd) => + { + using (new FormTester(name)) {} + }; + + using (var dialogParent = new Form()) + using (var dialog = new WmtsConnectionDialog(dialogParent)) + { + // Call + dialog.ShowDialog(); + + // Assert + Assert.AreEqual(250, dialog.MinimumSize.Width); + Assert.AreEqual(150, dialog.MinimumSize.Height); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void ActionButton_WithoutValidText_ButtonIsDisabled( + [Values("", " ", null)] string name, + [Values("", " ", null)] string url) + { + // Setup + DialogBoxHandler = (formName, wnd) => + { + using (new FormTester(formName)) {} + }; + + using (var dialogParent = new Form()) + using (var dialog = new WmtsConnectionDialog(dialogParent)) + { + dialog.ShowDialog(); + + var nameTextBox = (TextBox) new TextBoxTester("nameTextBox", dialog).TheObject; + var urlTextBox = (TextBox) new TextBoxTester("urlTextBox", dialog).TheObject; + var actionButton = (Button) new ButtonTester("actionButton", dialog).TheObject; + + // Call + nameTextBox.Text = name; + urlTextBox.Text = url; + + // Assert + Assert.IsFalse(actionButton.Enabled); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void ActionButton_WithValidText_ButtonIsEnabled() + { + // Setup + DialogBoxHandler = (formName, wnd) => + { + using (new FormTester(formName)) {} + }; + + using (var dialogParent = new Form()) + using (var dialog = new WmtsConnectionDialog(dialogParent)) + { + dialog.ShowDialog(); + + var nameTextBox = (TextBox) new TextBoxTester("nameTextBox", dialog).TheObject; + var urlTextBox = (TextBox) new TextBoxTester("urlTextBox", dialog).TheObject; + var actionButton = (Button) new ButtonTester("actionButton", dialog).TheObject; + + // Call + nameTextBox.Text = @"nameTextBox"; + urlTextBox.Text = @"urlTextBox"; + + // Assert + Assert.IsTrue(actionButton.Enabled); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void ActionButtonCick_WithValidText_SetsPropertiesAndClosesForm() + { + // Setup + const string urltextbox = @"urlTextBox"; + const string nametextbox = @"nameTextBox"; + var dialogResult = DialogResult.None; + + DialogBoxHandler = (formName, wnd) => + { + using (var formTester = new FormTester(formName)) + { + var nameTextBox = (TextBox) new TextBoxTester("nameTextBox", formName).TheObject; + var urlTextBox = (TextBox) new TextBoxTester("urlTextBox", formName).TheObject; + nameTextBox.Text = nametextbox; + urlTextBox.Text = urltextbox; + + var actionButton = new ButtonTester("actionButton", formName); + + // Call + actionButton.Click(); + + dialogResult = formTester.DialogResult; + } + }; + + using (var dialogParent = new Form()) + using (var dialog = new WmtsConnectionDialog(dialogParent)) + { + dialog.ShowDialog(); + + // Assert + Assert.AreEqual(nametextbox, dialog.WmtsConnectionName); + Assert.AreEqual(urltextbox, dialog.WmtsConnectionUrl); + Assert.AreEqual(DialogResult.OK, dialogResult); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenValidDialog_WhenCancelPressed_ThenWmtsConnectionDataNull() + { + // Given + Button cancelButton = null; + + DialogBoxHandler = (name, wnd) => + { + using (new FormTester(name)) + { + var button = new ButtonTester("cancelButton", name); + cancelButton = (Button) button.TheObject; + button.Click(); + } + }; + + using (var dialogParent = new Form()) + using (var dialog = new WmtsConnectionDialog(dialogParent)) + { + // When + dialog.ShowDialog(); + + // Then + Assert.IsNull(dialog.WmtsConnectionName); + Assert.IsNull(dialog.WmtsConnectionUrl); + + Assert.AreEqual(dialog.CancelButton, cancelButton); + } + } + + [Test] + public void Dispose_AlreadyDisposed_DoesNotThrowException() + { + // Setup + var mocks = new MockRepository(); + var dialogParent = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => + { + using (var control = new WmtsConnectionDialog(dialogParent)) + { + control.Dispose(); + } + }; + + // Assert + Assert.DoesNotThrow(call); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsLocationControlTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsLocationControlTest.cs (revision 0) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/Views/WmtsLocationControlTest.cs (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -0,0 +1,388 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.DataGrid; +using Core.Common.Controls.Views; +using Core.Components.DotSpatial.Forms.Views; +using NUnit.Extensions.Forms; +using NUnit.Framework; + +namespace Core.Components.DotSpatial.Forms.Test.Views +{ + [TestFixture] + public class WmtsLocationControlTest : NUnitFormTest + { + private const int mapLayerIdColumnIndex = 0; + private const int mapLayerFormatColumnIndex = 1; + private const int mapLayerTitleColumnIndex = 2; + private const int mapLayerCoordinateSystemColumnIndex = 3; + + [Test] + public void Constructor_DefaultValues() + { + // Call + using (var control = new WmtsLocationControl()) + { + // Assert + Assert.IsInstanceOf(control); + Assert.IsInstanceOf(control); + Assert.IsNull(control.Data); + } + } + + [Test] + public void Show_AddedToForm_DefaultProperties() + { + // Setup + using (var control = new WmtsLocationControl()) + using (var form = new Form()) + { + // Call + form.Controls.Add(control); + + // Assert + var urlLocationLabel = new LabelTester("urlLocationLabel", form); + Assert.AreEqual("Locatie (URL)", urlLocationLabel.Text); + + var urlLocations = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject; + Assert.AreEqual(ComboBoxStyle.DropDownList, urlLocations.DropDownStyle); + Assert.IsInstanceOf>(urlLocations.DataSource); + Assert.AreEqual("Name", urlLocations.DisplayMember); + Assert.AreEqual("Url", urlLocations.ValueMember); + Assert.IsTrue(urlLocations.Sorted); + + var buttonConnectTo = new ButtonTester("connectToButton", form); + Assert.AreEqual("Verbinding maken", buttonConnectTo.Text); + + var buttonAddLocation = new ButtonTester("addLocationButton", form); + Assert.AreEqual("Locatie toevoegen...", buttonAddLocation.Text); + + var buttonEditLocation = new ButtonTester("editLocationButton", form); + Assert.AreEqual("Locatie aanpassen...", buttonEditLocation.Text); + } + } + + [Test] + public void Constructor_DataGridViewCorrectlyInitialized() + { + // Call + using (var control = new WmtsLocationControl()) + using (var form = new Form()) + { + form.Controls.Add(control); + + // Assert + var dataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", form).TheObject; + var dataGridView = dataGridViewControl.Controls.OfType().First(); + + Assert.AreEqual(DataGridViewSelectionMode.FullRowSelect, dataGridView.SelectionMode); + Assert.IsFalse(dataGridView.MultiSelect); + Assert.AreEqual(4, dataGridView.ColumnCount); + + var mapLayerIdColumn = (DataGridViewTextBoxColumn) dataGridView.Columns[mapLayerIdColumnIndex]; + Assert.AreEqual("Kaartlaag", mapLayerIdColumn.HeaderText); + Assert.AreEqual("Id", mapLayerIdColumn.DataPropertyName); + Assert.IsTrue(mapLayerIdColumn.ReadOnly); + + var mapLayerFormatColumn = (DataGridViewTextBoxColumn) dataGridView.Columns[mapLayerFormatColumnIndex]; + Assert.AreEqual("Formaat", mapLayerFormatColumn.HeaderText); + Assert.AreEqual("Format", mapLayerFormatColumn.DataPropertyName); + Assert.IsTrue(mapLayerFormatColumn.ReadOnly); + + var mapLayerTitleColumn = (DataGridViewTextBoxColumn) dataGridView.Columns[mapLayerTitleColumnIndex]; + Assert.AreEqual("Titel", mapLayerTitleColumn.HeaderText); + Assert.AreEqual("Title", mapLayerTitleColumn.DataPropertyName); + Assert.IsTrue(mapLayerTitleColumn.ReadOnly); + + var mapLayerCoordinateSystemColumn = (DataGridViewTextBoxColumn) dataGridView.Columns[mapLayerCoordinateSystemColumnIndex]; + Assert.AreEqual("Coördinatenstelsel", mapLayerCoordinateSystemColumn.HeaderText); + Assert.AreEqual("CoordinateSystem", mapLayerCoordinateSystemColumn.DataPropertyName); + Assert.IsTrue(mapLayerCoordinateSystemColumn.ReadOnly); + } + } + + [Test] + public void Dispose_AlreadyDisposed_DoesNotThrowException() + { + // Call + TestDelegate call = () => + { + using (var control = new WmtsLocationControl()) + { + control.Dispose(); + } + }; + + // Assert + Assert.DoesNotThrow(call); + } + + [Test] + public void Data_WmtsCapabilityRow_DataSet() + { + // Setup + using (var view = new WmtsLocationControl()) + { + var capabilityRows = Enumerable.Empty(); + + // Call + view.Data = capabilityRows; + + // Assert + Assert.AreSame(capabilityRows, view.Data); + } + } + + [Test] + public void Data_OtherThanWmtsCapabilityRow_DataNull() + { + // Setup + using (var view = new WmtsLocationControl()) + { + var data = new object(); + + // Call + view.Data = data; + + // Assert + Assert.IsNull(view.Data); + } + } + + [Test] + public void WmtsLocationControl_WithData_DataGridViewCorrectlyInitialized() + { + // Setup & Call + using (Form form = ShowFullyConfiguredWmtsLocationControl()) + { + // Assert + var dataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", form).TheObject; + var rows = dataGridViewControl.Rows; + Assert.AreEqual(2, rows.Count); + + var cells = rows[0].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual("-", cells[mapLayerIdColumnIndex].FormattedValue); + Assert.AreEqual("image/png", cells[mapLayerFormatColumnIndex].FormattedValue); + Assert.AreEqual("-", cells[mapLayerTitleColumnIndex].FormattedValue); + Assert.AreEqual("-", cells[mapLayerCoordinateSystemColumnIndex].FormattedValue); + + cells = rows[1].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual("brtachtergrondkaart(EPSG:28992)", cells[mapLayerIdColumnIndex].FormattedValue); + Assert.AreEqual("image/png8", cells[mapLayerFormatColumnIndex].FormattedValue); + Assert.AreEqual("brtachtergrondkaart", cells[mapLayerTitleColumnIndex].FormattedValue); + Assert.AreEqual("EPSG:28992", cells[mapLayerCoordinateSystemColumnIndex].FormattedValue); + } + } + + [Test] + public void GivenWmtsLocationControlAndAddLocationClicked_WhenDialogCanceled_ThenWmtsLocationsNotUpdated() + { + // Given + DialogBoxHandler = (formName, wnd) => + { + using (new FormTester(formName)) {} + }; + + using (var form = new Form()) + using (var control = new WmtsLocationControl()) + { + form.Controls.Add(control); + form.Show(); + + var buttonAddLocation = new ButtonTester("addLocationButton", form); + + // When + buttonAddLocation.Click(); + + // Then + var comboBox = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject; + var dataSource = (List) comboBox.DataSource; + Assert.AreEqual(0, dataSource.Count); + } + } + + [Test] + public void GivenWmtsLocationControlAndAddLocationClicked_WhenValidDataInDialog_ThenWmtsLocationsUpdated() + { + // Given + const string name = @"someName"; + const string url = @"someUrl"; + + 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(); + } + }; + + using (var form = new Form()) + using (var control = new WmtsLocationControl()) + { + form.Controls.Add(control); + form.Show(); + + var buttonAddLocation = new ButtonTester("addLocationButton", form); + + // When + buttonAddLocation.Click(); + + // Then + var comboBox = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject; + var dataSource = (List) comboBox.DataSource; + Assert.AreEqual(1, dataSource.Count); + var item = (WmtsConnectionInfo) comboBox.Items[0]; + Assert.AreEqual(name, item.Name); + Assert.AreEqual(url, item.Url); + } + } + + [Test] + public void GivenWmtsLocationControlAndEditLocationClicked_WhenDialogCanceled_ThenWmtsLocationsNotUpdated() + { + // Given + DialogBoxHandler = (formName, wnd) => + { + using (new FormTester(formName)) {} + }; + + using (var form = new Form()) + using (var control = new WmtsLocationControl()) + { + form.Controls.Add(control); + form.Show(); + + var comboBox = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject; + comboBox.DataSource = new List + { + new WmtsConnectionInfo("oldName", "oldUrl") + }; + + var buttonAddLocation = new ButtonTester("editLocationButton", form); + + // When + buttonAddLocation.Click(); + + // Then + var dataSource = (List) comboBox.DataSource; + Assert.AreEqual(1, dataSource.Count); + var item = (WmtsConnectionInfo) comboBox.Items[0]; + Assert.AreEqual("oldName", item.Name); + Assert.AreEqual("oldUrl", item.Url); + } + } + + [Test] + public void GivenWmtsLocationControlAndEditLocationClicked_WhenValidDataInDialog_ThenWmtsLocationsUpdated() + { + // Given + const string newName = @"newName"; + const string newUrl = @"newUrl"; + + 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 = newName; + urlTextBox.Text = newUrl; + + actionButton.Click(); + } + }; + + using (var form = new Form()) + using (var control = new WmtsLocationControl()) + { + form.Controls.Add(control); + form.Show(); + + var comboBox = (ComboBox) new ComboBoxTester("urlLocationComboBox", form).TheObject; + comboBox.DataSource = new List + { + new WmtsConnectionInfo("oldName", "oldUrl") + }; + + var buttonAddLocation = new ButtonTester("editLocationButton", form); + + // When + buttonAddLocation.Click(); + + // Then + var dataSource = (List) comboBox.DataSource; + Assert.AreEqual(1, dataSource.Count); + var item = (WmtsConnectionInfo) comboBox.Items[0]; + Assert.AreEqual(newName, item.Name); + Assert.AreEqual(newUrl, item.Url); + } + } + + [Test] + public void Dispose_DisposedAlreadyCalled_DoesNotThrowException() + { + // Call + TestDelegate call = () => + { + using (var control = new WmtsLocationControl()) + { + control.Dispose(); + } + }; + + // Assert + Assert.DoesNotThrow(call); + } + + private static Form ShowFullyConfiguredWmtsLocationControl() + { + var form = new Form(); + var control = new WmtsLocationControl(); + + var capabilities = new List + { + new WmtsCapabilityRow(new WmtsCapability("-", "image/png", "-", "-")), + new WmtsCapabilityRow(new WmtsCapability("brtachtergrondkaart(EPSG:28992)", "image/png8", "brtachtergrondkaart", "EPSG:28992")) + }; + + control.Data = capabilities; + + form.Controls.Add(control); + return form; + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r7c3122d2253a734d538d9a58b46c6c55ce7989bf -rcfb8cddfe064c4aa4a1843846968554c918ba58f --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 7c3122d2253a734d538d9a58b46c6c55ce7989bf) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -678,68 +678,5 @@ return ResourceManager.GetString("WaveHeightLocationsContext_DisplayName", resourceCulture); } } - - /// - /// Looks up a localized string similar to Coördinatenstelsel. - /// - public static string WmtsCapability_MapLayer_CoordinateSystem { - get { - return ResourceManager.GetString("WmtsCapability_MapLayer_CoordinateSystem", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Formaat. - /// - public static string WmtsCapability_MapLayer_Format { - get { - return ResourceManager.GetString("WmtsCapability_MapLayer_Format", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Kaartlaag. - /// - public static string WmtsCapability_MapLayer_Id { - get { - return ResourceManager.GetString("WmtsCapability_MapLayer_Id", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Titel. - /// - public static string WmtsCapability_MapLayer_Title { - get { - return ResourceManager.GetString("WmtsCapability_MapLayer_Title", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Bewerken. - /// - public static string WmtsConnectionDialog_ActionButton_Edit { - get { - return ResourceManager.GetString("WmtsConnectionDialog_ActionButton_Edit", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to WMTS locatie aanpassen. - /// - public static string WmtsConnectionDialog_Text_Edit { - get { - return ResourceManager.GetString("WmtsConnectionDialog_Text_Edit", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Het is niet mogelijk om WMTS connectie {0} aan te maken met URL '{1}'.. - /// - public static string WmtsConnectionInfoReader_Unable_To_Create_WmtsConnectionInfo { - get { - return ResourceManager.GetString("WmtsConnectionInfoReader_Unable_To_Create_WmtsConnectionInfo", resourceCulture); - } - } } } Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx =================================================================== diff -u -r7c3122d2253a734d538d9a58b46c6c55ce7989bf -rcfb8cddfe064c4aa4a1843846968554c918ba58f --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx (.../Resources.resx) (revision 7c3122d2253a734d538d9a58b46c6c55ce7989bf) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx (.../Resources.resx) (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -315,25 +315,4 @@ URL - - Kaartlaag - - - Formaat - - - Titel - - - Coördinatenstelsel - - - Het is niet mogelijk om WMTS connectie {0} aan te maken met URL '{1}'. - - - Bewerken - - - WMTS locatie aanpassen - \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj =================================================================== diff -u -r1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c -rcfb8cddfe064c4aa4a1843846968554c918ba58f --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -38,11 +38,8 @@ - - - @@ -153,24 +150,6 @@ WaveHeightLocationsView.cs - - - Form - - - WmtsConnectionDialog.cs - - - UserControl - - - WmtsLocationControl.cs - - - - - - @@ -284,12 +263,6 @@ WaveHeightLocationsView.cs Designer - - WmtsConnectionDialog.cs - - - WmtsLocationControl.cs - Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsCapability.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsCapabilityRow.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsConnectionDialog.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsConnectionDialog.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsConnectionDialog.resx'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsLocationControl.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsLocationControl.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WmtsLocationControl.resx'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/WmtsConnectionInfo.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/WmtsConnectionInfoReader.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/WmtsConnectionInfoWriter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/WmtsConnectionInfoXmlDefinitions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/app.config =================================================================== diff -u -r7cc1fd960a912443ccc3c6995eccb5673d1d8d22 -rcfb8cddfe064c4aa4a1843846968554c918ba58f --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/app.config (.../app.config) (revision 7cc1fd960a912443ccc3c6995eccb5673d1d8d22) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/app.config (.../app.config) (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -1,4 +1,26 @@  + Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj =================================================================== diff -u -r1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c -rcfb8cddfe064c4aa4a1843846968554c918ba58f --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 1fb54b1f8b8be7500a290f3cc8c3aaf46aa0b24c) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision cfb8cddfe064c4aa4a1843846968554c918ba58f) @@ -59,7 +59,6 @@ - @@ -117,13 +116,6 @@ - - - - - - - @@ -138,10 +130,6 @@ {30e4c2ae-719e-4d70-9fa9-668a9767fbfa} Core.Common.Gui - - {E344867E-9AC9-44C8-88A5-8185681679A9} - Core.Common.IO - {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} Core.Common.Utils @@ -166,10 +154,6 @@ {9b6f3987-eaf7-4733-80c1-3dcab44d87ae} Core.Components.DotSpatial.TestUtil - - {d24fa2f7-28a7-413b-afd3-ee10e985630b} - Ringtoets.Common.Forms.TestUtil - {BF753DB5-973B-4ADF-B0F6-9437325C3466} Ringtoets.GrassCoverErosionInwards.Data.TestUtil Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WmtsCapabilityRowTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WmtsCapabilityTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WmtsConnectionDialogTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WmtsLocationControlTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/WmtsConnectionInfoReaderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/WmtsConnectionInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag cfb8cddfe064c4aa4a1843846968554c918ba58f refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/WmtsConnectionInfoWriterTest.cs'. Fisheye: No comparison available. Pass `N' to diff?