using NUnit.Framework; using UnityEngine; /// /// Test the ThemeList class /// [TestFixture] public class ThemeListTest { private ThemeList themeList; /// /// Setup a ThemeList with all possible themes in the enum /// [SetUp] public void Setup_Minigame() { themeList = ScriptableObject.CreateInstance(); // 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(); // 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); } } } /// /// Check if all themes can be correctly set as current via SetCurrentTheme /// [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); } } } }