diff options
author | chai <215380520@qq.com> | 2024-06-03 10:15:45 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-06-03 10:15:45 +0800 |
commit | acea7b2e728787a0d83bbf83c8c1f042d2c32e7e (patch) | |
tree | 0bfec05c1ca2d71be2c337bcd110a0421f19318b /Plugins/MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/ComponentMapperTests.cs | |
parent | 88febcb02bf127d961c6471d9e846c0e1315f5c3 (diff) |
+ plugins project
Diffstat (limited to 'Plugins/MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/ComponentMapperTests.cs')
-rw-r--r-- | Plugins/MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/ComponentMapperTests.cs | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/ComponentMapperTests.cs b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/ComponentMapperTests.cs new file mode 100644 index 0000000..54fab04 --- /dev/null +++ b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/ComponentMapperTests.cs @@ -0,0 +1,95 @@ +using Xunit; + +namespace MonoGame.Extended.Entities.Tests +{ + public class ComponentMapperTests + { + [Fact] + public void CreateComponentMapper() + { + var mapper = new ComponentMapper<object>(0, _ => {}); + + Assert.Equal(typeof(object), mapper.ComponentType); + Assert.Empty(mapper.Components); + } + + [Fact] + public void OnPut() + { + const int entityId = 3; + + var mapper = new ComponentMapper<Transform2>(1, _ => { }); + var component = new Transform2(); + + mapper.OnPut += (entId) => + { + Assert.Equal(entityId, entId); + Assert.Same(component, mapper.Get(entityId)); + }; + + mapper.Put(entityId, component); + } + + [Fact] + public void PutAndGetComponent() + { + const int entityId = 3; + + var mapper = new ComponentMapper<Transform2>(1, _ => { }); + var component = new Transform2(); + + mapper.Put(entityId, component); + + Assert.Equal(typeof(Transform2), mapper.ComponentType); + Assert.True(mapper.Components.Count >= 1); + Assert.Same(component, mapper.Get(entityId)); + } + + [Fact] + public void OnDelete() + { + const int entityId = 1; + + var mapper = new ComponentMapper<Transform2>(2, _ => { }); + var component = new Transform2(); + + mapper.OnDelete += (entId) => + { + Assert.Equal(entityId, entId); + Assert.False(mapper.Has(entityId)); + }; + + mapper.Put(entityId, component); + mapper.Delete(entityId); + } + + [Fact] + public void DeleteComponent() + { + const int entityId = 1; + + var mapper = new ComponentMapper<Transform2>(2, _ => { }); + var component = new Transform2(); + + mapper.Put(entityId, component); + mapper.Delete(entityId); + + Assert.False(mapper.Has(entityId)); + } + + [Fact] + public void HasComponent() + { + const int entityId = 0; + + var mapper = new ComponentMapper<Transform2>(3, _ => { }); + var component = new Transform2(); + + Assert.False(mapper.Has(entityId)); + + mapper.Put(entityId, component); + + Assert.True(mapper.Has(entityId)); + } + } +} |