Files
unity-application/Assets/Common/Tests/ThemeListTest.cs
2023-03-25 13:12:55 +00:00

61 lines
1.8 KiB
C#

using NUnit.Framework;
using UnityEngine;
/// <summary>
/// Test the ThemeList class
/// </summary>
[TestFixture]
public class ThemeListTest
{
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.index = 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);
}
}
}
}