Files
unity-application/Assets/Common/Tests/EditMode/ThemeListTests.cs
2023-05-14 20:18:29 +00:00

65 lines
1.9 KiB
C#

using NUnit.Framework;
using UnityEngine;
/// <summary>
/// Test the ThemeList class
/// </summary>
[TestFixture]
public class ThemeListTests
{
/// <summary>
/// Reference to the themelist, for quick access
/// </summary>
private ThemeList themeList;
/// <summary>
/// Setup a ThemeList with all possible themes in the enum
/// </summary>
[SetUp]
public void Setup_Minigame()
{
themeList = ScriptableObject.CreateInstance<ThemeList>();
// Add a theme for each index in the enum
// Dumb way to access each index in the enum, couldn't find a different way to do it though
foreach (var field in typeof(ThemeIndex).GetFields())
{
if (field.IsLiteral)
{
ThemeIndex value = (ThemeIndex)field.GetValue(null);
string name = field.Name;
Theme theme = ScriptableObject.CreateInstance<Theme>();
// This is all we will need to distinguish
theme.themeIndex = value;
theme.title = name;
// Insert in front to guarantee that themeIndex will not line up with listIndex
themeList.themes.Insert(0, theme);
}
}
}
/// <summary>
/// Check if all themes can be correctly set as current via SetCurrentTheme
/// </summary>
[Test]
public void TestSetCurrentMinigame()
{
foreach (var field in typeof(ThemeIndex).GetFields())
{
if (field.IsLiteral)
{
ThemeIndex value = (ThemeIndex)field.GetValue(null);
string name = field.Name;
themeList.SetCurrentTheme(value);
// Fetch the current theme and check if its name is the same as the one we made into the current one
Theme m = themeList.themes[themeList.currentThemeIndex];
Assert.AreEqual(m.title, name);
}
}
}
}