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); }
public void should_correctly_identify_if_component_exists_for_entity() { var expectedSize = 10; var fakeEntityId = 1; var otherEntityId = 2; var fakeComponent1 = new TestComponentOne(); 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(0, otherEntityId, new TestComponentOne()); database.Add(1, otherEntityId, new TestComponentOne()); var hasComponent0 = database.Has(0, fakeEntityId); Assert.True(hasComponent0); var hasComponent1 = database.Has(1, fakeEntityId); Assert.False(hasComponent1); }