Browse Source

Warning fixes: '25 winter wave (#18103)

* Use TryGetValue in UnicodeEnumsGenerator

* Suppress incorrect CA2256 in Win32.Automation

* Fix xUnit analyzer warnings

* Misc warning fixes

* Ignore some obsolete warnings
pull/18251/head
Julien Lebosquain 12 months ago
committed by GitHub
parent
commit
5824d9b079
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 21
      samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext.csproj
  2. 60
      samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/UnloadableAssemblyLoadContextPlug.csproj
  3. 4
      samples/XEmbedSample/HarfbuzzWorkaround.cs
  4. 13
      samples/XEmbedSample/Program.cs
  5. 6
      samples/XEmbedSample/SocketEx.cs
  6. 24
      src/Avalonia.Base/Media/TextFormatting/Unicode/PropertyValueAliasHelper.cs
  7. 2
      src/Avalonia.Controls/TextBox.cs
  8. 4
      src/Headless/Avalonia.Headless/HeadlessPlatformStubs.cs
  9. 11
      src/Windows/Avalonia.Win32.Automation/GlobalSuppressions.cs
  10. 12
      tests/Avalonia.Base.UnitTests/Animation/AnimationIterationTests.cs
  11. 2
      tests/Avalonia.Base.UnitTests/Collections/AvaloniaListTests.cs
  12. 2
      tests/Avalonia.Base.UnitTests/DispatcherTests.cs
  13. 4
      tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiClassTests.cs
  14. 8
      tests/Avalonia.Base.UnitTests/Media/TextFormatting/UnicodeEnumsGenerator.cs
  15. 2
      tests/Avalonia.Base.UnitTests/Utilities/StringTokenizerTests.cs
  16. 2
      tests/Avalonia.Build.Tasks.UnitTest/CompileAvaloniaXamlTaskTest.cs
  17. 3
      tests/Avalonia.Controls.DataGrid.UnitTests/Collections/ComparerTests.cs
  18. 2
      tests/Avalonia.Controls.UnitTests/GridLengthTests.cs
  19. 6
      tests/Avalonia.Controls.UnitTests/MaskedTextBoxTests.cs
  20. 4
      tests/Avalonia.Controls.UnitTests/Platform/ScreensTests.cs
  21. 42
      tests/Avalonia.Controls.UnitTests/TextBoxTests.cs
  22. 2
      tests/Avalonia.Controls.UnitTests/WindowTests.cs
  23. 2
      tests/Avalonia.DesignerSupport.Tests/RemoteProtocolTests.cs
  24. 6
      tests/Avalonia.Generators.Tests/XamlXNameResolverTests.cs
  25. 4
      tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs
  26. 4
      tests/Avalonia.RenderTests/TestBase.cs
  27. 2
      tests/Avalonia.RenderTests/TestRenderHelper.cs
  28. 8
      tests/Avalonia.Skia.UnitTests/Media/EmbeddedFontCollectionTests.cs
  29. 8
      tests/Avalonia.Skia.UnitTests/Media/FontCollectionTests.cs

21
samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContext.csproj

@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <OutputType>WinExe</OutputType>
<Nullable>enable</Nullable> <TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport> <Nullable>enable</Nullable>
<ApplicationManifest>app.manifest</ApplicationManifest> <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault> <ApplicationManifest>app.manifest</ApplicationManifest>
<IncludeAvaloniaGenerators>true</IncludeAvaloniaGenerators> <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup> <IncludeAvaloniaGenerators>true</IncludeAvaloniaGenerators>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" /> <Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" />
@ -18,6 +19,7 @@
<Import Project="..\..\..\build\BuildTargets.targets" Condition="Exists('..\..\..\build\BuildTargets.targets')" /> <Import Project="..\..\..\build\BuildTargets.targets" Condition="Exists('..\..\..\build\BuildTargets.targets')" />
<Import Project="..\..\..\build\SourceGenerators.props" /> <Import Project="..\..\..\build\SourceGenerators.props" />
</ImportGroup> </ImportGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\packages\Avalonia\Avalonia.csproj" /> <ProjectReference Include="..\..\..\packages\Avalonia\Avalonia.csproj" />
<ProjectReference Include="..\..\..\src\Avalonia.Base\Avalonia.Base.csproj" /> <ProjectReference Include="..\..\..\src\Avalonia.Base\Avalonia.Base.csproj" />
@ -26,4 +28,5 @@
<ProjectReference Include="..\..\..\src\Avalonia.Fonts.Inter\Avalonia.Fonts.Inter.csproj" /> <ProjectReference Include="..\..\..\src\Avalonia.Fonts.Inter\Avalonia.Fonts.Inter.csproj" />
<ProjectReference Include="..\..\..\src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj" /> <ProjectReference Include="..\..\..\src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

60
samples/UnloadableAssemblyLoadContext/UnloadableAssemblyLoadContextPlug/UnloadableAssemblyLoadContextPlug.csproj

