Skip to content

Commit 73ba3bb

Browse files
committed
Updated tests and process to add components in correct order
1 parent 89a106c commit 73ba3bb

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/EcsRx.Tests/Framework/EntityTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,22 @@ public void should_remove_all_components_when_disposing()
146146
Assert.True(afterWasCalled);
147147
Assert.Empty(entity.Components);
148148
}
149+
150+
[Fact]
151+
public void should_add_components_in_parameter_order()
152+
{
153+
var fakeEntityId = 1;
154+
var fakeComponents = new IComponent[] {new TestComponentOne(), new TestComponentTwo(), new TestComponentThree()};
155+
156+
var componentRepository = Substitute.For<IComponentRepository>();
157+
var entity = new Entity(fakeEntityId, componentRepository);
158+
entity.AddComponents(fakeComponents);
159+
160+
Received.InOrder(() => {
161+
componentRepository.Add(fakeEntityId, fakeComponents[0]);
162+
componentRepository.Add(fakeEntityId, fakeComponents[1]);
163+
componentRepository.Add(fakeEntityId, fakeComponents[2]);
164+
});
165+
}
149166
}
150167
}

src/EcsRx/Entities/Entity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public Entity(int id, IComponentRepository componentRepository)
3636
public void AddComponents(params IComponent[] components)
3737
{
3838
var componentTypeIds = new int[components.Length];
39-
for (var i = components.Length - 1; i >= 0; i--)
39+
for (var i = 0; i < components.Length; i++)
4040
{ componentTypeIds[i] = ComponentRepository.Add(Id, components[i]); }
4141

4242
_onComponentsAdded.OnNext(componentTypeIds);

0 commit comments

Comments
 (0)