Resolve WES-187 "Unit tests account and system"
This commit is contained in:
committed by
Jerome Coudron
parent
c4b6c60288
commit
b9bbef8dcf
61
Assets/Common/Tests/EditMode/ThemeListTests.cs
Normal file
61
Assets/Common/Tests/EditMode/ThemeListTests.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Test the ThemeList class
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class ThemeListTests
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user