How to Unit Test Aspects?

I’m trying to write a unit test for an aspect GridAspect

    public readonly partial struct GridAspect : IAspect
    {
       
        private readonly RefRW<GridItems> _gridItems;
       
        private readonly RefRO<GridProperties> _gridProperties;

        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        private Entity this[int index]
        {
            get => _gridItems.ValueRO.Items[index];

            set => _gridItems.ValueRW.Items[index] = value;
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool TryGetItem(int index, out Entity item)
        {
            if (InArray(index))
            {
                item = this[index];
                return true;
            }
            item = default;
            return false;
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <param name="entity"></param>
        public bool TrySetItem(int index, Entity entity)
        {
            if (InArray(index))
            {
                this[index] = entity;
                return true;
            }
            return false;
        }
       
        /// <summary>
        /// Check to make sure index is in the 
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public bool InArray(int index) => 0 <= index && index < Count;

    }

But Im not sure how to mock out RefRW RefRO or how to set the read-only fields

Is there a framework for testing Aspects?

Hey, I leverage a “Test World” in my unit tests so I can use a lot of the different objects in ECS. Here is a simple way to create and test a simple aspect.

public class SimpleTests {
    private EntityManager _entityManager;

    [SetUp]
    public void SetUp() {
        World.DefaultGameObjectInjectionWorld = new World("Test World");
        _entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
    }
  
    [TearDown]
    public void TearDown() {
        World.DefaultGameObjectInjectionWorld.Dispose();
    }
  
    [Test]
    public void TestAspectPosition() {
        var entity = _entityManager.CreateEntity();
        _entityManager.AddComponentData(entity, new Position {
            Value = new float3(0, 0, 0),
        });

        var aspect = _entityManager.GetAspectRO<PositionAspect>(entity);
        var data = aspect.GetPosition();

        Assert.AreEqual(new float3(0, 0, 0), data);
    }
}