@ -1,17 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<AssemblyName>UnloadableAssemblyLoadContextPlug</AssemblyName>
<RootNamespace>UnloadableAssemblyLoadContextPlug</RootNamespace>
</PropertyGroup>
<ItemGroup> <PropertyGroup>
<AvaloniaResource Include="Assets\**"/> <TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
</ItemGroup> <Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<AssemblyName>UnloadableAssemblyLoadContextPlug</AssemblyName>
<RootNamespace>UnloadableAssemblyLoadContextPlug</RootNamespace>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**"/>
</ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="**\*.xaml.cs"> <Compile Update="**\*.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon> <DependentUpon>%(Filename)</DependentUpon>
@ -19,33 +21,27 @@
<AvaloniaResource Include="**\*.xaml"> <AvaloniaResource Include="**\*.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</AvaloniaResource> </AvaloniaResource>
<AvaloniaResource Include="Assets\*" /> <AvaloniaResource Include="Assets\*"/>
<AvaloniaResource Include="Assets\Fonts\*" /> <AvaloniaResource Include="Assets\Fonts\*"/>
</ItemGroup> </ItemGroup>
<ImportGroup> <ImportGroup>
<Import Project="..\..\..\build\BuildTargets.targets" Condition="Exists('..\..\..\build\BuildTargets.targets')" /> <Import Project="..\..\..\build\BuildTargets.targets" Condition="Exists('..\..\..\build\BuildTargets.targets')"/>
<Import Project="..\..\..\build\SourceGenerators.props" /> <Import Project="..\..\..\build\SourceGenerators.props"/>
</ImportGroup> </ImportGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\packages\Avalonia\Avalonia.csproj" /> <ProjectReference Include="..\..\..\packages\Avalonia\Avalonia.csproj"/>
<ProjectReference Include="..\..\..\src\Avalonia.Desktop\Avalonia.Desktop.csproj" /> <ProjectReference Include="..\..\..\src\Avalonia.Desktop\Avalonia.Desktop.csproj"/>
<ProjectReference Condition="'$(Configuration)' == 'Debug'" Include="..\..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" /> <ProjectReference Condition="'$(Configuration)' == 'Debug'" Include="..\..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj"/>
<ProjectReference Include="..\..\..\src\Avalonia.Fonts.Inter\Avalonia.Fonts.Inter.csproj" /> <ProjectReference Include="..\..\..\src\Avalonia.Fonts.Inter\Avalonia.Fonts.Inter.csproj"/>
<ProjectReference Include="..\..\..\src\Avalonia.ReactiveUI\Avalonia.ReactiveUI.csproj" /> <ProjectReference Include="..\..\..\src\Avalonia.ReactiveUI\Avalonia.ReactiveUI.csproj"/>
<ProjectReference Include="..\..\..\src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj" /> <ProjectReference Include="..\..\..\src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj"/>
<ProjectReference Include="..\..\..\src\Markup\Avalonia.Markup.Xaml.Loader\Avalonia.Markup.Xaml.Loader.csproj" /> <ProjectReference Include="..\..\..\src\Markup\Avalonia.Markup.Xaml.Loader\Avalonia.Markup.Xaml.Loader.csproj"/>
</ItemGroup> </ItemGroup>
<ItemGroup>
<UpToDateCheckInput Remove="Views\MainWindow.axaml"/>
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Remove="Views\MainWindow.axaml" />
</ItemGroup>
</Project> </Project>

4
samples/XEmbedSample/HarfbuzzWorkaround.cs

@ -46,7 +46,7 @@ public unsafe class HarfbuzzWorkaround
var libraryPathBytes = Marshal.AllocHGlobal(4096); var libraryPathBytes = Marshal.AllocHGlobal(4096);
var handle = NativeLibrary.Load("libHarfBuzzSharp", typeof(HarfBuzzSharp.Blob).Assembly, null); var handle = NativeLibrary.Load("libHarfBuzzSharp", typeof(HarfBuzzSharp.Blob).Assembly, null);
dlinfo(handle, RTLD_DI_ORIGIN, libraryPathBytes); dlinfo(handle, RTLD_DI_ORIGIN, libraryPathBytes);
var libraryOrigin = Marshal.PtrToStringUTF8(libraryPathBytes); var libraryOrigin = Marshal.PtrToStringUTF8(libraryPathBytes) ?? string.Empty;
Marshal.FreeHGlobal(libraryPathBytes); Marshal.FreeHGlobal(libraryPathBytes);
var libraryPath = Path.Combine(libraryOrigin, "libHarfBuzzSharp.so"); var libraryPath = Path.Combine(libraryOrigin, "libHarfBuzzSharp.so");
@ -63,4 +63,4 @@ public unsafe class HarfbuzzWorkaround
}); });
} }
} }

13
samples/XEmbedSample/Program.cs

@ -4,7 +4,9 @@ using Avalonia.Controls.Primitives;
using Avalonia.Media; using Avalonia.Media;
using ControlCatalog; using ControlCatalog;
using ControlCatalog.Models; using ControlCatalog.Models;
using Gdk;
using Gtk; using Gtk;
using Window = Gtk.Window;
namespace XEmbedSample; namespace XEmbedSample;
@ -31,7 +33,7 @@ class Program
var w = new Gtk.Window("XEmbed Test Window"); var w = new Gtk.Window("XEmbed Test Window");
var socket = new AvaloniaXEmbedGtkSocket(w.StyleContext.GetBackgroundColor(StateFlags.Normal)) var socket = new AvaloniaXEmbedGtkSocket(GetBackgroundColor(w))
{ {
Content = new ScrollViewer() Content = new ScrollViewer()
{ {
@ -60,4 +62,11 @@ class Program
Gtk.Application.Run(); Gtk.Application.Run();
} }
}
private static RGBA GetBackgroundColor(Window window)
{
#pragma warning disable CS0612 // Type or member is obsolete; OK for a sample.
return window.StyleContext.GetBackgroundColor(StateFlags.Normal);
#pragma warning restore CS0612 // Type or member is obsolete
}
}

6
samples/XEmbedSample/SocketEx.cs

@ -14,8 +14,8 @@ public class AvaloniaXEmbedGtkSocket : Gtk.Socket
_backgroundColor = backgroundColor; _backgroundColor = backgroundColor;
} }
private object _content; private object? _content;
public object Content public object? Content
{ {
get => _content; get => _content;
set set
@ -61,4 +61,4 @@ public class AvaloniaXEmbedGtkSocket : Gtk.Socket
_avaloniaPlug = null; _avaloniaPlug = null;
base.OnDestroyed(); base.OnDestroyed();
} }
} }

24
src/Avalonia.Base/Media/TextFormatting/Unicode/PropertyValueAliasHelper.cs

