mirror of
https://github.com/corvax-team/ss14-wl.git
synced 2026-06-09 10:06:46 +02:00
9adb10d791
* Ports much of GameTest, minus all the WIP stuff. * remark. * EnsureCVar now adds test properties. * Some cleanup and functionality. * Ignore broken test. Needs fixed eventually. Also explicit context config. * TrackingIssue attribute. * oops * Pair config attribute. * Remove SystemAttribute in favor of using the EntitySystemManager dependency collection. * Ensure idleness. * More tests for tests. * More specific failure catching tests. * Reverse attribute resolution order so suite-wide attributes happen first. * Get rid of AffectedProperties again because I need to refactor PoolSettings for that. * Poke * Final cleanup pass. * Update Content.IntegrationTests/Fixtures/Attributes/RunOnSideAttribute.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * Update Content.IntegrationTests/Fixtures/Attributes/Side.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * Update Content.IntegrationTests/NUnit/Utilities/ITestExtensions.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * Fixes. * shut up nunit. * Make TrackingIssue a bit strict on purpose, so people don't put junk here. * Update Content.IntegrationTests/Tests/GameTestTests/DisconnectedDependencyTest.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * Address. --------- Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
54 lines
2.1 KiB
C#
54 lines
2.1 KiB
C#
#nullable enable
|
|
using System.Reflection;
|
|
|
|
namespace Content.IntegrationTests.Fixtures.Attributes;
|
|
|
|
/// <summary>
|
|
/// Configures the test pair using settings from the given type (by default the current test) and static property member.
|
|
/// </summary>
|
|
/// <param name="sourceType">The type to look up the member on, if any.</param>
|
|
/// <param name="sourceMember">The static property to read the settings from.</param>
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
|
public sealed class PairConfigAttribute(Type? sourceType, string sourceMember) : Attribute, IGameTestPairConfigModifier
|
|
{
|
|
public bool Exclusive => true;
|
|
|
|
public readonly Type? SourceType = sourceType;
|
|
public readonly string SourceMember = sourceMember;
|
|
|
|
private const BindingFlags PropertyBindingFlags = BindingFlags.Static
|
|
| BindingFlags.Public
|
|
| BindingFlags.NonPublic
|
|
| BindingFlags.FlattenHierarchy;
|
|
|
|
public PairConfigAttribute(string sourceMember) : this(null, sourceMember)
|
|
{
|
|
}
|
|
|
|
public void ApplyToPairSettings(GameTest test, ref PoolSettings settings)
|
|
{
|
|
var sourceType = SourceType ?? test.GetType();
|
|
|
|
var property = sourceType.GetProperty(SourceMember, PropertyBindingFlags);
|
|
|
|
if (property is null)
|
|
{
|
|
if (sourceType.GetField(SourceMember, PropertyBindingFlags) is not null)
|
|
{
|
|
throw new ArgumentException(
|
|
$"Couldn't find static property {SourceMember} on {sourceType.Name}, but could find a field. Only properties are allowed.");
|
|
}
|
|
|
|
throw new ArgumentException($"Couldn't find static property {SourceMember} on {sourceType.Name}");
|
|
}
|
|
|
|
if (!property.PropertyType.IsAssignableTo(typeof(PoolSettings)))
|
|
{
|
|
throw new ArgumentException(
|
|
$"{sourceType.Name}.{SourceMember} is not assignable to {nameof(PoolSettings)} and cannot be used.");
|
|
}
|
|
|
|
settings = (PoolSettings)property.GetValue(null)!;
|
|
}
|
|
}
|