Skip to content

Commit b436c8f

Browse files
committed
Updated tests to reflect new type id usage internally
1 parent 2f9597a commit b436c8f

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

src/EcsRx.PerformanceTests/GroupPerformanceScenario.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void GlobalSetup()
4646
var entityFactory = new DefaultEntityFactory(new IdPool(), componentRepository);
4747
var poolFactory = new DefaultEntityCollectionFactory(entityFactory);
4848
var observableGroupFactory = new DefaultObservableObservableGroupFactory();
49-
_entityCollectionManager = new EntityCollectionManager(poolFactory, observableGroupFactory);
49+
_entityCollectionManager = new EntityCollectionManager(poolFactory, observableGroupFactory, componentLookup);
5050

5151
_availableComponents = _groupFactory.GetComponentTypes
5252
.Select(x => Activator.CreateInstance(x) as IComponent)

src/EcsRx.Tests/Framework/EntityTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public void should_raise_event_when_removing_component_that_exists()
3333
var entity = new Entity(1, componentRepository);
3434
var dummyComponent = Substitute.For<IComponent>();
3535

36-
componentRepository.Has(Arg.Any<int>(), dummyComponent.GetType()).Returns(true);
36+
componentRepository.Has(Arg.Any<int>(), 1).Returns(true);
37+
componentRepository.GetTypesFor(Arg.Any<Type>()).Returns(new []{1});
3738

3839
var beforeWasCalled = false;
3940
var afterWasCalled = false;
@@ -119,24 +120,23 @@ public void should_remove_all_components_when_disposing()
119120

120121
var componentRepository = Substitute.For<IComponentRepository>();
121122
componentRepository.GetAll(fakeEntityId).Returns(fakeComponents);
122-
123-
componentRepository.Has(Arg.Any<int>(), Arg.Any<Type>()).Returns(true);
123+
componentRepository.GetTypesFor(Arg.Any<Type[]>()).Returns(new []{1,2});
124+
componentRepository.Has(Arg.Any<int>(), Arg.Any<int>()).Returns(true);
124125

125126
var entity = new Entity(fakeEntityId, componentRepository);
126127

127128
var beforeWasCalled = false;
128129
var afterWasCalled = false;
130+
var expectedRange = Enumerable.Range(1, 2);
129131
entity.ComponentsRemoving.Subscribe(x =>
130132
{
131133
beforeWasCalled = true;
132-
var fakeComponentTypes = fakeComponents.Select(y => y.GetType());
133-
Assert.All(x, y => fakeComponentTypes.Contains(y));
134+
Assert.All(x, y => expectedRange.Contains(y));
134135
});
135136
entity.ComponentsRemoved.Subscribe(x =>
136137
{
137138
afterWasCalled = true;
138-
var fakeComponentTypes = fakeComponents.Select(y => y.GetType());
139-
Assert.All(x, y => fakeComponentTypes.Contains(y));
139+
Assert.All(x, y => expectedRange.Contains(y));
140140
});
141141

142142
entity.Dispose();