@ -182,11 +182,11 @@ namespace Avalonia.Media.TextFormatting.Unicode
public static string GetTag(Script script) public static string GetTag(Script script)
{ {
if(!s_scriptToTag.ContainsKey(script)) if (!s_scriptToTag.TryGetValue(script, out var value))
{ {
return "Zzzz"; return "Zzzz";
} }
return s_scriptToTag[script]; return value;
} }
private static readonly Dictionary<string, Script> s_tagToScript = private static readonly Dictionary<string, Script> s_tagToScript =
@ -367,11 +367,11 @@ namespace Avalonia.Media.TextFormatting.Unicode
public static Script GetScript(string tag) public static Script GetScript(string tag)
{ {
if(!s_tagToScript.ContainsKey(tag)) if (!s_tagToScript.TryGetValue(tag, out var value))
{ {
return Script.Unknown; return Script.Unknown;
} }
return s_tagToScript[tag]; return value;
} }
private static readonly Dictionary<string, GeneralCategory> s_tagToGeneralCategory = private static readonly Dictionary<string, GeneralCategory> s_tagToGeneralCategory =
@ -418,11 +418,11 @@ namespace Avalonia.Media.TextFormatting.Unicode
public static GeneralCategory GetGeneralCategory(string tag) public static GeneralCategory GetGeneralCategory(string tag)
{ {
if(!s_tagToGeneralCategory.ContainsKey(tag)) if (!s_tagToGeneralCategory.TryGetValue(tag, out var value))
{ {
return GeneralCategory.Other; return GeneralCategory.Other;
} }
return s_tagToGeneralCategory[tag]; return value;
} }
private static readonly Dictionary<string, LineBreakClass> s_tagToLineBreakClass = private static readonly Dictionary<string, LineBreakClass> s_tagToLineBreakClass =
@ -479,11 +479,11 @@ namespace Avalonia.Media.TextFormatting.Unicode
public static LineBreakClass GetLineBreakClass(string tag) public static LineBreakClass GetLineBreakClass(string tag)
{ {
if(!s_tagToLineBreakClass.ContainsKey(tag)) if (!s_tagToLineBreakClass.TryGetValue(tag, out var value))
{ {
return LineBreakClass.Unknown; return LineBreakClass.Unknown;
} }
return s_tagToLineBreakClass[tag]; return value;
} }
private static readonly Dictionary<string, BidiPairedBracketType> s_tagToBidiPairedBracketType = private static readonly Dictionary<string, BidiPairedBracketType> s_tagToBidiPairedBracketType =
@ -495,11 +495,11 @@ namespace Avalonia.Media.TextFormatting.Unicode
public static BidiPairedBracketType GetBidiPairedBracketType(string tag) public static BidiPairedBracketType GetBidiPairedBracketType(string tag)
{ {
if(!s_tagToBidiPairedBracketType.ContainsKey(tag)) if (!s_tagToBidiPairedBracketType.TryGetValue(tag, out var value))
{ {
return BidiPairedBracketType.None; return BidiPairedBracketType.None;
} }
return s_tagToBidiPairedBracketType[tag]; return value;
} }
private static readonly Dictionary<string, BidiClass> s_tagToBidiClass = private static readonly Dictionary<string, BidiClass> s_tagToBidiClass =
@ -531,11 +531,11 @@ namespace Avalonia.Media.TextFormatting.Unicode
public static BidiClass GetBidiClass(string tag) public static BidiClass GetBidiClass(string tag)
{ {
if(!s_tagToBidiClass.ContainsKey(tag)) if (!s_tagToBidiClass.TryGetValue(tag, out var value))
{ {
return BidiClass.LeftToRight; return BidiClass.LeftToRight;
} }
return s_tagToBidiClass[tag]; return value;
} }
} }

2
src/Avalonia.Controls/TextBox.cs

@ -1,6 +1,7 @@
using Avalonia.Input.Platform; using Avalonia.Input.Platform;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Avalonia.Reactive; using Avalonia.Reactive;
using Avalonia.Controls.Presenters; using Avalonia.Controls.Presenters;
@ -629,6 +630,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets or sets the text selected in the TextBox /// Gets or sets the text selected in the TextBox
/// </summary> /// </summary>
[AllowNull]
public string SelectedText public string SelectedText
{ {
get => GetSelection(); get => GetSelection();

4
src/Headless/Avalonia.Headless/HeadlessPlatformStubs.cs

@ -73,7 +73,11 @@ namespace Avalonia.Headless
if (format == DataFormats.Files && _data is not null) if (format == DataFormats.Files && _data is not null)
return _data.GetFiles(); return _data.GetFiles();
if (format == DataFormats.FileNames && _data is not null) if (format == DataFormats.FileNames && _data is not null)
{
#pragma warning disable CS0618 // Type or member is obsolete
return _data.GetFileNames(); return _data.GetFileNames();
#pragma warning restore CS0618 // Type or member is obsolete
}
else else
return (object?)_data; return (object?)_data;
}); });

11
src/Windows/Avalonia.Win32.Automation/GlobalSuppressions.cs

@ -0,0 +1,11 @@
using System.Diagnostics.CodeAnalysis;
// Until https://github.com/dotnet/runtime/issues/90922 is resolved, this is the only way
// to suppress CA2256 in the generated code.
[assembly: SuppressMessage(
"Usage",
"CA2256:All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface",
Justification = "Generated code and analyzer ignores that it is generated AND partial",
Scope = "type",
Target = "~T:InterfaceImplementation")
]

12
tests/Avalonia.Base.UnitTests/Animation/AnimationIterationTests.cs

