#nullable enable
using Content.IntegrationTests.NUnit.Operators;
using NUnit.Framework.Constraints;
using Robust.Shared.GameObjects;
using Robust.UnitTesting;
namespace Content.IntegrationTests.NUnit.Constraints;
///
/// Provides Has.Comp<T>(side),
/// a constraint that allows you to check for the presence of, or operate on, a component.
///
///
///
/// // Assert that the server sided entity myEntity has ItemComponent on the server.
/// Assert.That(myEntity, Has.Comp<ItemComponent>(Server));
///
///
public static class CompConstraintExtensions
{
extension(Has)
{
///
public static ResolvableConstraintExpression Comp(IIntegrationInstance instance)
where T : IComponent
{
return new ConstraintExpression().Comp(instance);
}
///
public static ResolvableConstraintExpression Comp(Type t, IIntegrationInstance instance)
{
return new ConstraintExpression().Comp(t, instance);
}
}
extension(ConstraintExpression expr)
{
///
/// Returns a new constraint which will either test for the existence of a
/// on the entity being tested or apply any following constraint to that component.
///
/// The component Type to check for.
/// The (i.e. Server or Client) on which to perform the test.
///
///
/// // Assert that the server-sided entity myEntity has an ItemComponent on the server.
/// Assert.That(myEntity, Has.Comp<ItemComponent>(Server));
///
/// // Assert that the server-sided entity myEntity has an ItemComponent with a Size field equal to "Small"
/// Assert.That(myEntity,
/// Has
/// .Comp<ItemComponent>(Server)
/// .Property(nameof(ItemComponent.Size))
/// .EqualTo("Small")
/// );
///
///
public ResolvableConstraintExpression Comp(IIntegrationInstance instance)
where T : IComponent
{
return expr.Append(new CompOperator(typeof(T), instance));
}
///
/// Returns a new constraint which will either test for the existence of a component of the specified type
/// on the entity being tested or apply any following constraint to that component.
///
/// The Type of the component to check for.
/// The (i.e. Server or Client) on which to perform the test.
///
///
/// // Assert that the server-sided entity myEntity has an ItemComponent on the server.
/// Assert.That(myEntity, Has.Comp(typeof(ItemComponent), Server));
///
/// // Assert that the server-sided entity myEntity has an ItemComponent with a Size field equal to "Small"
/// Assert.That(myEntity,
/// Has
/// .Comp(typeof(ItemComponent), Server)
/// .Property(nameof(ItemComponent.Size))
/// .EqualTo("Small")
/// );
///
///
public ResolvableConstraintExpression Comp(Type t, IIntegrationInstance instance)
{
return expr.Append(new CompOperator(t, instance));
}
}
}