From f15a136e00cbd741cf92f9d9a3cd239151d66b1a Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 17 Sep 2016 20:46:48 +0200 Subject: [PATCH 1/2] Throw an exception if FontWeight <= 0 In FormattedText. Fixes #700. --- .../Media/FormattedText.cs | 11 +++++++- .../Media/FormattedTextTests.cs | 28 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/Avalonia.SceneGraph.UnitTests/Media/FormattedTextTests.cs diff --git a/src/Avalonia.SceneGraph/Media/FormattedText.cs b/src/Avalonia.SceneGraph/Media/FormattedText.cs index 1169a56343..f6aeaf5f5f 100644 --- a/src/Avalonia.SceneGraph/Media/FormattedText.cs +++ b/src/Avalonia.SceneGraph/Media/FormattedText.cs @@ -33,7 +33,16 @@ namespace Avalonia.Media { Contract.Requires(text != null); Contract.Requires(fontFamilyName != null); - Contract.Requires(fontSize > 0); + + if (fontSize <= 0) + { + throw new ArgumentException("FontSize must be greater than 0"); + } + + if (fontWeight <= 0) + { + throw new ArgumentException("FontWeight must be greater than 0"); + } Text = text; FontFamilyName = fontFamilyName; diff --git a/tests/Avalonia.SceneGraph.UnitTests/Media/FormattedTextTests.cs b/tests/Avalonia.SceneGraph.UnitTests/Media/FormattedTextTests.cs new file mode 100644 index 0000000000..d36e23a6d8 --- /dev/null +++ b/tests/Avalonia.SceneGraph.UnitTests/Media/FormattedTextTests.cs @@ -0,0 +1,28 @@ +using System; +using Avalonia.Media; +using Xunit; + +namespace Avalonia.SceneGraph.UnitTests.Media +{ + public class FormattedTextTests + { + [Fact] + public void Exception_Should_Be_Thrown_If_FontSize_0() + { + Assert.Throws(() => new FormattedText( + "foo", + "Ariel", + 0)); + } + + [Fact] + public void Exception_Should_Be_Thrown_If_FontWeight_0() + { + Assert.Throws(() => new FormattedText( + "foo", + "Ariel", + 12, + fontWeight: 0)); + } + } +} From b2141da4308e7508bfa66bc3de3325b77f4ef27a Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 17 Sep 2016 20:54:10 +0200 Subject: [PATCH 2/2] Forgot to save .csproj. --- .../Avalonia.SceneGraph.UnitTests.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Avalonia.SceneGraph.UnitTests/Avalonia.SceneGraph.UnitTests.csproj b/tests/Avalonia.SceneGraph.UnitTests/Avalonia.SceneGraph.UnitTests.csproj index 34f12d16ed..9d6f861ddf 100644 --- a/tests/Avalonia.SceneGraph.UnitTests/Avalonia.SceneGraph.UnitTests.csproj +++ b/tests/Avalonia.SceneGraph.UnitTests/Avalonia.SceneGraph.UnitTests.csproj @@ -77,6 +77,7 @@ +