public void should_raise_event_when_creating_entity() { var mockEventSystem = Substitute.For <IEventSystem>(); var mockEntityFactory = Substitute.For <IEntityFactory>(); mockEntityFactory.Create(null).Returns(new Entity(Guid.NewGuid(), mockEventSystem)); var entityCollection = new EntityCollection("", mockEntityFactory, mockEventSystem); var entity = entityCollection.CreateEntity(); mockEventSystem.Received().Publish(Arg.Is <EntityAddedEvent>(x => x.Entity == entity && x.EntityCollection == entityCollection)); }
public void should_add_created_entity_into_the_collection() { var mockEventSystem = Substitute.For <IEventSystem>(); var mockEntityFactory = Substitute.For <IEntityFactory>(); mockEntityFactory.Create(null).Returns(new Entity(Guid.NewGuid(), mockEventSystem)); var entityCollection = new EntityCollection("", mockEntityFactory, mockEventSystem); var entity = entityCollection.CreateEntity(); Assert.Equal(1, entityCollection.Count()); Assert.Equal(entity, entityCollection.First()); }
public void should_remove_created_entity_from_the_collection() { var mockEventSystem = Substitute.For <IEventSystem>(); var mockEntityFactory = Substitute.For <IEntityFactory>(); mockEntityFactory.Create(null).Returns(new Entity(Guid.NewGuid(), mockEventSystem)); var entityCollection = new EntityCollection("", mockEntityFactory, mockEventSystem); var entity = entityCollection.CreateEntity(); entityCollection.RemoveEntity(entity); Assert.Empty(entityCollection); }
public void should_create_new_entity() { var expectedId = Guid.NewGuid(); var mockEntityFactory = Substitute.For <IEntityFactory>(); var mockEventSystem = Substitute.For <IEventSystem>(); mockEntityFactory.Create(null).Returns(new Entity(expectedId, mockEventSystem)); var entityCollection = new EntityCollection("", mockEntityFactory, mockEventSystem); var entity = entityCollection.CreateEntity(); Assert.Equal(expectedId, entity.Id); Assert.NotNull(entity.Components); Assert.Empty(entity.Components); }
public void should_raise_events_and_remove_components_when_removing_entity() { var mockEventSystem = Substitute.For <IEventSystem>(); var mockEntityFactory = Substitute.For <IEntityFactory>(); mockEntityFactory.Create(null).Returns(new Entity(Guid.NewGuid(), mockEventSystem)); var entityCollection = new EntityCollection("", mockEntityFactory, mockEventSystem); var entity = entityCollection.CreateEntity(); entityCollection.RemoveEntity(entity); mockEventSystem.Received().Publish(Arg.Is <EntityRemovedEvent>(x => x.Entity == entity && x.EntityCollection == entityCollection)); Assert.Empty(entity.Components); }
public void should_create_new_entity_and_raise_event() { var mockEntityFactory = Substitute.For <IEntityFactory>(); var mockEntity = Substitute.For <IEntity>(); mockEntityFactory.Create(null).Returns(mockEntity); var entityCollection = new EntityCollection(1, mockEntityFactory); var wasCalled = false; entityCollection.EntityAdded.Subscribe(x => wasCalled = true); var entity = entityCollection.CreateEntity(); Assert.Contains(mockEntity, entityCollection.EntityLookup); Assert.Equal(mockEntity, entity); Assert.True(wasCalled); }
public void should_raise_events_and_remove_components_when_removing_entity() { var mockEntityFactory = Substitute.For <IEntityFactory>(); var mockEntity = Substitute.For <IEntity>(); mockEntity.Id.Returns(1); mockEntityFactory.Create(null).Returns(mockEntity); var entityCollection = new EntityCollection(1, mockEntityFactory); var wasCalled = false; entityCollection.EntityRemoved.Subscribe(x => wasCalled = true); entityCollection.CreateEntity(); entityCollection.RemoveEntity(mockEntity.Id); Assert.True(wasCalled); Assert.DoesNotContain(mockEntity, entityCollection); }