A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
1.6 KiB

using System;
using System.Linq;
using Avalonia.Themes.Fluent;
using Avalonia.Themes.Simple;
using Avalonia.Themes.UnitTests.Utilities;
using Xunit;
namespace Avalonia.Themes.UnitTests;
[Trait("Category", "FluentTheme")]
public class FluentResourceDictionaryTests() : ResourceDictionaryTests(typeof(FluentTheme));
[Trait("Category", "SimpleTheme")]
public class SimpleResourceDictionaryTests() : ResourceDictionaryTests(typeof(SimpleTheme));
public abstract class ResourceDictionaryTests(Type typeEntryPoint) : ThemeTestBase(typeEntryPoint)
{
[Fact]
public void Should_Define_Identical_Keys_In_ThemeDictionaries()
{
// Any resource defined in one ThemeDictionary, must be defined in the rest
var theme = CreateAttachedTheme();
// We expect that our built-in themes define ThemeDictionaries on the root style object.
var flatThemeDictionaryResources = theme.Resources
.ThemeDictionaries.ToDictionary(
dict => dict.Key,
dict => dict.Value.EnumerateResources());
Assert.NotEmpty(flatThemeDictionaryResources.Keys);
Assert.All(flatThemeDictionaryResources.Keys, variant =>
{
var variantResourceKeys = flatThemeDictionaryResources[variant].Select(r => r.Key);
var otherResourceKeys = flatThemeDictionaryResources
.Where(p => p.Key != variant)
.SelectMany(p => p.Value).Select(r => r.Key)
.ToHashSet();
Assert.All(variantResourceKeys, k => Assert.Contains(k, otherResourceKeys));
});
}
}