public void should_get_all_components_for_entity() { var expectedSize = 10; var fakeEntityId = 1; var otherEntityId = 2; var fakeComponent1 = new TestComponentOne(); var fakeComponent2 = new TestComponentThree(); var fakeComponentTypes = new Dictionary <Type, int> { { typeof(TestComponentOne), 0 }, { typeof(TestComponentTwo), 1 }, { typeof(TestComponentThree), 2 } }; var mockComponentLookup = Substitute.For <IComponentTypeLookup>(); mockComponentLookup.GetAllComponentTypes().Returns(fakeComponentTypes); var database = new ComponentDatabase(mockComponentLookup, expectedSize); database.Add(0, fakeEntityId, fakeComponent1); database.Add(2, fakeEntityId, fakeComponent2); database.Add(0, otherEntityId, new TestComponentOne()); database.Add(1, otherEntityId, new TestComponentTwo()); database.Add(2, otherEntityId, new TestComponentThree()); var allComponents = database.GetAll(fakeEntityId).ToArray(); Assert.True(allComponents.Contains(fakeComponent1)); Assert.True(allComponents.Contains(fakeComponent2)); Assert.Equal(allComponents.Length, 2); }
public void should_correctly_remove_all_components_for_entity() { var expectedSize = 10; var fakeEntityId = 1; var otherEntityId = 2; var fakeComponentTypes = new Dictionary <Type, int> { { typeof(TestComponentOne), 0 }, { typeof(TestComponentTwo), 1 }, { typeof(TestComponentThree), 2 } }; var mockComponentLookup = Substitute.For <IComponentTypeLookup>(); mockComponentLookup.GetAllComponentTypes().Returns(fakeComponentTypes); var database = new ComponentDatabase(mockComponentLookup, expectedSize); database.Add(0, fakeEntityId, new TestComponentOne()); database.Add(0, fakeEntityId, new TestComponentTwo()); database.Add(0, fakeEntityId, new TestComponentThree()); database.Add(0, otherEntityId, new TestComponentOne()); database.Add(1, otherEntityId, new TestComponentOne()); database.RemoveAll(fakeEntityId); Assert.False(database.Has(0, fakeEntityId)); Assert.False(database.Has(1, fakeEntityId)); Assert.False(database.Has(2, fakeEntityId)); var allComponents = database.GetAll(fakeEntityId); Assert.Empty(allComponents); }