using Avalonia.Controls; using Avalonia.Platform; using Xunit; namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions; public class OnPlatformExtensionTests : XamlTestBase { [Fact] public void Should_Resolve_Default_Value() { using (AvaloniaLocator.EnterScope()) { AvaloniaLocator.CurrentMutable.Bind() .ToConstant(new TestRuntimePlatform(OperatingSystemType.Unknown)); var xaml = @" "; var userControl = (UserControl)AvaloniaRuntimeXamlLoader.Load(xaml); var textBlock = (TextBlock)userControl.Content!; Assert.Equal("Hello World", textBlock.Text); } } [Theory] [InlineData(OperatingSystemType.WinNT, "Im Windows")] [InlineData(OperatingSystemType.OSX, "Im macOS")] [InlineData(OperatingSystemType.Linux, "Im Linux")] [InlineData(OperatingSystemType.Android, "Im Android")] [InlineData(OperatingSystemType.iOS, "Im iOS")] [InlineData(OperatingSystemType.Browser, "Im Browser")] [InlineData(OperatingSystemType.Unknown, "Default value")] public void Should_Resolve_Expected_Value_Per_Platform(OperatingSystemType currentPlatform, string expectedResult) { using (AvaloniaLocator.EnterScope()) { AvaloniaLocator.CurrentMutable.Bind() .ToConstant(new TestRuntimePlatform(currentPlatform)); var xaml = @" "; var userControl = (UserControl)AvaloniaRuntimeXamlLoader.Load(xaml); var textBlock = (TextBlock)userControl.Content!; Assert.Equal(expectedResult, textBlock.Text); } } private class TestRuntimePlatform : StandardRuntimePlatform { private readonly OperatingSystemType _operatingSystemType; public TestRuntimePlatform(OperatingSystemType operatingSystemType) { _operatingSystemType = operatingSystemType; } public override RuntimePlatformInfo GetRuntimeInfo() { return new RuntimePlatformInfo() { OperatingSystem = _operatingSystemType }; } } }