mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Robust.UnitTesting was both ALL tests for RT, and also API surface for content tests. Tests are now split into separate projects as appropriate, and the API side has also been split off.
71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
using System;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Robust.Server.ViewVariables;
|
|
using Robust.Server.ViewVariables.Traits;
|
|
using Robust.Shared.Analyzers;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Robust.UnitTesting.Server.ViewVariables
|
|
{
|
|
[Parallelizable]
|
|
[TestFixture]
|
|
internal sealed class ViewVariablesTraitMembersTest
|
|
{
|
|
[Test]
|
|
public void Test()
|
|
{
|
|
var ser = new Mock<IRobustSerializer>();
|
|
ser.Setup(p => p.CanSerialize(It.IsAny<Type>())).Returns(true);
|
|
|
|
var logger = new Mock<ISawmill>();
|
|
var session = new Mock<IViewVariablesSession>();
|
|
session.SetupGet(p => p.Object).Returns(new C());
|
|
session.SetupGet(p => p.ObjectType).Returns(typeof(C));
|
|
session.SetupGet(p => p.RobustSerializer).Returns(ser.Object);
|
|
|
|
var blob = new ViewVariablesTraitMembers(session.Object, logger.Object).DataRequest(new ViewVariablesRequestMembers());
|
|
Assert.That(blob, Is.TypeOf<ViewVariablesBlobMembers>());
|
|
|
|
var blobM = (ViewVariablesBlobMembers) blob!;
|
|
Assert.That(blobM.MemberGroups, Has.Count.EqualTo(2));
|
|
|
|
var group0 = blobM.MemberGroups[0];
|
|
var group1 = blobM.MemberGroups[1];
|
|
|
|
Assert.That(group0.groupName, Does.EndWith("+C"));
|
|
Assert.That(group1.groupName, Does.EndWith("+A"));
|
|
|
|
Assert.That(group0.groupMembers, Has.Count.EqualTo(2));
|
|
Assert.That(group1.groupMembers, Has.Count.EqualTo(1));
|
|
|
|
Assert.That(group0.groupMembers[0].Name, Is.EqualTo("Y"));
|
|
Assert.That(group0.groupMembers[1].Name, Is.EqualTo("Z"));
|
|
|
|
Assert.That(group1.groupMembers[0].Name, Is.EqualTo("X"));
|
|
}
|
|
|
|
#pragma warning disable 649
|
|
[Virtual]
|
|
private class A
|
|
{
|
|
[ViewVariables] public int X;
|
|
}
|
|
|
|
[Virtual]
|
|
private class B : A
|
|
{
|
|
public int Hidden { get; set; }
|
|
}
|
|
|
|
private sealed class C : B
|
|
{
|
|
[ViewVariables] public int Y { get; set; }
|
|
[ViewVariables] public string? Z { get; set; }
|
|
}
|
|
#pragma warning restore 649
|
|
}
|
|
}
|