@ -317,7 +317,7 @@ namespace Avalonia.Base.UnitTests.Animation
} }
[Fact] [Fact]
public void Cancellation_Should_Stop_Animation() public async Task Cancellation_Should_Stop_Animation()
{ {
var keyframe1 = new KeyFrame() var keyframe1 = new KeyFrame()
{ {
@ -364,7 +364,7 @@ namespace Avalonia.Base.UnitTests.Animation
clock.Step(TimeSpan.FromSeconds(2)); clock.Step(TimeSpan.FromSeconds(2));
clock.Step(TimeSpan.FromSeconds(3)); clock.Step(TimeSpan.FromSeconds(3));
animationRun.Wait(); await animationRun;
clock.Step(TimeSpan.FromSeconds(6)); clock.Step(TimeSpan.FromSeconds(6));
Assert.True(animationRun.IsCompleted); Assert.True(animationRun.IsCompleted);
@ -404,7 +404,7 @@ namespace Avalonia.Base.UnitTests.Animation
} }
[Fact] [Fact]
public void Cancellation_Of_Completed_Animation_Does_Not_Fail() public async Task Cancellation_Of_Completed_Animation_Does_Not_Fail()
{ {
var keyframe1 = new KeyFrame() var keyframe1 = new KeyFrame()
{ {
@ -450,12 +450,12 @@ namespace Avalonia.Base.UnitTests.Animation
Assert.Equal(2, propertyChangedCount); Assert.Equal(2, propertyChangedCount);
cancellationTokenSource.Cancel(); cancellationTokenSource.Cancel();
animationRun.Wait(); await animationRun;
} }
// https://github.com/AvaloniaUI/Avalonia/issues/12582 // https://github.com/AvaloniaUI/Avalonia/issues/12582
[Fact] [Fact]
public void Interpolator_Is_Not_Called_After_Last_Iteration() public async Task Interpolator_Is_Not_Called_After_Last_Iteration()
{ {
var animator = new FakeAnimator(); var animator = new FakeAnimator();
@ -511,7 +511,7 @@ namespace Avalonia.Base.UnitTests.Animation
Assert.Equal(3, animator.CallCount); Assert.Equal(3, animator.CallCount);
Assert.Equal(1.0d, animator.LastProgress); Assert.Equal(1.0d, animator.LastProgress);
animationRun.Wait(); await animationRun;
} }
[Theory] [Theory]

2
tests/Avalonia.Base.UnitTests/Collections/AvaloniaListTests.cs

@ -554,7 +554,7 @@ namespace Avalonia.Base.UnitTests.Collections
} }
/// <summary> /// <summary>
/// Assert that <see cref="items"/> emits <see cref="expectedEvents"/> when performing <see cref="action"/>. /// Assert that <paramref name="items"/> emits <paramref name="expectedEvents"/> when performing <paramref name="action"/>.
/// </summary> /// </summary>
/// <param name="items">The event source.</param> /// <param name="items">The event source.</param>
/// <param name="action">The action to perform.</param> /// <param name="action">The action to perform.</param>

2
tests/Avalonia.Base.UnitTests/DispatcherTests.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -462,6 +463,7 @@ public partial class DispatcherTests
} }
[Fact] [Fact]
[SuppressMessage("Usage", "xUnit1031:Do not use blocking task operations in test method", Justification = "Tests the dispatcher itself")]
public void DispatcherInvokeAsyncUnwrapsTasks() public void DispatcherInvokeAsyncUnwrapsTasks()
{ {
int asyncMethodStage = 0; int asyncMethodStage = 0;

4
tests/Avalonia.Base.UnitTests/Media/TextFormatting/BiDiClassTests.cs

@ -1,4 +1,5 @@
using System.Linq; using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using Avalonia.Media.TextFormatting.Unicode; using Avalonia.Media.TextFormatting.Unicode;
@ -18,6 +19,7 @@ namespace Avalonia.Visuals.UnitTests.Media.TextFormatting
[Theory(Skip = "Only run when the Unicode spec changes.")] [Theory(Skip = "Only run when the Unicode spec changes.")]
[ClassData(typeof(BiDiClassTestDataGenerator))] [ClassData(typeof(BiDiClassTestDataGenerator))]
[SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters", Justification = "Parameters match BiDi fields")]
public void Should_Resolve( public void Should_Resolve(
int lineNumber, int lineNumber,
int[] codePoints, int[] codePoints,

8
tests/Avalonia.Base.UnitTests/Media/TextFormatting/UnicodeEnumsGenerator.cs

@ -447,11 +447,11 @@ namespace Avalonia.Base.UnitTests.Media.TextFormatting
writer.WriteLine($" public static string GetTag({typeName} {typeName.ToLower()})"); writer.WriteLine($" public static string GetTag({typeName} {typeName.ToLower()})");
writer.WriteLine(" {"); writer.WriteLine(" {");
writer.WriteLine($" if(!s_{typeName.ToLower()}ToTag.ContainsKey({typeName.ToLower()}))"); writer.WriteLine($" if (!s_{typeName.ToLower()}ToTag.TryGetValue({typeName.ToLower()}, out var value))");
writer.WriteLine(" {"); writer.WriteLine(" {");
writer.WriteLine($" return \"{defaultValue}\";"); writer.WriteLine($" return \"{defaultValue}\";");
writer.WriteLine(" }"); writer.WriteLine(" }");
writer.WriteLine($" return s_{typeName.ToLower()}ToTag[{typeName.ToLower()}];"); writer.WriteLine($" return value;");
writer.WriteLine(" }"); writer.WriteLine(" }");
writer.WriteLine(); writer.WriteLine();
@ -474,11 +474,11 @@ namespace Avalonia.Base.UnitTests.Media.TextFormatting
writer.WriteLine($" public static {typeName} Get{typeName}(string tag)"); writer.WriteLine($" public static {typeName} Get{typeName}(string tag)");
writer.WriteLine(" {"); writer.WriteLine(" {");
writer.WriteLine($" if(!s_tagTo{typeName}.ContainsKey(tag))"); writer.WriteLine($" if (!s_tagTo{typeName}.TryGetValue(tag, out var value))");
writer.WriteLine(" {"); writer.WriteLine(" {");
writer.WriteLine($" return {typeName}.{defaultValue};"); writer.WriteLine($" return {typeName}.{defaultValue};");
writer.WriteLine(" }"); writer.WriteLine(" }");
writer.WriteLine($" return s_tagTo{typeName}[tag];"); writer.WriteLine($" return value;");
writer.WriteLine(" }"); writer.WriteLine(" }");
writer.WriteLine(); writer.WriteLine();

2
tests/Avalonia.Base.UnitTests/Utilities/StringTokenizerTests.cs

@ -2,6 +2,8 @@
using Avalonia.Utilities; using Avalonia.Utilities;
using Xunit; using Xunit;
#pragma warning disable CS0618 // Type or member is obsolete
namespace Avalonia.Base.UnitTests.Utilities namespace Avalonia.Base.UnitTests.Utilities
{ {
public class StringTokenizerTests public class StringTokenizerTests

2
tests/Avalonia.Build.Tasks.UnitTest/CompileAvaloniaXamlTaskTest.cs

@ -30,7 +30,7 @@ public class CompileAvaloniaXamlTaskTest
ProjectDirectory = Directory.GetCurrentDirectory(), ProjectDirectory = Directory.GetCurrentDirectory(),
VerifyIl = true VerifyIl = true
}.Execute(); }.Execute();
Assert.Equal(0, engine.Errors.Count); Assert.Empty(engine.Errors);
} }

3
tests/Avalonia.Controls.DataGrid.UnitTests/Collections/ComparerTests.cs

@ -219,5 +219,8 @@ public class NoStringTypeComparerTests
} }
return false; return false;
} }
public override int GetHashCode()
=> Prop;
} }
} }

