10 changed files with 194 additions and 4 deletions
@ -0,0 +1 @@ |
|||
|
|||
@ -0,0 +1,75 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Avalonia.Media; |
|||
using Avalonia.Media.Fonts; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media |
|||
{ |
|||
public class FontFamilyTests |
|||
{ |
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_Name_Is_Null() |
|||
{ |
|||
Assert.Throws<ArgumentNullException>(() => new FontFamily((string)null)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_Names_Is_Null() |
|||
{ |
|||
Assert.Throws<ArgumentNullException>(() => new FontFamily((IEnumerable<string>)null)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Parse_Parses_FontFamily_With_Name() |
|||
{ |
|||
var fontFamily = FontFamily.Parse("Courier New"); |
|||
|
|||
Assert.Equal("Courier New", fontFamily.Name); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Parse_Parses_FontFamily_With_Names() |
|||
{ |
|||
var fontFamily = FontFamily.Parse("Courier New, Times New Roman"); |
|||
|
|||
Assert.Equal("Courier New", fontFamily.Name); |
|||
|
|||
Assert.Equal(2, fontFamily.FamilyNames.Count()); |
|||
|
|||
Assert.Equal("Times New Roman", fontFamily.FamilyNames.Last()); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Parse_Parses_FontFamily_With_Resource_Folder() |
|||
{ |
|||
var source = new Uri("resm:Avalonia.Visuals.UnitTests#MyFont"); |
|||
|
|||
var key = new FontFamilyKey(source); |
|||
|
|||
var fontFamily = FontFamily.Parse(source.OriginalString); |
|||
|
|||
Assert.Equal("MyFont", fontFamily.Name); |
|||
|
|||
Assert.Equal(key, fontFamily.Key); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Parse_Parses_FontFamily_With_Resource_Filename() |
|||
{ |
|||
var source = new Uri("resm:Avalonia.Visuals.UnitTests.MyFont.ttf#MyFont"); |
|||
|
|||
var key = new FontFamilyKey(source); |
|||
|
|||
var fontFamily = FontFamily.Parse(source.OriginalString); |
|||
|
|||
Assert.Equal("MyFont", fontFamily.Name); |
|||
|
|||
Assert.Equal(key, fontFamily.Key); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Linq; |
|||
using Avalonia.Media.Fonts; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media.Fonts |
|||
{ |
|||
public class FamilyNameCollectionTests |
|||
{ |
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_Names_Is_Null() |
|||
{ |
|||
Assert.Throws<ArgumentNullException>(() => new FamilyNameCollection(null)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_Names_Is_Empty() |
|||
{ |
|||
Assert.Throws<ArgumentException>(() => new FamilyNameCollection(Enumerable.Empty<string>())); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using Avalonia.Media; |
|||
using Avalonia.Media.Fonts; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media.Fonts |
|||
{ |
|||
public class FontFamilyKeyTests |
|||
{ |
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_Source_Is_Null() |
|||
{ |
|||
Assert.Throws<ArgumentNullException>(() => new FontFamilyKey(null)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Initialize_With_Location() |
|||
{ |
|||
var source = new Uri("resm:Avalonia.Visuals.UnitTests#MyFont"); |
|||
|
|||
var fontFamilyKey = new FontFamilyKey(source); |
|||
|
|||
Assert.Equal(new Uri("resm:Avalonia.Visuals.UnitTests"), fontFamilyKey.Location); |
|||
|
|||
Assert.Null(fontFamilyKey.FileName); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Initialize_With_Location_And_Filename() |
|||
{ |
|||
var source = new Uri("resm:Avalonia.Visuals.UnitTests.MyFont.ttf#MyFont"); |
|||
|
|||
var fontFamilyKey = new FontFamilyKey(source); |
|||
|
|||
Assert.Equal(new Uri("resm:Avalonia.Visuals.UnitTests"), fontFamilyKey.Location); |
|||
|
|||
Assert.Equal("MyFont.ttf", fontFamilyKey.FileName); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Linq; |
|||
using Avalonia.Media.Fonts; |
|||
using Avalonia.UnitTests; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media.Fonts |
|||
{ |
|||
public class FontFamilyLoaderTests |
|||
{ |
|||
[Fact] |
|||
public void Should_Load_Single_FontResource() |
|||
{ |
|||
const string resourcePath = "resm:Avalonia.Visuals.UnitTests.Assets.MyFont.ttf?assembly=Avalonia.Visuals.UnitTests#MyFont"; |
|||
|
|||
using (StartWithResources((resourcePath, "MyFont.ttf"))) |
|||
{ |
|||
var source = new Uri(resourcePath, UriKind.RelativeOrAbsolute); |
|||
|
|||
var key = new FontFamilyKey(source); |
|||
|
|||
var resources = FontFamilyLoader.LoadFontResources(key); |
|||
|
|||
Assert.Single(resources); |
|||
} |
|||
} |
|||
|
|||
private static IDisposable StartWithResources(params (string, string)[] assets) |
|||
{ |
|||
var assetLoader = new MockAssetLoader(assets); |
|||
var services = new TestServices(assetLoader: assetLoader, platform: new AppBuilder().RuntimePlatform); |
|||
return UnitTestApplication.Start(services); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue