using NUnit.Framework;
using UnityEngine;
///
/// Test the CourseList class
///
[TestFixture]
public class CourseListTests
{
///
/// Reference to the courses list, for quick access
///
private CourseList courseList;
///
/// Setup a CourseList with all possible courses in the enum
///
[SetUp]
public void Setup_Minigame()
{
courseList = ScriptableObject.CreateInstance();
// Add a course 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(CourseIndex).GetFields())
{
if (field.IsLiteral)
{
CourseIndex value = (CourseIndex)field.GetValue(null);
string name = field.Name;
Course course = ScriptableObject.CreateInstance();
// This is all we will need to distinguish
course.index = value;
course.title = name;
// Insert in front to guarantee that courseIndex will not line up with listIndex
courseList.courses.Insert(0, course);
}
}
}
///
/// Check if all courses can be correctly fetched via GetCourseByIndex
///
[Test]
public void TestGetMinigameByIndex()
{
foreach (var field in typeof(CourseIndex).GetFields())
{
if (field.IsLiteral)
{
CourseIndex value = (CourseIndex)field.GetValue(null);
string name = field.Name;
Course m = courseList.GetCourseByIndex(value);
Assert.AreEqual(m.title, name);
}
}
}
///
/// Check if all courses can be correctly set as current via SetCurrentCourse
///
[Test]
public void TestSetCurrentMinigame()
{
foreach (var field in typeof(CourseIndex).GetFields())
{
if (field.IsLiteral)
{
CourseIndex value = (CourseIndex)field.GetValue(null);
string name = field.Name;
courseList.SetCurrentCourse(value);
// Fetch the current course and check if its name is the same as the one we made into the current one
Course m = courseList.courses[courseList.currentCourseIndex];
Assert.AreEqual(m.title, name);
}
}
}
}