mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 15:22:27 +02:00
* Move to Central Package Management. Allows us to store NuGet package versions all in one place. Yay! * Update NuGet packages and fix code for changes. Notable: Changes to ILVerify. Npgsql doesn't need hacks for inet anymore, now we need hacks to make the old code work with this new reality. NUnit's analyzers are already complaining and I didn't even update it to 4.x yet. TerraFX changed to GetLastSystemError so error handling had to be changed. Buncha APIs have more NRT annotations. * Remove dotnet-eng NuGet package source. I genuinely don't know what this was for, and Central Package Management starts throwing warnings about it, so YEET. * Fix double loading of assemblies due to ALC shenanigans. Due to how the "sideloading" code for the ModLoader was set up, it would first try to load Microsoft.Extensions.Primitives from next to the content dll. But we already have that library in Robust! Chaos ensues. We now try to forcibly prioritize loading from the default ALC first to avoid this. * Remove Robust.Physics project. Never used. * Remove erroneous NVorbis reference. Should be VorbisPizza and otherwise wasn't used. * Sandbox fixes * Remove unused unit test package references. Castle.Core and NUnit.ConsoleRunner. * Update NUnit to 4.0.1 This requires replacing all the old assertion methods because they removed them 🥲 * Mute CA1416 (platform check) errors TerraFX started annotating APIs with this and I can't be arsed to entertain this analyzer so out it goes. * Fine ya cranky, no more CPM for Robust.Client.Injectors * Changelog * Oh so that's what dotnet-eng was used for. Yeah ok that makes sense. * Central package management for remaining 2 robust projects * Ok that was a bad idea let's just use NUnit 3 on the analyzer test project * Oh right forgot to remove this one * Update to a newer version of RemoteExecutor * Disable RemoteExecutor test https://github.com/dotnet/arcade/issues/8483 Yeah this package is not well maintained and clearly we can't rely on it. * Fix immutable list serialization
139 lines
7.0 KiB
C#
139 lines
7.0 KiB
C#
using System.Linq;
|
|
using NUnit.Framework;
|
|
using Robust.Shared.Serialization.Manager;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.Serialization.Manager.Definition;
|
|
using Robust.Shared.Serialization.Markdown.Mapping;
|
|
using Robust.Shared.Serialization.Markdown.Value;
|
|
using Robust.Shared.Utility;
|
|
|
|
// ReSharper disable UnassignedGetOnlyAutoProperty
|
|
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
|
// ReSharper disable AccessToStaticMemberViaDerivedType
|
|
|
|
namespace Robust.UnitTesting.Shared.Serialization
|
|
{
|
|
public sealed partial class PropertyAndFieldDefinitionTest : SerializationTest
|
|
{
|
|
private const string GetOnlyPropertyName = "GetOnlyProperty";
|
|
private const string GetOnlyPropertyFieldTargetedName = "GetOnlyPropertyFieldTargeted";
|
|
private const string GetAndSetPropertyName = "GetAndSetProperty";
|
|
private const string FieldName = "Field";
|
|
private const string GetOnlyPropertyWithOtherAttributeFieldTargetedName =
|
|
"GetOnlyPropertyWithOtherAttributeFieldTargeted";
|
|
private const string GetOnlyPropertyFieldTargetedAndOtherAttributeName =
|
|
"GetOnlyPropertyFieldTargetedAndOtherAttribute";
|
|
|
|
[Test]
|
|
public void ParityTest()
|
|
{
|
|
var mapping = new MappingDataNode();
|
|
mapping.Add(GetOnlyPropertyName, new ValueDataNode("5"));
|
|
mapping.Add(GetOnlyPropertyFieldTargetedName, new ValueDataNode("10"));
|
|
mapping.Add(GetAndSetPropertyName, new ValueDataNode("15"));
|
|
mapping.Add(FieldName, new ValueDataNode("20"));
|
|
mapping.Add(GetOnlyPropertyWithOtherAttributeFieldTargetedName, new ValueDataNode("25"));
|
|
mapping.Add(GetOnlyPropertyFieldTargetedAndOtherAttributeName, new ValueDataNode("30"));
|
|
|
|
var definition = Serialization.Read<PropertyAndFieldDefinitionTestDefinition>(mapping, notNullableOverride: true);
|
|
|
|
Assert.That(definition, Is.Not.Null);
|
|
|
|
// Get only property with backing field, property targeted
|
|
Assert.That(definition!.GetOnlyProperty, Is.EqualTo(5));
|
|
|
|
var backingField = definition.GetType().GetBackingField(GetOnlyPropertyName);
|
|
Assert.That(backingField, Is.Not.Null);
|
|
|
|
var backingFieldValue = backingField!.GetValue(definition);
|
|
Assert.That(backingFieldValue, Is.EqualTo(5));
|
|
|
|
// Get only property with backing field, field targeted
|
|
Assert.That(definition.GetOnlyPropertyFieldTargeted, Is.EqualTo(10));
|
|
|
|
// Get and set property with backing field, property targeted
|
|
Assert.That(definition.GetAndSetProperty, Is.EqualTo(15));
|
|
|
|
// Field
|
|
Assert.That(definition.Field, Is.EqualTo(20));
|
|
|
|
// Get only property with backing field, property targeted with another attribute field targeted
|
|
Assert.That(definition.GetOnlyPropertyWithOtherAttributeFieldTargeted, Is.EqualTo(25));
|
|
|
|
var property = definition.GetType().GetProperty(GetOnlyPropertyWithOtherAttributeFieldTargetedName);
|
|
Assert.That(property, Is.Not.Null);
|
|
|
|
var propertyInfo = new SpecificPropertyInfo(property!);
|
|
Assert.That(propertyInfo.GetAttribute<DataFieldAttribute>(), Is.Not.Null);
|
|
Assert.That(propertyInfo.GetAttribute<AlwaysPushInheritanceAttribute>(), Is.Not.Null);
|
|
|
|
// We check for the property info properly finding field targeted attributes as
|
|
// well, otherwise we run the risk of the data field being targeted to the
|
|
// property but an additional attribute like AlwaysPushInheritance being targeted
|
|
// to the field, as was the case in EntityPrototype.
|
|
// And I don't want to debug that ever again.
|
|
Assert.That(propertyInfo.DeclaringType, Is.Not.Null);
|
|
|
|
var dataDefinition = ((SerializationManager) Serialization).GetDefinition(propertyInfo.DeclaringType!);
|
|
Assert.That(dataDefinition, Is.Not.Null);
|
|
|
|
var alwaysPushDataField = propertyInfo.GetAttribute<DataFieldAttribute>();
|
|
var propertyDefinition =
|
|
dataDefinition!.BaseFieldDefinitions.Single(e => e.Attribute.Equals(alwaysPushDataField));
|
|
var inheritanceBehaviour = propertyDefinition.InheritanceBehavior;
|
|
Assert.That(inheritanceBehaviour, Is.EqualTo(InheritanceBehavior.Always));
|
|
|
|
// Get only property with backing field, field targeted with another attribute property targeted
|
|
Assert.That(definition.GetOnlyPropertyFieldTargetedAndOtherAttribute, Is.EqualTo(30));
|
|
|
|
property = definition.GetType().GetProperty(GetOnlyPropertyFieldTargetedAndOtherAttributeName);
|
|
Assert.That(property, Is.Not.Null);
|
|
|
|
propertyInfo = new SpecificPropertyInfo(property!);
|
|
|
|
// Data field is targeted to the backing field
|
|
Assert.That(propertyInfo.GetAttribute<DataFieldAttribute>(), Is.Not.Null);
|
|
Assert.That(propertyInfo.GetBackingField()!.GetAttribute<DataFieldAttribute>(), Is.Null);
|
|
Assert.That(propertyInfo.GetAttribute<DataFieldAttribute>(true), Is.Not.Null);
|
|
|
|
// NeverPushInheritanceAttribute is targeted to the property
|
|
Assert.That(propertyInfo.GetAttribute<NeverPushInheritanceAttribute>(), Is.Not.Null);
|
|
Assert.That(propertyInfo.GetBackingField()!.GetAttribute<NeverPushInheritanceAttribute>(), Is.Null);
|
|
Assert.That(propertyInfo.GetAttribute<NeverPushInheritanceAttribute>(true), Is.Not.Null);
|
|
|
|
var neverPushDataField = propertyInfo.GetAttribute<DataFieldAttribute>();
|
|
propertyDefinition =
|
|
dataDefinition!.BaseFieldDefinitions.Single(e => e.Attribute.Equals(neverPushDataField));
|
|
inheritanceBehaviour = propertyDefinition.InheritanceBehavior;
|
|
dataDefinition = ((SerializationManager) Serialization).GetDefinition(property!.DeclaringType!);
|
|
Assert.That(dataDefinition, Is.Not.Null);
|
|
Assert.That(inheritanceBehaviour, Is.EqualTo(InheritanceBehavior.Never));
|
|
}
|
|
|
|
[Robust.Shared.Serialization.Manager.Attributes.DataDefinition]
|
|
public sealed partial class PropertyAndFieldDefinitionTestDefinition
|
|
{
|
|
[DataField(GetOnlyPropertyName)]
|
|
public int GetOnlyProperty { get; private set; }
|
|
|
|
[DataField(GetOnlyPropertyFieldTargetedName)]
|
|
public int GetOnlyPropertyFieldTargeted { get; private set; }
|
|
|
|
[DataField(GetAndSetPropertyName)]
|
|
public int GetAndSetProperty { get; set; }
|
|
|
|
[DataField(FieldName)]
|
|
// ReSharper disable once UnassignedField.Global
|
|
public int Field;
|
|
|
|
[DataField(GetOnlyPropertyWithOtherAttributeFieldTargetedName)]
|
|
[AlwaysPushInheritance]
|
|
public int GetOnlyPropertyWithOtherAttributeFieldTargeted { get; private set; }
|
|
|
|
[DataField(GetOnlyPropertyFieldTargetedAndOtherAttributeName)]
|
|
[NeverPushInheritance]
|
|
public int GetOnlyPropertyFieldTargetedAndOtherAttribute { get; private set; }
|
|
}
|
|
}
|
|
}
|