Index: Core/Components/src/Core.Components.PointedTree/Core.Components.PointedTree.csproj
===================================================================
diff -u -reb0b935ed63fa3d09a438c897044f95e645c95b9 -r40514f2e47eded8cd37dad8d7e17829e77565d92
--- Core/Components/src/Core.Components.PointedTree/Core.Components.PointedTree.csproj (.../Core.Components.PointedTree.csproj) (revision eb0b935ed63fa3d09a438c897044f95e645c95b9)
+++ Core/Components/src/Core.Components.PointedTree/Core.Components.PointedTree.csproj (.../Core.Components.PointedTree.csproj) (revision 40514f2e47eded8cd37dad8d7e17829e77565d92)
@@ -37,6 +37,8 @@
+
+
Index: Core/Components/src/Core.Components.PointedTree/Data/GraphNode.cs
===================================================================
diff -u -r3e86aa56a8e99291f35ffe7b88df33e90d6d68c9 -r40514f2e47eded8cd37dad8d7e17829e77565d92
--- Core/Components/src/Core.Components.PointedTree/Data/GraphNode.cs (.../GraphNode.cs) (revision 3e86aa56a8e99291f35ffe7b88df33e90d6d68c9)
+++ Core/Components/src/Core.Components.PointedTree/Data/GraphNode.cs (.../GraphNode.cs) (revision 40514f2e47eded8cd37dad8d7e17829e77565d92)
@@ -22,6 +22,11 @@
using System;
using System.Collections.Generic;
using System.Drawing;
+using System.IO;
+using System.Xml;
+using System.Xml.Linq;
+using System.Xml.Schema;
+using Core.Components.PointedTree.Properties;
namespace Core.Components.PointedTree.Data
{
@@ -40,8 +45,14 @@
/// Indicator whether the node is selectable.
/// Thrown when
/// or is null.
+ /// Thrown when the content is not valid.
+ /// Content should have the following format: <text>Content</text>.
+ /// The following tags are supported as content:
+ ///
+ /// - <bold></bold>
+ ///
public GraphNode(string content, GraphNode[] childNodes, bool isSelectable)
- : this(content, childNodes, isSelectable, CreateDefaultGraphNodeStyle()) { }
+ : this(content, childNodes, isSelectable, CreateDefaultGraphNodeStyle()) {}
///
/// Creates a new instance of .
@@ -52,6 +63,12 @@
/// The style of the node.
/// Thrown when ,
/// or is null.
+ /// Thrown when the content is not valid.
+ /// Content should have the following format: <text>Content</text>.
+ /// The following tags are supported as content:
+ ///
+ /// - <bold></bold>
+ ///
public GraphNode(string content, GraphNode[] childNodes, bool isSelectable, GraphNodeStyle style)
{
if (content == null)
@@ -67,6 +84,8 @@
throw new ArgumentNullException(nameof(style));
}
+ ValidateContent(content);
+
Content = content;
this.childNodes = childNodes;
IsSelectable = isSelectable;
@@ -99,6 +118,29 @@
///
public GraphNodeStyle Style { get; }
+ ///
+ /// Validates whether the content is valid XML.
+ ///
+ /// The content to validate.
+ /// Thrown when the
+ /// content is not valid.
+ private static void ValidateContent(string content)
+ {
+ var xmlSchemaSet = new XmlSchemaSet();
+ xmlSchemaSet.Add(XmlSchema.Read(new StringReader(Resources.GraphNodeContentSchema), null));
+ xmlSchemaSet.Compile();
+
+ try
+ {
+ XDocument doc = XDocument.Parse(content);
+ doc.Validate(xmlSchemaSet, null);
+ }
+ catch (Exception e) when (e is XmlException || e is XmlSchemaValidationException)
+ {
+ throw new ArgumentException(Resources.GraphNode_ValidateContent_Content_not_valid, e);
+ }
+ }
+
private static GraphNodeStyle CreateDefaultGraphNodeStyle()
{
return new GraphNodeStyle(GraphNodeShape.Rectangle, Color.Gray, Color.Black, 2);
Index: Core/Components/src/Core.Components.PointedTree/Properties/Resources.Designer.cs
===================================================================
diff -u -reb0b935ed63fa3d09a438c897044f95e645c95b9 -r40514f2e47eded8cd37dad8d7e17829e77565d92
--- Core/Components/src/Core.Components.PointedTree/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision eb0b935ed63fa3d09a438c897044f95e645c95b9)
+++ Core/Components/src/Core.Components.PointedTree/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 40514f2e47eded8cd37dad8d7e17829e77565d92)
@@ -82,11 +82,28 @@
}
///
- /// Looks up a localized string similar to <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
- /// <xs:element name="text>
+ /// Looks up a localized string similar to De content voor deze node is niet geldig..
+ ///
+ internal static string GraphNode_ValidateContent_Content_not_valid {
+ get {
+ return ResourceManager.GetString("GraphNode_ValidateContent_Content_not_valid", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to <!--
+ ///Copyright (C) Stichting Deltares 2017. All rights reserved.
///
- /// </xs:element>
- ///</xs:schema>.
+ ///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 FO [rest of string was truncated]";.
///
internal static string GraphNodeContentSchema {
get {
Index: Core/Components/src/Core.Components.PointedTree/Properties/Resources.resx
===================================================================
diff -u -reb0b935ed63fa3d09a438c897044f95e645c95b9 -r40514f2e47eded8cd37dad8d7e17829e77565d92
--- Core/Components/src/Core.Components.PointedTree/Properties/Resources.resx (.../Resources.resx) (revision eb0b935ed63fa3d09a438c897044f95e645c95b9)
+++ Core/Components/src/Core.Components.PointedTree/Properties/Resources.resx (.../Resources.resx) (revision 40514f2e47eded8cd37dad8d7e17829e77565d92)
@@ -121,4 +121,7 @@
..\Resources\GraphNodeContentSchema.xsd;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
+
+ De content voor deze node is niet geldig.
+
\ No newline at end of file
Index: Core/Components/test/Core.Components.GraphSharp.Forms.Test/PointedTreeGraphControlTest.cs
===================================================================
diff -u -r1fb18822ebf5a2e3dae6eb2dc3c4687e4d1d0e62 -r40514f2e47eded8cd37dad8d7e17829e77565d92
--- Core/Components/test/Core.Components.GraphSharp.Forms.Test/PointedTreeGraphControlTest.cs (.../PointedTreeGraphControlTest.cs) (revision 1fb18822ebf5a2e3dae6eb2dc3c4687e4d1d0e62)
+++ Core/Components/test/Core.Components.GraphSharp.Forms.Test/PointedTreeGraphControlTest.cs (.../PointedTreeGraphControlTest.cs) (revision 40514f2e47eded8cd37dad8d7e17829e77565d92)
@@ -69,14 +69,14 @@
// Given
using (var graphControl = new PointedTreeGraphControl())
{
- var doubleUsedNode = new GraphNode("Double used", new GraphNode[0], false);
- var node = new GraphNode("Root", new[]
+ var doubleUsedNode = new GraphNode("Double used", new GraphNode[0], false);
+ var node = new GraphNode("Root", new[]
{
- new GraphNode("Child 1", new[]
+ new GraphNode("Child 1", new[]
{
doubleUsedNode
}, false),
- new GraphNode("Child 2", new[]
+ new GraphNode("Child 2", new[]
{
doubleUsedNode
}, false)
@@ -100,9 +100,9 @@
public void GivenGraphControlWithData_WhenDataSetToOtherGraphNode_ThenGraphControlUpdated()
{
// Given
- var node = new GraphNode("Root", new[]
+ var node = new GraphNode("Root", new[]
{
- new GraphNode("Child 1", new GraphNode[0], false)
+ new GraphNode("Child 1", new GraphNode[0], false)
}, false);
using (var graphControl = new PointedTreeGraphControl
@@ -120,7 +120,7 @@
Assert.AreEqual(1, graph.EdgeCount);
// When
- graphControl.Data = new GraphNode("Double used", new GraphNode[0], false);
+ graphControl.Data = new GraphNode("Double used", new GraphNode[0], false);
// Then
Assert.AreEqual(1, graph.VertexCount);
@@ -132,9 +132,9 @@
public void GivenGraphControlWithData_WhenDataSetToNull_ThenGraphControlUpdated()
{
// Given
- var node = new GraphNode("Root", new[]
+ var node = new GraphNode("Root", new[]
{
- new GraphNode("Child 1", new GraphNode[0], false)
+ new GraphNode("Child 1", new GraphNode[0], false)
}, false);
using (var graphControl = new PointedTreeGraphControl
Index: Core/Components/test/Core.Components.GraphSharp.Test/Converters/GraphNodeConverterTest.cs
===================================================================
diff -u -r1fb18822ebf5a2e3dae6eb2dc3c4687e4d1d0e62 -r40514f2e47eded8cd37dad8d7e17829e77565d92
--- Core/Components/test/Core.Components.GraphSharp.Test/Converters/GraphNodeConverterTest.cs (.../GraphNodeConverterTest.cs) (revision 1fb18822ebf5a2e3dae6eb2dc3c4687e4d1d0e62)
+++ Core/Components/test/Core.Components.GraphSharp.Test/Converters/GraphNodeConverterTest.cs (.../GraphNodeConverterTest.cs) (revision 40514f2e47eded8cd37dad8d7e17829e77565d92)
@@ -50,7 +50,7 @@
public void Convert_InvalidShapeType_ThrowsInvalidEnumArgumentException()
{
// Setup
- var graphNode = new GraphNode("test", new GraphNode[0], false,
+ var graphNode = new GraphNode("test", new GraphNode[0], false,
new GraphNodeStyle((GraphNodeShape) 99, Color.AliceBlue,
Color.AntiqueWhite, 2));
@@ -69,7 +69,7 @@
PointedTreeVertexType expectedVertexType)
{
// Setup
- const string content = "Node";
+ const string content = "Node";
const bool isSelectable = false;
const int lineWidth = 3;
Color fillColor = Color.Aquamarine;
Index: Core/Components/test/Core.Components.PointedTree.Test/Core.Components.PointedTree.Test.csproj
===================================================================
diff -u -r2a9569e9a7d82f4f1627fc6eaafd9bda61ac0feb -r40514f2e47eded8cd37dad8d7e17829e77565d92
--- Core/Components/test/Core.Components.PointedTree.Test/Core.Components.PointedTree.Test.csproj (.../Core.Components.PointedTree.Test.csproj) (revision 2a9569e9a7d82f4f1627fc6eaafd9bda61ac0feb)
+++ Core/Components/test/Core.Components.PointedTree.Test/Core.Components.PointedTree.Test.csproj (.../Core.Components.PointedTree.Test.csproj) (revision 40514f2e47eded8cd37dad8d7e17829e77565d92)
@@ -62,6 +62,10 @@
+
+ {D749EE4C-CE50-4C17-BF01-9A953028C126}
+ Core.Common.TestUtil
+
{ad3b1634-c435-4618-9971-2ea0817f5de2}
Core.Components.PointedTree
Index: Core/Components/test/Core.Components.PointedTree.Test/Data/GraphNodeTest.cs
===================================================================
diff -u -r3e86aa56a8e99291f35ffe7b88df33e90d6d68c9 -r40514f2e47eded8cd37dad8d7e17829e77565d92
--- Core/Components/test/Core.Components.PointedTree.Test/Data/GraphNodeTest.cs (.../GraphNodeTest.cs) (revision 3e86aa56a8e99291f35ffe7b88df33e90d6d68c9)
+++ Core/Components/test/Core.Components.PointedTree.Test/Data/GraphNodeTest.cs (.../GraphNodeTest.cs) (revision 40514f2e47eded8cd37dad8d7e17829e77565d92)
@@ -23,6 +23,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
+using Core.Common.TestUtil;
using Core.Components.PointedTree.Data;
using NUnit.Framework;
@@ -44,14 +45,14 @@
GraphNode[] childNodes =
{
- new GraphNode("node 1", new GraphNode[0], false, style),
- new GraphNode("node 2", new[]
+ new GraphNode("node 1", new GraphNode[0], false, style),
+ new GraphNode("node 2", new[]
{
- new GraphNode("node 3", new GraphNode[0], false, style)
+ new GraphNode("node 3", new GraphNode[0], false, style)
}, true, style)
};
- const string content = "test";
+ const string content = "test";
const bool isSelectable = false;
// Call
@@ -72,14 +73,14 @@
// Setup
GraphNode[] childNodes =
{
- new GraphNode("node 1", new GraphNode[0], false),
- new GraphNode("node 2", new[]
+ new GraphNode("node 1", new GraphNode[0], false),
+ new GraphNode("node 2", new[]
{
- new GraphNode("node 3", new GraphNode[0], true)
+ new GraphNode("node 3", new GraphNode[0], true)
}, true)
};
- const string content = "test";
+ const string content = "test";
const bool isSelectable = false;
// Call
@@ -112,7 +113,7 @@
public void Constructor_ChildNodesNull_ThrowsArgumentNullException()
{
// Call
- TestDelegate call = () => new GraphNode("test", null, false);
+ TestDelegate call = () => new GraphNode("test", null, false);
// Assert
var exception = Assert.Throws(call);
@@ -123,13 +124,26 @@
public void Constructor_StyleNull_ThrowsArgumentNullException()
{
// Call
- TestDelegate call = () => new GraphNode("test", new GraphNode[0], false, null);
+ TestDelegate call = () => new GraphNode("test", new GraphNode[0], false, null);
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("style", exception.ParamName);
}
+ [Test]
+ [TestCase("plain text")]
+ [TestCase("test")]
+ [TestCase("test italic")]
+ public void Constructor_InvalidContent_ThrowsArgumentException(string content)
+ {
+ // Call
+ TestDelegate call = () => new GraphNode(content, new GraphNode[0], false);
+
+ // Assert
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "De content voor deze node is niet geldig.");
+ }
+
private static void AssertChildNodes(IList childNodes, IList actualChildNodes)
{
Assert.AreEqual(childNodes.Count, actualChildNodes.Count);