2
tests/Avalonia.Controls.UnitTests/GridLengthTests.cs

@ -107,7 +107,7 @@ namespace Avalonia.Controls.UnitTests
[InlineData(1.2d, GridUnitType.Pixel, "1.2")] [InlineData(1.2d, GridUnitType.Pixel, "1.2")]
[InlineData(1.2d, GridUnitType.Star, "1.2*")] [InlineData(1.2d, GridUnitType.Star, "1.2*")]
[InlineData(1.2d, GridUnitType.Auto, "Auto")] [InlineData(1.2d, GridUnitType.Auto, "Auto")]
public async void ToString_AllCulture_Should_Pass(double d, GridUnitType type, string result) public async Task ToString_AllCulture_Should_Pass(double d, GridUnitType type, string result)
{ {
List<CultureInfo> cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures).ToList(); List<CultureInfo> cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures).ToList();
GridLength length = new GridLength(d, type); GridLength length = new GridLength(d, type);

6
tests/Avalonia.Controls.UnitTests/MaskedTextBoxTests.cs

@ -804,7 +804,7 @@ namespace Avalonia.Controls.UnitTests
[InlineData("abc", "ddd", 3, 0, 2, true, "ddc")] [InlineData("abc", "ddd", 3, 0, 2, true, "ddc")]
[InlineData("abc", "dddd", 4, 1, 3, true, "addd")] [InlineData("abc", "dddd", 4, 1, 3, true, "addd")]
[InlineData("abc", "ddddd", 5, 3, 3, true, "abcdd")] [InlineData("abc", "ddddd", 5, 3, 3, true, "abcdd")]
public void MaxLength_Works_Properly( public async Task MaxLength_Works_Properly(
string initalText, string initalText,
string textInput, string textInput,
int maxLength, int maxLength,
@ -838,10 +838,10 @@ namespace Avalonia.Controls.UnitTests
if (fromClipboard) if (fromClipboard)
{ {
topLevel.Clipboard?.SetTextAsync(textInput).GetAwaiter().GetResult(); await topLevel.Clipboard!.SetTextAsync(textInput);
RaiseKeyEvent(target, Key.V, KeyModifiers.Control); RaiseKeyEvent(target, Key.V, KeyModifiers.Control);
topLevel.Clipboard?.ClearAsync().GetAwaiter().GetResult(); await topLevel.Clipboard!.ClearAsync();
} }
else else
{ {

4
tests/Avalonia.Controls.UnitTests/Platform/ScreensTests.cs

@ -102,7 +102,7 @@ public class ScreensTests : ScopedTestBase
} }
[Fact] [Fact]
public void Should_Raise_Event_When_Screen_Changed_From_Another_Thread() public async Task Should_Raise_Event_When_Screen_Changed_From_Another_Thread()
{ {
using var _ = UnitTestApplication.Start(TestServices.MockThreadingInterface); using var _ = UnitTestApplication.Start(TestServices.MockThreadingInterface);
@ -114,7 +114,7 @@ public class ScreensTests : ScopedTestBase
hasChangedTimes += 1; hasChangedTimes += 1;
}; };
Task.Run(() => screens.PushNewScreens([1, 2])).Wait(); await Task.Run(() => screens.PushNewScreens([1, 2]));
Dispatcher.UIThread.RunJobs(); Dispatcher.UIThread.RunJobs();
Assert.Equal(1, hasChangedTimes); Assert.Equal(1, hasChangedTimes);

42
tests/Avalonia.Controls.UnitTests/TextBoxTests.cs

@ -1,3 +1,5 @@
#nullable enable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reactive.Linq; using System.Reactive.Linq;
@ -837,7 +839,7 @@ namespace Avalonia.Controls.UnitTests
[InlineData("abc", "ddd", 3, 0, 2, true, "ddc")] [InlineData("abc", "ddd", 3, 0, 2, true, "ddc")]
[InlineData("abc", "dddd", 4, 1, 3, true, "addd")] [InlineData("abc", "dddd", 4, 1, 3, true, "addd")]
[InlineData("abc", "ddddd", 5, 3, 3, true, "abcdd")] [InlineData("abc", "ddddd", 5, 3, 3, true, "abcdd")]
public void MaxLength_Works_Properly( public async Task MaxLength_Works_Properly(
string initalText, string initalText,
string textInput, string textInput,
int maxLength, int maxLength,
@ -870,10 +872,10 @@ namespace Avalonia.Controls.UnitTests
if (fromClipboard) if (fromClipboard)
{ {
topLevel.Clipboard?.SetTextAsync(textInput).GetAwaiter().GetResult(); await topLevel.Clipboard!.SetTextAsync(textInput);
RaiseKeyEvent(target, Key.V, KeyModifiers.Control); RaiseKeyEvent(target, Key.V, KeyModifiers.Control);
topLevel.Clipboard?.ClearAsync().GetAwaiter().GetResult(); await topLevel.Clipboard!.ClearAsync();
} }
else else
{ {
@ -936,7 +938,7 @@ namespace Avalonia.Controls.UnitTests
SelectionEnd = 3, SelectionEnd = 3,
}; };
var values = new List<string>(); var values = new List<string?>();
target.GetObservable(TextBox.TextProperty).Subscribe(x => values.Add(x)); target.GetObservable(TextBox.TextProperty).Subscribe(x => values.Add(x));
target.SelectedText = "A"; target.SelectedText = "A";
@ -960,7 +962,7 @@ namespace Avalonia.Controls.UnitTests
SelectionEnd = 3, SelectionEnd = 3,
}; };
var values = new List<string>(); var values = new List<string?>();
target.GetObservable(TextBox.TextProperty).Subscribe(x => values.Add(x)); target.GetObservable(TextBox.TextProperty).Subscribe(x => values.Add(x));
RaiseTextEvent(target, "A"); RaiseTextEvent(target, "A");
@ -1008,7 +1010,7 @@ namespace Avalonia.Controls.UnitTests
} }
[Fact] [Fact]
public void Should_Fullfill_MaxLines_Contraint() public async Task Should_Fullfill_MaxLines_Contraint()
{ {
using (UnitTestApplication.Start(Services)) using (UnitTestApplication.Start(Services))
{ {
@ -1034,10 +1036,10 @@ namespace Avalonia.Controls.UnitTests
var initialHeight = target.DesiredSize.Height; var initialHeight = target.DesiredSize.Height;
topLevel.Clipboard?.SetTextAsync(Environment.NewLine).GetAwaiter().GetResult(); await topLevel.Clipboard!.SetTextAsync(Environment.NewLine);
RaiseKeyEvent(target, Key.V, KeyModifiers.Control); RaiseKeyEvent(target, Key.V, KeyModifiers.Control);
topLevel.Clipboard?.ClearAsync().GetAwaiter().GetResult(); await topLevel.Clipboard!.ClearAsync();
RaiseTextEvent(target, Environment.NewLine); RaiseTextEvent(target, Environment.NewLine);
@ -1075,10 +1077,12 @@ namespace Avalonia.Controls.UnitTests
topLevel.LayoutManager.ExecuteInitialLayoutPass(); topLevel.LayoutManager.ExecuteInitialLayoutPass();
var textPresenter = target.FindDescendantOfType<TextPresenter>(); var textPresenter = target.FindDescendantOfType<TextPresenter>();
Assert.NotNull(textPresenter);
Assert.Equal("PART_TextPresenter", textPresenter.Name); Assert.Equal("PART_TextPresenter", textPresenter.Name);
Assert.Equal(new Thickness(0), textPresenter.Margin); // Test assumes no margin on TextPresenter Assert.Equal(new Thickness(0), textPresenter.Margin); // Test assumes no margin on TextPresenter
var scrollViewer = target.FindDescendantOfType<ScrollViewer>(); var scrollViewer = target.FindDescendantOfType<ScrollViewer>();
Assert.NotNull(scrollViewer);
Assert.Equal("PART_ScrollViewer", scrollViewer.Name); Assert.Equal("PART_ScrollViewer", scrollViewer.Name);
Assert.Equal(maxLines * target.LineHeight, scrollViewer.MaxHeight); Assert.Equal(maxLines * target.LineHeight, scrollViewer.MaxHeight);
} }
@ -1111,6 +1115,7 @@ namespace Avalonia.Controls.UnitTests
topLevel.LayoutManager.ExecuteInitialLayoutPass(); topLevel.LayoutManager.ExecuteInitialLayoutPass();
var textPresenter = target.FindDescendantOfType<TextPresenter>(); var textPresenter = target.FindDescendantOfType<TextPresenter>();
Assert.NotNull(textPresenter);
Assert.Equal("PART_TextPresenter", textPresenter.Name); Assert.Equal("PART_TextPresenter", textPresenter.Name);
var textPresenterMargin = new Thickness(horizontal: 0, vertical: 3); var textPresenterMargin = new Thickness(horizontal: 0, vertical: 3);
textPresenter.Margin = textPresenterMargin; textPresenter.Margin = textPresenterMargin;
@ -1119,6 +1124,7 @@ namespace Avalonia.Controls.UnitTests
target.Measure(Size.Infinity); target.Measure(Size.Infinity);
var scrollViewer = target.FindDescendantOfType<ScrollViewer>(); var scrollViewer = target.FindDescendantOfType<ScrollViewer>();
Assert.NotNull(scrollViewer);
Assert.Equal("PART_ScrollViewer", scrollViewer.Name); Assert.Equal("PART_ScrollViewer", scrollViewer.Name);
Assert.Equal((maxLines * target.LineHeight) + textPresenterMargin.Top + textPresenterMargin.Bottom, scrollViewer.MaxHeight); Assert.Equal((maxLines * target.LineHeight) + textPresenterMargin.Top + textPresenterMargin.Bottom, scrollViewer.MaxHeight);
} }
@ -1187,10 +1193,12 @@ namespace Avalonia.Controls.UnitTests
topLevel.LayoutManager.ExecuteInitialLayoutPass(); topLevel.LayoutManager.ExecuteInitialLayoutPass();
var textPresenter = target.FindDescendantOfType<TextPresenter>(); var textPresenter = target.FindDescendantOfType<TextPresenter>();
Assert.NotNull(textPresenter);
Assert.Equal("PART_TextPresenter", textPresenter.Name); Assert.Equal("PART_TextPresenter", textPresenter.Name);
Assert.Equal(new Thickness(0), textPresenter.Margin); // Test assumes no margin on TextPresenter Assert.Equal(new Thickness(0), textPresenter.Margin); // Test assumes no margin on TextPresenter
var scrollViewer = target.FindDescendantOfType<ScrollViewer>(); var scrollViewer = target.FindDescendantOfType<ScrollViewer>();
Assert.NotNull(scrollViewer);
Assert.Equal("PART_ScrollViewer", scrollViewer.Name); Assert.Equal("PART_ScrollViewer", scrollViewer.Name);
Assert.Equal(minLines * target.LineHeight, scrollViewer.MinHeight); Assert.Equal(minLines * target.LineHeight, scrollViewer.MinHeight);
} }
@ -1223,6 +1231,7 @@ namespace Avalonia.Controls.UnitTests
topLevel.LayoutManager.ExecuteInitialLayoutPass(); topLevel.LayoutManager.ExecuteInitialLayoutPass();
var textPresenter = target.FindDescendantOfType<TextPresenter>(); var textPresenter = target.FindDescendantOfType<TextPresenter>();
Assert.NotNull(textPresenter);
Assert.Equal("PART_TextPresenter", textPresenter.Name); Assert.Equal("PART_TextPresenter", textPresenter.Name);
var textPresenterMargin = new Thickness(horizontal: 0, vertical: 3); var textPresenterMargin = new Thickness(horizontal: 0, vertical: 3);
textPresenter.Margin = textPresenterMargin; textPresenter.Margin = textPresenterMargin;
@ -1231,6 +1240,7 @@ namespace Avalonia.Controls.UnitTests
target.Measure(Size.Infinity); target.Measure(Size.Infinity);
var scrollViewer = target.FindDescendantOfType<ScrollViewer>(); var scrollViewer = target.FindDescendantOfType<ScrollViewer>();
Assert.NotNull(scrollViewer);
Assert.Equal("PART_ScrollViewer", scrollViewer.Name); Assert.Equal("PART_ScrollViewer", scrollViewer.Name);
Assert.Equal((minLines * target.LineHeight) + textPresenterMargin.Top + textPresenterMargin.Bottom, scrollViewer.MinHeight); Assert.Equal((minLines * target.LineHeight) + textPresenterMargin.Top + textPresenterMargin.Bottom, scrollViewer.MinHeight);
} }
@ -1541,6 +1551,7 @@ namespace Avalonia.Controls.UnitTests
var adorner = new TextBox { Template = CreateTemplate(), Text = "a" }; var adorner = new TextBox { Template = CreateTemplate(), Text = "a" };
var adornerLayer = AdornerLayer.GetAdornerLayer(button); var adornerLayer = AdornerLayer.GetAdornerLayer(button);
Assert.NotNull(adornerLayer);
adornerLayer.Children.Add(adorner); adornerLayer.Children.Add(adorner);
AdornerLayer.SetAdornedElement(adorner, button); AdornerLayer.SetAdornedElement(adorner, button);
@ -1561,6 +1572,7 @@ namespace Avalonia.Controls.UnitTests
}; };
var adorner = new TextBox { Template = CreateTemplate(), Text = "a" }; var adorner = new TextBox { Template = CreateTemplate(), Text = "a" };
var adornerLayer = AdornerLayer.GetAdornerLayer(button); var adornerLayer = AdornerLayer.GetAdornerLayer(button);
Assert.NotNull(adornerLayer);
root.Measure(new Size(10, 10)); root.Measure(new Size(10, 10));
@ -1780,7 +1792,7 @@ namespace Avalonia.Controls.UnitTests
private class Class1 : NotifyingBase private class Class1 : NotifyingBase
{ {
private int _foo; private int _foo;
private string _bar; private string? _bar;
public int Foo public int Foo
{ {
@ -1788,7 +1800,7 @@ namespace Avalonia.Controls.UnitTests
set { _foo = value; RaisePropertyChanged(); } set { _foo = value; RaisePropertyChanged(); }
} }
public string Bar public string? Bar
{ {
get { return _bar; } get { return _bar; }
set { _bar = value; RaisePropertyChanged(); } set { _bar = value; RaisePropertyChanged(); }
@ -1797,11 +1809,11 @@ namespace Avalonia.Controls.UnitTests
private class ClipboardStub : IClipboard // in order to get tests working that use the clipboard private class ClipboardStub : IClipboard // in order to get tests working that use the clipboard
{ {
private string _text; private string? _text;
public Task<string> GetTextAsync() => Task.FromResult(_text); public Task<string?> GetTextAsync() => Task.FromResult(_text);
public Task SetTextAsync(string text) public Task SetTextAsync(string? text)
{ {
_text = text; _text = text;
return Task.CompletedTask; return Task.CompletedTask;
@ -1817,14 +1829,14 @@ namespace Avalonia.Controls.UnitTests
public Task<string[]> GetFormatsAsync() => Task.FromResult(Array.Empty<string>()); public Task<string[]> GetFormatsAsync() => Task.FromResult(Array.Empty<string>());
public Task<object> GetDataAsync(string format) => Task.FromResult((object)null); public Task<object?> GetDataAsync(string format) => Task.FromResult((object?)null);
} }
private class TestTopLevel : TopLevel private class TestTopLevel : TopLevel
{ {
private readonly ILayoutManager _layoutManager; private readonly ILayoutManager _layoutManager;
public TestTopLevel(ITopLevelImpl impl, ILayoutManager layoutManager = null) public TestTopLevel(ITopLevelImpl impl, ILayoutManager? layoutManager = null)
: base(impl) : base(impl)
{ {
_layoutManager = layoutManager ?? new LayoutManager(this); _layoutManager = layoutManager ?? new LayoutManager(this);

2
tests/Avalonia.Controls.UnitTests/WindowTests.cs

@ -1072,7 +1072,7 @@ namespace Avalonia.Controls.UnitTests
var task = target.ShowDialog<bool>(parent); var task = target.ShowDialog<bool>(parent);
target.IsVisible = false; target.IsVisible = false;
Assert.True(task.IsCompletedSuccessfully); Assert.True(task.IsCompletedSuccessfully);
} }
} }

2
tests/Avalonia.DesignerSupport.Tests/RemoteProtocolTests.cs

@ -2,6 +2,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
@ -80,6 +81,7 @@ namespace Avalonia.DesignerSupport.Tests
} }
[Fact] [Fact]
[SuppressMessage("Usage", "xUnit1031:Do not use blocking task operations in test method", Justification = "Sync context is explicitly disabled")]
void EntitiesAreProperlySerializedAndDeserialized() void EntitiesAreProperlySerializedAndDeserialized()
{ {
Init(); Init();

6
tests/Avalonia.Generators.Tests/XamlXNameResolverTests.cs

@ -22,9 +22,9 @@ public class XamlXNameResolverTests
var controls = ResolveNames(xaml); var controls = ResolveNames(xaml);
Assert.NotEmpty(controls); Assert.NotEmpty(controls);
Assert.Equal(1, controls.Count); var control = Assert.Single(controls);
Assert.Equal("UserNameTextBox", controls[0].Name); Assert.Equal("UserNameTextBox", control.Name);
Assert.Contains(typeof(TextBox).FullName!, controls[0].TypeName); Assert.Contains(typeof(TextBox).FullName!, control.TypeName);
} }
[Theory] [Theory]

4
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs

@ -244,7 +244,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
window.DataContext = dataContext; window.DataContext = dataContext;
Assert.Equal(dataContext.TaskProperty.Result, textBlock.Text); Assert.Equal("foobar", textBlock.Text);
} }
} }
@ -1920,7 +1920,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
[Theory] [Theory]
[InlineData(null, "Not called")] [InlineData(null, "Not called")]
[InlineData("A", "Do A")] [InlineData("A", "Do A")]
public void Binding_Method_With_Parameter_To_Command_CanExecute(object commandParameter, string result) public void Binding_Method_With_Parameter_To_Command_CanExecute(object? commandParameter, string result)
{ {
using (UnitTestApplication.Start(TestServices.StyledWindow)) using (UnitTestApplication.Start(TestServices.StyledWindow))
{ {

4
tests/Avalonia.RenderTests/TestBase.cs

@ -99,7 +99,7 @@ namespace Avalonia.Direct2D1.RenderTests
var immediateError = TestRenderHelper.CompareImages(immediate!, expected); var immediateError = TestRenderHelper.CompareImages(immediate!, expected);
if (immediateError > AllowedError) if (immediateError > AllowedError)
{ {
Assert.True(false, immediatePath + ": Error = " + immediateError); Assert.Fail(immediatePath + ": Error = " + immediateError);
} }
} }
@ -108,7 +108,7 @@ namespace Avalonia.Direct2D1.RenderTests
var compositedError = TestRenderHelper.CompareImages(composited!, expected); var compositedError = TestRenderHelper.CompareImages(composited!, expected);
if (compositedError > AllowedError) if (compositedError > AllowedError)
{ {
Assert.True(false, compositedPath + ": Error = " + compositedError); Assert.Fail(compositedPath + ": Error = " + compositedError);
} }
} }
} }

