1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 07:35:42 +00:00
X10D/X10D.Unity.Tests/Assets/Tests/SingletonTests.cs

44 lines
1.3 KiB
C#
Raw Normal View History

2022-05-13 08:54:00 +01:00
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace X10D.Unity.Tests
{
public class SingletonTests
{
[Test]
public void Singleton_ShouldReturnNewInstance_WhenNoInstanceExists()
2022-05-13 08:54:00 +01:00
{
TestBehaviour instance = Singleton<TestBehaviour>.Instance;
Assert.That(instance, Is.Not.Null);
Assert.That(instance.Flag);
2022-05-13 08:54:00 +01:00
}
[Test]
public void Singleton_ShouldReturnSameInstance_WhenAccessedTwice()
2022-05-13 08:54:00 +01:00
{
TestBehaviour instance = Singleton<TestBehaviour>.Instance;
Assert.That(instance, Is.Not.Null);
Assert.That(Singleton<TestBehaviour>.Instance, Is.EqualTo(instance));
2022-05-13 08:54:00 +01:00
}
[UnityTest]
public IEnumerator Singleton_ShouldReturnNewInstance_WhenDestroyed()
{
TestBehaviour instance = Singleton<TestBehaviour>.Instance;
Assert.That(instance, Is.Not.Null);
2022-05-13 08:54:00 +01:00
Object.Destroy(instance);
2022-05-13 08:54:00 +01:00
yield return null;
2022-05-13 08:54:00 +01:00
Assert.IsFalse(instance);
// ReSharper disable once HeuristicUnreachableCode
instance = Singleton<TestBehaviour>.Instance;
Assert.That(instance, Is.Not.Null);
2022-05-13 08:54:00 +01:00
Assert.IsTrue(instance.Flag);
}
}
}