Resolve WES-117 "Persistent data handling"

This commit is contained in:
Dries Van Schuylenbergh
2023-04-04 17:00:47 +00:00
parent 3499e61bb0
commit 5f4408063f
82 changed files with 1963 additions and 1190 deletions

View File

@@ -1,36 +1,31 @@
using System.Collections;
using System.Linq;
using System.IO;
using NUnit.Framework;
using TMPro;
using System.Collections;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;
public class StartGamesTests
{
[UnityTest]
public IEnumerator BootWithUsersTest()
{
string path = $"{Application.persistentDataPath}/users.json";
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
using (StreamWriter writer = new StreamWriter(path))
{
writer.Write(oneUser);
}
string path = $"{Application.persistentDataPath}/unit_test_users.json";
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
File.WriteAllText(path, oneUser);
PersistentDataController.PATH = path;
PersistentDataController.GetInstance().Load();
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
SceneManager.LoadScene("Common/Scenes/Boot");
yield return new WaitForSeconds(1);
var userCreationScreen = (UserCreationScreen) GameObject.FindObjectOfType(typeof(UserCreationScreen));
var bootScreen = (BootScreen) GameObject.FindObjectOfType(typeof(BootScreen));
var mainMenuScreen = (MainMenuScreen) GameObject.FindObjectOfType(typeof(MainMenuScreen));
var userCreationScreen = (UserCreationScreen)GameObject.FindObjectOfType(typeof(UserCreationScreen));
var bootScreen = (BootScreen)GameObject.FindObjectOfType(typeof(BootScreen));
var mainMenuScreen = (MainMenuScreen)GameObject.FindObjectOfType(typeof(MainMenuScreen));
// yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
// if (Application.HasUserAuthorization(UserAuthorization.WebCam))
@@ -42,41 +37,37 @@ public class StartGamesTests
// Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat deze applicatie toegang heeft tot je webcam!");
// }
// else
if(0 >= WebCamTexture.devices.Length){
Debug.Log("no webcam");
Assert.IsNull(userCreationScreen);
if (0 >= WebCamTexture.devices.Length)
{
Assert.IsNull(mainMenuScreen);
Assert.IsNotNull(bootScreen);
Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat je webcam correct is aangesloten!");
}
else
else
{
Debug.Log("everything is there");
Assert.IsNull(bootScreen);
Assert.IsNull(userCreationScreen);
Assert.IsNotNull(mainMenuScreen);
}
Assert.IsNull(userCreationScreen);
}
[UnityTest]
public IEnumerator BootWithoutUsersTest()
{
// Arrange
string path = $"{Application.persistentDataPath}/users.json";
var oneUser = "{}";
using (StreamWriter writer = new StreamWriter(path))
{
writer.Write(oneUser);
}
string path = $"{Application.persistentDataPath}/unit_test_users.json";
string noUsers = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
File.WriteAllText(path, noUsers);
PersistentDataController.PATH = path;
PersistentDataController.GetInstance().Load();
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
SceneManager.LoadScene("Common/Scenes/Boot");
yield return new WaitForSeconds(1);
var userCreationScreen = (UserCreationScreen) GameObject.FindObjectOfType(typeof(UserCreationScreen));
var bootScreen = (BootScreen) GameObject.FindObjectOfType(typeof(BootScreen));
var mainMenuScreen = (MainMenuScreen) GameObject.FindObjectOfType(typeof(MainMenuScreen));
var userCreationScreen = (UserCreationScreen)GameObject.FindObjectOfType(typeof(UserCreationScreen));
var bootScreen = (BootScreen)GameObject.FindObjectOfType(typeof(BootScreen));
var mainMenuScreen = (MainMenuScreen)GameObject.FindObjectOfType(typeof(MainMenuScreen));
// yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
// if (Application.HasUserAuthorization(UserAuthorization.WebCam))
@@ -88,19 +79,18 @@ public class StartGamesTests
// Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat deze applicatie toegang heeft tot je webcam!");
// }
// else
if(0 >= WebCamTexture.devices.Length){
Debug.Log("no webcam");
if (0 >= WebCamTexture.devices.Length)
{
Assert.IsNull(userCreationScreen);
Assert.IsNull(mainMenuScreen);
Assert.IsNotNull(bootScreen);
Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat je webcam correct is aangesloten!");
} else
}
else
{
Debug.Log("no users");
Assert.IsNull(bootScreen);
Assert.IsNull(mainMenuScreen);
Assert.IsNotNull(userCreationScreen);
}
Assert.IsNull(mainMenuScreen);
}
}