2
tests/Avalonia.RenderTests/TestRenderHelper.cs

@ -172,7 +172,7 @@ static class TestRenderHelper
if (immediateError > 0.022) if (immediateError > 0.022)
{ {
Assert.True(false, actualPath + ": Error = " + immediateError); Assert.Fail(actualPath + ": Error = " + immediateError);
} }
} }
} }

8
tests/Avalonia.Skia.UnitTests/Media/EmbeddedFontCollectionTests.cs

@ -1,4 +1,6 @@
using System; #nullable enable
using System;
using System.Collections; using System.Collections;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
@ -32,7 +34,7 @@ namespace Avalonia.Skia.UnitTests.Media
Assert.True(fontCollection.TryGetGlyphTypeface("Noto Mono", fontStyle, fontWeight, FontStretch.Normal, out var glyphTypeface)); Assert.True(fontCollection.TryGetGlyphTypeface("Noto Mono", fontStyle, fontWeight, FontStretch.Normal, out var glyphTypeface));
var actual = glyphTypeface?.FamilyName; var actual = glyphTypeface.FamilyName;
Assert.Equal("Noto Mono", actual); Assert.Equal("Noto Mono", actual);
} }
@ -49,7 +51,7 @@ namespace Avalonia.Skia.UnitTests.Media
fontCollection.Initialize(new CustomFontManagerImpl()); fontCollection.Initialize(new CustomFontManagerImpl());
Assert.False(fontCollection.TryGetGlyphTypeface("ABC", FontStyle.Normal, FontWeight.Normal, FontStretch.Normal, out var glyphTypeface)); Assert.False(fontCollection.TryGetGlyphTypeface("ABC", FontStyle.Normal, FontWeight.Normal, FontStretch.Normal, out _));
} }
} }

