Browse Source

Throw an exception if FontWeight <= 0

In FormattedText. Fixes #700.
pull/744/head
Steven Kirk 10 years ago
parent
commit
f15a136e00
  1. 11
      src/Avalonia.SceneGraph/Media/FormattedText.cs
  2. 28
      tests/Avalonia.SceneGraph.UnitTests/Media/FormattedTextTests.cs

11
src/Avalonia.SceneGraph/Media/FormattedText.cs

@ -33,7 +33,16 @@ namespace Avalonia.Media
{
Contract.Requires<ArgumentNullException>(text != null);
Contract.Requires<ArgumentNullException>(fontFamilyName != null);
Contract.Requires<ArgumentException>(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;

28
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<ArgumentException>(() => new FormattedText(
"foo",
"Ariel",
0));
}
[Fact]
public void Exception_Should_Be_Thrown_If_FontWeight_0()
{
Assert.Throws<ArgumentException>(() => new FormattedText(
"foo",
"Ariel",
12,
fontWeight: 0));
}
}
}
Loading…
Cancel
Save