Browse Source

Merge pull request #744 from AvaloniaUI/fixes/700-fontweight-0

Throw an exception if FontWeight <= 0
pull/751/head
Steven Kirk 10 years ago
committed by GitHub
parent
commit
b8e78742a7
  1. 11
      src/Avalonia.SceneGraph/Media/FormattedText.cs
  2. 1
      tests/Avalonia.SceneGraph.UnitTests/Avalonia.SceneGraph.UnitTests.csproj
  3. 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;

1
tests/Avalonia.SceneGraph.UnitTests/Avalonia.SceneGraph.UnitTests.csproj

@ -77,6 +77,7 @@
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="Media\FormattedTextTests.cs" />
<Compile Include="Media\PathMarkupParserTests.cs" />
<Compile Include="RelativeRectComparer.cs" />
<Compile Include="RelativeRectTests.cs" />

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