8
tests/Avalonia.Skia.UnitTests/Media/FontCollectionTests.cs

@ -1,4 +1,6 @@
using System.Collections.Concurrent; #nullable enable
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Media.Fonts; using Avalonia.Media.Fonts;
@ -41,7 +43,7 @@ namespace Avalonia.Skia.UnitTests.Media
Assert.True(glyphTypeface.FontSimulations == FontSimulations.Bold); Assert.True(glyphTypeface.FontSimulations == FontSimulations.Bold);
Assert.True(fontCollection.GlyphTypfaceCache.TryGetValue("Arial", out var glyphTypefaces)); Assert.True(fontCollection.GlyphTypefaceCache.TryGetValue("Arial", out var glyphTypefaces));
Assert.Equal(2, glyphTypefaces.Count); Assert.Equal(2, glyphTypefaces.Count);
@ -60,7 +62,7 @@ namespace Avalonia.Skia.UnitTests.Media
} }
public IDictionary<string, ConcurrentDictionary<FontCollectionKey, IGlyphTypeface?>> GlyphTypfaceCache => _glyphTypefaceCache; public IDictionary<string, ConcurrentDictionary<FontCollectionKey, IGlyphTypeface?>> GlyphTypefaceCache => _glyphTypefaceCache;
} }
} }
} }

Loading…
Cancel
Save