Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkatz6 committed May 22, 2022
1 parent a8c9dfe commit 5c56e3f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 42 deletions.
3 changes: 0 additions & 3 deletions tests/Avalonia.Benchmarks/Themes/FluentBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ private static Styles LoadFluentTheme()
return new Styles
{
new Avalonia.Themes.Fluent.FluentTheme(new Uri("avares://Avalonia.Benchmarks"))
{

}
};
}
}
Expand Down
31 changes: 8 additions & 23 deletions tests/Avalonia.Benchmarks/Themes/ThemeBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Avalonia.Markup.Xaml.Styling;
using Avalonia.PlatformSupport;
using Avalonia.Styling;
using Avalonia.Themes.Default;
using Avalonia.Themes.Fluent;
using Avalonia.UnitTests;

using BenchmarkDotNet.Attributes;
Expand All @@ -25,34 +27,17 @@ public ThemeBenchmark()
}

[Benchmark]
[Arguments("avares://Avalonia.Themes.Fluent/FluentDark.xaml")]
[Arguments("avares://Avalonia.Themes.Fluent/FluentLight.xaml")]
public bool InitFluentTheme(string themeUri)
public bool InitFluentTheme()
{
UnitTestApplication.Current.Styles[0] = new StyleInclude(new Uri("resm:Styles?assembly=Avalonia.Benchmarks"))
{
Source = new Uri(themeUri)
};
return ((IResourceHost)UnitTestApplication.Current).TryGetResource("SystemAccentColor", out _);
UnitTestApplication.Current.Styles[0] = new FluentTheme(new Uri("resm:Styles?assembly=Avalonia.Benchmarks"));
return ((IResourceHost)UnitTestApplication.Current).TryGetResource(ElementTheme.Dark, "SystemAccentColor", out _);
}

[Benchmark]
[Arguments("avares://Avalonia.Themes.Default/Accents/BaseLight.xaml")]
[Arguments("avares://Avalonia.Themes.Default/Accents/BaseDark.xaml")]
public bool InitDefaultTheme(string themeUri)
public bool InitDefaultTheme()
{
UnitTestApplication.Current.Styles[0] = new Styles
{
new StyleInclude(new Uri("resm:Styles?assembly=Avalonia.Benchmarks"))
{
Source = new Uri(themeUri)
},
new StyleInclude(new Uri("resm:Styles?assembly=Avalonia.Benchmarks"))
{
Source = new Uri("avares://Avalonia.Themes.Default/DefaultTheme.xaml")
}
};
return ((IResourceHost)UnitTestApplication.Current).TryGetResource("ThemeAccentColor", out _);
UnitTestApplication.Current.Styles[0] = new SimpleTheme(new Uri("resm:Styles?assembly=Avalonia.Benchmarks"));
return ((IResourceHost)UnitTestApplication.Current).TryGetResource(ElementTheme.Dark, "ThemeAccentColor", out _);
}

public void Dispose()
Expand Down
19 changes: 5 additions & 14 deletions tests/Avalonia.UnitTests/TestServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public TestServices(
IScheduler scheduler = null,
ICursorFactory standardCursorFactory = null,
IStyler styler = null,
Func<Styles> theme = null,
Func<IStyle> theme = null,
IPlatformThreadingInterface threadingInterface = null,
IFontManagerImpl fontManagerImpl = null,
ITextShaperImpl textShaperImpl = null,
Expand Down Expand Up @@ -123,7 +123,7 @@ public TestServices(
public IScheduler Scheduler { get; }
public ICursorFactory StandardCursorFactory { get; }
public IStyler Styler { get; }
public Func<Styles> Theme { get; }
public Func<IStyle> Theme { get; }
public IPlatformThreadingInterface ThreadingInterface { get; }
public IWindowImpl WindowImpl { get; }
public IWindowingPlatform WindowingPlatform { get; }
Expand All @@ -142,7 +142,7 @@ public TestServices With(
IScheduler scheduler = null,
ICursorFactory standardCursorFactory = null,
IStyler styler = null,
Func<Styles> theme = null,
Func<IStyle> theme = null,
IPlatformThreadingInterface threadingInterface = null,
IFontManagerImpl fontManagerImpl = null,
ITextShaperImpl textShaperImpl = null,
Expand Down Expand Up @@ -170,18 +170,9 @@ public TestServices With(
windowImpl: windowImpl ?? WindowImpl);
}

private static Styles CreateDefaultTheme()
private static IStyle CreateDefaultTheme()
{
var result = new Styles
{
new DefaultTheme(),
};

var baseLight = (IStyle)AvaloniaXamlLoader.Load(
new Uri("avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"));
result.Add(baseLight);

return result;
return new SimpleTheme(new Uri("resm:Styles?assembly=Avalonia.UnitTest"));
}

private static IPlatformRenderInterface CreateRenderInterfaceMock()
Expand Down
8 changes: 6 additions & 2 deletions tests/Avalonia.UnitTests/UnitTestApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@ public override void RegisterServices()
.Bind<IStyler>().ToConstant(Services.Styler)
.Bind<IWindowingPlatform>().ToConstant(Services.WindowingPlatform)
.Bind<PlatformHotkeyConfiguration>().ToSingleton<PlatformHotkeyConfiguration>();
var styles = Services.Theme?.Invoke();
var style = Services.Theme?.Invoke();

if (styles != null)
if (style is Styles styles)
{
Styles.AddRange(styles);
}
else if (style is not null)
{
Styles.Add(style);
}
}
}
}

0 comments on commit 5c56e3f

Please sign in to comment.