mirror of
https://github.com/Earth-Genesis-Games/Ajedrez_Purgatorio.git
synced 2026-09-11 09:47:35 +00:00
87 lines
2.5 KiB
C#
87 lines
2.5 KiB
C#
using NUnit.Framework;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
|
|
/// <summary>
|
|
/// Cobertura de las ramas de error de CampaignConfig.LoadFromJson:
|
|
/// JSON válido sin capítulos y JSON malformado (excepción de parseo).
|
|
/// Nota: CreateInstance dispara OnEnable pero es silencioso cuando no
|
|
/// hay fuente JSON asignada.
|
|
/// </summary>
|
|
[TestFixture]
|
|
[Category("Unit")]
|
|
[Category("Campaign")]
|
|
[Category("FastTests")]
|
|
public class CampaignConfigCoverageTests
|
|
{
|
|
[TearDown]
|
|
public void Teardown()
|
|
{
|
|
LogAssert.ignoreFailingMessages = false;
|
|
}
|
|
|
|
private CampaignConfig CreateUnloadedConfig()
|
|
{
|
|
// CreateInstance dispara OnEnable → LoadFromJson sin fuente.
|
|
// OnEnable es silencioso cuando no hay fuente asignada (sin error log).
|
|
return ScriptableObject.CreateInstance<CampaignConfig>();
|
|
}
|
|
|
|
[Test]
|
|
public void LoadFromJson_EmptyChapters_LogsErrorAndIsNotLoaded()
|
|
{
|
|
var config = CreateUnloadedConfig();
|
|
try
|
|
{
|
|
config.SetJsonSource(new TextAsset("{\"campaignId\":\"_test\",\"chapters\":[]}"));
|
|
|
|
LogAssert.Expect(LogType.Error, "[CampaignConfig] El JSON no contiene capítulos válidos.");
|
|
config.LoadFromJson();
|
|
|
|
Assert.IsFalse(config.IsLoaded);
|
|
Assert.AreEqual(0, config.ChapterCount);
|
|
}
|
|
finally
|
|
{
|
|
Object.DestroyImmediate(config);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void LoadFromJson_MalformedJson_CatchesExceptionAndIsNotLoaded()
|
|
{
|
|
var config = CreateUnloadedConfig();
|
|
try
|
|
{
|
|
config.SetJsonSource(new TextAsset("{capítulos inválidos::"));
|
|
LogAssert.ignoreFailingMessages = true; // catch + fallback: textos variables
|
|
config.LoadFromJson();
|
|
LogAssert.ignoreFailingMessages = false;
|
|
|
|
Assert.IsFalse(config.IsLoaded);
|
|
}
|
|
finally
|
|
{
|
|
Object.DestroyImmediate(config);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void GetChapterById_WithoutLoadedData_LogsErrorAndReturnsNull()
|
|
{
|
|
var config = CreateUnloadedConfig();
|
|
try
|
|
{
|
|
LogAssert.Expect(LogType.Error, "[CampaignConfig] Datos no cargados.");
|
|
Assert.IsNull(config.GetChapterById("cualquiera"));
|
|
|
|
LogAssert.Expect(LogType.Error, "[CampaignConfig] Índice de capítulo inválido: 0");
|
|
Assert.IsNull(config.GetChapter(0));
|
|
}
|
|
finally
|
|
{
|
|
Object.DestroyImmediate(config);
|
|
}
|
|
}
|
|
}
|