This commit is contained in:
DrSmugleaf 2020-12-24 14:28:49 +01:00 committed by GitHub
parent 0063d30a85
commit b208ff4c20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 25 deletions

View File

@ -1,15 +1,8 @@
using System.IO;
using Content.Server.Utility;
using System;
using System.IO;
using Content.Shared.Alert;
using Content.Shared.Interfaces;
using NUnit.Framework;
using Robust.Shared.Interfaces.Log;
using Robust.Shared.Interfaces.Reflection;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.UnitTesting;
using YamlDotNet.RepresentationModel;
namespace Content.Tests.Shared.Alert
@ -17,7 +10,8 @@ namespace Content.Tests.Shared.Alert
[TestFixture, TestOf(typeof(AlertPrototype))]
public class AlertPrototypeTests : ContentUnitTest
{
private const string PROTOTYPE = @"- type: alert
private const string Prototypes = @"
- type: alert
alertType: HumanHealth
category: Health
icon: /Textures/Interface/Alerts/Human/human.rsi/human.png
@ -34,32 +28,50 @@ namespace Content.Tests.Shared.Alert
Assert.That((new AlertKey(AlertType.Buckled, AlertCategory.Health)), Is.EqualTo(AlertKey.ForCategory(AlertCategory.Health)));
}
[TestCase(0, "/Textures/Interface/Alerts/Human/human.rsi/human0.png")]
[TestCase(null, "/Textures/Interface/Alerts/Human/human.rsi/human0.png")]
[TestCase(1, "/Textures/Interface/Alerts/Human/human.rsi/human1.png")]
[TestCase(6, "/Textures/Interface/Alerts/Human/human.rsi/human6.png")]
[TestCase(7, "/Textures/Interface/Alerts/Human/human.rsi/human6.png")]
public void GetsIconPath(short? severity, string expected)
{
var alert = GetTestPrototype();
Assert.That(alert.GetIcon(severity), Is.EqualTo(new SpriteSpecifier.Texture(new ResourcePath(expected))));
}
[TestCase(null, "/Textures/Interface/Alerts/Human/human.rsi/human0.png")]
[TestCase(7, "/Textures/Interface/Alerts/Human/human.rsi/human1.png")]
public void GetsIconPathThrows(short? severity, string expected)
{
var alert = GetTestPrototype();
try
{
alert.GetIcon(severity);
}
catch (ArgumentException e)
{
Assert.Pass();
}
catch (Exception e)
{
Assert.Fail($"Unexpected exception: {e}");
}
}
private AlertPrototype GetTestPrototype()
{
using (TextReader stream = new StringReader(PROTOTYPE))
{
var yamlStream = new YamlStream();
yamlStream.Load(stream);
var document = yamlStream.Documents[0];
var rootNode = (YamlSequenceNode) document.RootNode;
var proto = (YamlMappingNode) rootNode[0];
var newReagent = new AlertPrototype();
newReagent.LoadFrom(proto);
return newReagent;
}
using TextReader stream = new StringReader(Prototypes);
var yamlStream = new YamlStream();
yamlStream.Load(stream);
var document = yamlStream.Documents[0];
var rootNode = (YamlSequenceNode) document.RootNode;
var proto = (YamlMappingNode) rootNode[0];
var newReagent = new AlertPrototype();
newReagent.LoadFrom(proto);
return newReagent;
}
}
}