91 lines
2.8 KiB
C#
91 lines
2.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
using NEG.Utils.Achivments;
|
|
|
|
public class ConfigTests
|
|
{
|
|
public const string AchivmentDefOnlyLabel = "TestAchivments";
|
|
public const string AchivmentSetLabel = "TestAchivments";
|
|
public const string AchivmentProgressLabel = "TestAchivments";
|
|
|
|
public const string NoProgressAchivment = "NO_PROGRESS";
|
|
public const string WithProgressAchivment = "WITH_PROGRESS";
|
|
|
|
[Test]
|
|
public void AchivmentDefOnly()
|
|
{
|
|
AchivmentManager manager = AchivmentManager.Builder.FromLabeledConfig(AchivmentDefOnlyLabel).Build();
|
|
|
|
//Shoud not throw
|
|
manager.SetAchivment(NoProgressAchivment);
|
|
//Shoud not throw
|
|
manager.SetAchivment(WithProgressAchivment);
|
|
}
|
|
|
|
[Test]
|
|
public void AchivmentSet()
|
|
{
|
|
var callbackTester = new TestCallbackRereiver();
|
|
|
|
AchivmentManager manager = AchivmentManager.Builder.FromLabeledConfig(AchivmentDefOnlyLabel)
|
|
.WithCallbackReciever(callbackTester)
|
|
.Build();
|
|
|
|
//Shoud not throw
|
|
manager.SetAchivment(NoProgressAchivment);
|
|
|
|
//Shoud not throw
|
|
manager.SetAchivment(WithProgressAchivment);
|
|
}
|
|
|
|
[Test]
|
|
public void AchivmentProgress()
|
|
{
|
|
AchivmentManager manager = AchivmentManager.Builder.FromLabeledConfig(AchivmentProgressLabel).Build();
|
|
}
|
|
|
|
private class TestCallbackRereiver : IAchivmentCallbackReciever
|
|
{
|
|
public int LastProgressUpdated { get; private set; } = -1;
|
|
public string LastIdUpdated { get; private set; } = null;
|
|
public string LastIdSet { get; private set; } = null;
|
|
|
|
public void SetAchivment(AchivmentData achivment)
|
|
{
|
|
LastIdSet = achivment.Achivment.Id;
|
|
}
|
|
|
|
public void SetAchivmentProgress(AchivmentData achivment, int progress)
|
|
{
|
|
LastIdUpdated = achivment.Achivment.Id;
|
|
LastProgressUpdated = progress;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
LastIdSet = null;
|
|
LastIdUpdated = null;
|
|
LastProgressUpdated = -1;
|
|
}
|
|
|
|
public void TestSetCallbackst(AchivmentManager manager, string id)
|
|
{
|
|
manager.SetAchivment(id);
|
|
Assert.AreEqual(id, LastIdSet);
|
|
Assert.AreEqual(null, LastIdUpdated);
|
|
Assert.AreEqual(-1, LastProgressUpdated);
|
|
}
|
|
|
|
public void TestProgressCallback(AchivmentManager manager, string id, int progress, int expectedProgress, bool shouldSet)
|
|
{
|
|
manager.AddProgress(id, progress);
|
|
//Assert.AreEqual(, LastIdSet);
|
|
Assert.AreEqual(null, LastIdUpdated);
|
|
Assert.AreEqual(-1, LastProgressUpdated);
|
|
}
|
|
}
|
|
}
|