65 lines
2.3 KiB
C#
65 lines
2.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
|
|
namespace NEG.Utils.Achievments.Tests
|
|
{
|
|
public class BackendTests
|
|
{
|
|
//If stests start to fail first make sure these are correct in relation to test config asset
|
|
public const string configLabel = "TestAchievments";
|
|
public const string backendLabel = "AchievmentsLocalTests";
|
|
public const string saveLocation = "./LocalAchievments/Tests.json";
|
|
|
|
public const string AchievmentIdToggle = "TOGGLE";
|
|
public const string AchievmentIdInt = "INT";
|
|
public const string AchievmentIdFloat = "FLOAT";
|
|
|
|
[OneTimeSetUp]
|
|
public void OneTtimeSetup()
|
|
{
|
|
Achievment.BackendLabel = backendLabel;
|
|
Achievment.ConfigLabel = configLabel;
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
Achievment.NullifyInstance();
|
|
if (File.Exists(saveLocation))
|
|
{
|
|
File.Delete(saveLocation);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void ReadWrite()
|
|
{
|
|
#if ACHIEVMENT_BACKEND_TESTS
|
|
//We assume that the achievments are set correctly because otherwise other tests would fail
|
|
Achievment.SetToggleAchivment(AchievmentIdToggle);
|
|
Achievment.SetIntProgress(AchievmentIdInt, 20);
|
|
Achievment.SetFloatProgress(AchievmentIdFloat, 20);
|
|
|
|
//We need to assume NullifyInstance works correctly because we dont have access to an AchievmentManager which has not syncked yet
|
|
Achievment.NullifyInstance();
|
|
|
|
Assert.IsTrue(Achievment.IsCompleted(AchievmentIdToggle));
|
|
Assert.AreEqual(Achievment.GetIntProgress(AchievmentIdInt), 20);
|
|
Assert.AreEqual(Achievment.GetFloatProgress(AchievmentIdFloat), 20, 0f);
|
|
|
|
Achievment.SetIntProgress(AchievmentIdInt, 30);
|
|
Achievment.SetFloatProgress(AchievmentIdFloat, 30);
|
|
|
|
Achievment.NullifyInstance();
|
|
|
|
Assert.AreEqual(Achievment.GetIntProgress(AchievmentIdInt), 30);
|
|
Assert.AreEqual(Achievment.GetFloatProgress(AchievmentIdFloat), 30, 0f);
|
|
#else
|
|
throw new System.Exception("Backend tests are not enabled. To enable Backend tests add define ACHIEVMENT_BACKEND_TESTS");
|
|
#endif
|
|
}
|
|
}
|
|
} |