src/EcsRx.Tests/Framework/Observables/ObservableGroupTests.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class ObservableGroupTests
2222
public void should_include_entity_snapshot_on_creation()
2323
{
2424
var mockCollectionNotifier = Substitute.For<INotifyingEntityCollection>();
25-
var accessorToken = new ObservableGroupToken(new Type[]{ typeof(TestComponentOne) }, new Type[0], "default");
25+
var accessorToken = new ObservableGroupToken(new[]{1}, new int[0], "default");
2626

2727
var applicableEntity1 = Substitute.For<IEntity>();
2828
var applicableEntity2 = Substitute.For<IEntity>();
@@ -32,9 +32,9 @@ public void should_include_entity_snapshot_on_creation()
3232
applicableEntity2.Id.Returns(2);
3333
notApplicableEntity1.Id.Returns(3);
3434

35-
applicableEntity1.HasComponent(Arg.Any<Type>()).Returns(true);
36-
applicableEntity2.HasComponent(Arg.Any<Type>()).Returns(true);
37-
notApplicableEntity1.HasComponent(Arg.Any<Type>()).Returns(false);
35+
applicableEntity1.HasComponent(Arg.Any<int>()).Returns(true);
36+
applicableEntity2.HasComponent(Arg.Any<int>()).Returns(true);
37+
notApplicableEntity1.HasComponent(Arg.Any<int>()).Returns(false);
3838

3939
var dummyEntitySnapshot = new List<IEntity>
4040
{
@@ -60,17 +60,17 @@ public void should_include_entity_snapshot_on_creation()
6060
public void should_add_entity_and_raise_event_when_applicable_entity_added()
6161
{
6262
var collectionName = "default";
63-
var accessorToken = new ObservableGroupToken(new[] { typeof(TestComponentOne), typeof(TestComponentTwo) }, new Type[0], collectionName);
63+
var accessorToken = new ObservableGroupToken(new[] { 1,2 }, new int[0], collectionName);
6464
var mockCollection = Substitute.For<IEntityCollection>();
6565
mockCollection.Name.Returns(collectionName);
6666

6767
var applicableEntity = Substitute.For<IEntity>();
6868
applicableEntity.Id.Returns(1);
69-
applicableEntity.HasComponent(Arg.Is<Type>(x => accessorToken.LookupGroup.RequiredComponents.Contains(x))).Returns(true);
69+
applicableEntity.HasComponent(Arg.Is<int>(x => accessorToken.LookupGroup.RequiredComponents.Contains(x))).Returns(true);
7070

7171
var unapplicableEntity = Substitute.For<IEntity>();
7272
unapplicableEntity.Id.Returns(2);
73-
unapplicableEntity.HasComponent(Arg.Is<Type>(x => accessorToken.LookupGroup.RequiredComponents.Contains(x))).Returns(false);
73+
unapplicableEntity.HasComponent(Arg.Is<int>(x => accessorToken.LookupGroup.RequiredComponents.Contains(x))).Returns(false);
7474

7575
var mockCollectionNotifier = Substitute.For<INotifyingEntityCollection>();
7676

@@ -99,7 +99,7 @@ public void should_add_entity_and_raise_event_when_applicable_entity_added()
9999
public void should_add_entity_and_raise_event_when_components_match_group()
100100
{
101101
var collectionName = "default";
102-
var accessorToken = new ObservableGroupToken(new[] { typeof(TestComponentOne) }, new []{typeof(TestComponentTwo)}, collectionName);
102+
var accessorToken = new ObservableGroupToken(new[] { 1 }, new []{ 2 }, collectionName);
103103
var mockCollection = Substitute.For<IEntityCollection>();
104104
mockCollection.Name.Returns(collectionName);
105105

@@ -131,14 +131,14 @@ public void should_add_entity_and_raise_event_when_components_match_group()
131131
public void should_remove_entity_and_raise_events_when_entity_removed_with_components()
132132
{
133133
var collectionName = "default";
134-
var accessorToken = new ObservableGroupToken(new[] { typeof(TestComponentOne), typeof(TestComponentTwo) }, new Type[0], collectionName);
134+
var accessorToken = new ObservableGroupToken(new[] { 1, 2 }, new int[0], collectionName);
135135
var mockCollection = Substitute.For<IEntityCollection>();
136136
mockCollection.Name.Returns(collectionName);
137137

138138
var applicableEntity = Substitute.For<IEntity>();
139139
applicableEntity.Id.Returns(1);
140-
applicableEntity.HasComponent(Arg.Is<Type>(x => accessorToken.LookupGroup.RequiredComponents.Contains(x))).Returns(true);
141-
applicableEntity.HasComponent(Arg.Is<Type>(x => accessorToken.LookupGroup.ExcludedComponents.Contains(x))).Returns(false);
140+
applicableEntity.HasComponent(Arg.Is<int>(x => accessorToken.LookupGroup.RequiredComponents.Contains(x))).Returns(true);
141+
applicableEntity.HasComponent(Arg.Is<int>(x => accessorToken.LookupGroup.ExcludedComponents.Contains(x))).Returns(false);
142142

143143
var mockCollectionNotifier = Substitute.For<INotifyingEntityCollection>();
144144

@@ -156,7 +156,7 @@ public void should_remove_entity_and_raise_events_when_entity_removed_with_compo
156156
var wasRemovedCalled = 0;
157157
observableGroup.OnEntityRemoved.Subscribe(x => wasRemovedCalled++);
158158

159-
componentRemoving.OnNext(new ComponentsChangedEvent(null, applicableEntity, new[]{typeof(TestComponentOne)}));
159+
componentRemoving.OnNext(new ComponentsChangedEvent(null, applicableEntity, new[]{1}));
160160

161161
Assert.Contains(applicableEntity, observableGroup.CachedEntities.Values);
162162
Assert.Equal(1, wasRemovingCalled);
@@ -174,14 +174,14 @@ public void should_remove_entity_and_raise_events_when_entity_removed_with_compo
174174
public void should_remove_entity_and_raise_event_when_no_longer_matches_group()
175175
{
176176
var collectionName = "default";
177-
var accessorToken = new ObservableGroupToken(new[] { typeof(TestComponentOne), typeof(TestComponentTwo) }, new Type[0], collectionName);
177+
var accessorToken = new ObservableGroupToken(new[] { 1,2 }, new int[0], collectionName);
178178
var mockCollection = Substitute.For<IEntityCollection>();
179179
mockCollection.Name.Returns(collectionName);
180180

181181
var applicableEntity = Substitute.For<IEntity>();
182182
applicableEntity.Id.Returns(1);
183-
applicableEntity.HasComponent(Arg.Is<Type>(x => accessorToken.LookupGroup.RequiredComponents.Contains(x))).Returns(true);
184-
applicableEntity.HasComponent(Arg.Is<Type>(x => accessorToken.LookupGroup.ExcludedComponents.Contains(x))).Returns(false);
183+
applicableEntity.HasComponent(Arg.Is<int>(x => accessorToken.LookupGroup.RequiredComponents.Contains(x))).Returns(true);
184+
applicableEntity.HasComponent(Arg.Is<int>(x => accessorToken.LookupGroup.ExcludedComponents.Contains(x))).Returns(false);
185185

186186
var mockCollectionNotifier = Substitute.For<INotifyingEntityCollection>();
187187

@@ -203,8 +203,8 @@ public void should_remove_entity_and_raise_event_when_no_longer_matches_group()
203203

204204
applicableEntity.HasAnyComponents(accessorToken.LookupGroup.RequiredComponents).Returns(false);
205205
applicableEntity.HasAllComponents(accessorToken.LookupGroup.RequiredComponents).Returns(false);
206-
componentRemoving.OnNext(new ComponentsChangedEvent(mockCollection, applicableEntity, new[]{ typeof(TestComponentOne) }));
207-
componentRemoved.OnNext(new ComponentsChangedEvent(mockCollection, applicableEntity, new[]{ typeof(TestComponentOne) }));
206+
componentRemoving.OnNext(new ComponentsChangedEvent(mockCollection, applicableEntity, new[]{ 1 }));
207+
componentRemoved.OnNext(new ComponentsChangedEvent(mockCollection, applicableEntity, new[]{ 1 }));
208208

209209
Assert.DoesNotContain(applicableEntity, observableGroup.CachedEntities.Values);
210210
Assert.Equal(1, wasRemovingCalled);

src/EcsRx.Tests/Framework/SanityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private IEntityCollectionManager CreateCollectionManager()
3131
var entityFactory = new DefaultEntityFactory(new IdPool(), componentRepository);
3232
var collectionFactory = new DefaultEntityCollectionFactory(entityFactory);
3333
var observableGroupFactory = new DefaultObservableObservableGroupFactory();
34-
return new EntityCollectionManager(collectionFactory, observableGroupFactory);
34+
return new EntityCollectionManager(collectionFactory, observableGroupFactory, componentLookupType);
3535
}
3636

3737
private SystemExecutor CreateExecutor(IEntityCollectionManager entityCollectionManager)

src/EcsRx/Groups/Observable/ObservableGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public ObservableGroup(ObservableGroupToken token, IEnumerable<IEntity> initialE
3535
_onEntityRemoved = new Subject<IEntity>();
3636
_onEntityRemoving = new Subject<IEntity>();
3737

38-
CachedEntities = initialEntities.Where(x => Token.LookupGroup.Matches(x)).ToDictionary(x => x.Id, x => x);
3938
Subscriptions = new List<IDisposable>();
39+
CachedEntities = initialEntities.Where(x => Token.LookupGroup.Matches(x)).ToDictionary(x => x.Id, x => x);
4040

4141
MonitorEntityChanges();
4242
}

0 commit comments

Comments
 (0)