Ejemplo n.º 1
0
        public void EntityThrowsOnMultipleModifyCalls()
        {
            var entity = new Entity.EngineEntity(0, new IComponent[] {new SimpleComponent()}, Mock.Of<IEventDispatcher>());

            Should.NotThrow(() => entity.Modify<IWriteableSimpleComponent>());
            Should.Throw<ComponentAccessException>(() => entity.Modify<IWriteableSimpleComponent>());
        }
Ejemplo n.º 2
0
        public void EntityNotifiesPostsComponentChangeEvent()
        {
            var mock = new Mock<IEventDispatcher>();
            var entity = new Entity.EngineEntity(0, new IComponent[] {new SimpleComponent()}, mock.Object);

            entity.Modify<IWriteableSimpleComponent>();

            mock.Verify(poster => poster.Post(It.IsAny<EntityComponentModified>()), Times.AtLeastOnce);
        }
Ejemplo n.º 3
0
        public void EntityReturnsCorrectComponent()
        {
            var entity = new Entity.EngineEntity(0, new IComponent[] {new SimpleComponent()}, Mock.Of<IEventDispatcher>());

            var c = entity.Current<ISimpleComponent>();

            c.ShouldNotBeNull();
            c.ShouldBeOfType<SimpleComponent>();
        }
Ejemplo n.º 4
0
        public void EntityContainsInitialComponents()
        {
            var entity = new Entity.EngineEntity(0, new IComponent[] {new SimpleComponent(), new OtherSimpleComponent()},
                Mock.Of<IEventDispatcher>());

            entity.HasComponent<ISimpleComponent>().ShouldBeTrue();
            entity.HasComponent<IOtherSimpleComponent>().ShouldBeTrue();
            entity.HasComponent<ISimpleAsyncComponent>().ShouldBeFalse();
        }
Ejemplo n.º 5
0
        public void EntityCommitsChangesToDirtyComponents()
        {
            var entity = new Entity.EngineEntity(0, new IComponent[] { new SimpleComponent() }, Mock.Of<IEventDispatcher>());

            var initialValue = entity.Current<ISimpleComponent>().Value;

            entity.Modify<IWriteableSimpleComponent>().Value = 5;
            entity.Current<ISimpleComponent>().Value.ShouldBe(initialValue);
            entity.Commit();
            entity.Current<ISimpleComponent>().Value.ShouldBe(5);
        }
Ejemplo n.º 6
0
        public void EntityCommitsDirtyComponentOnlyWhenDirty()
        {
            var mockWEntity = new Mock<IWriteableSimpleComponent>();
            var mockEntity = mockWEntity.As<ISimpleComponent>();

            var cloneWEntity = new Mock<IWriteableSimpleComponent>();
            var cloneEntity = cloneWEntity.As<ISimpleComponent>();

            mockEntity.SetupGet(c => c.Type).Returns(typeof (ISimpleComponent));
            mockEntity.Setup(c => c.Clone()).Returns(() => cloneEntity.Object);

            // Setup entity and mark ISimpleComponent as dirty
            var entity = new Entity.EngineEntity(0, new IComponent[] { mockEntity.Object }, Mock.Of<IEventDispatcher>());

            // Ensure a commit with the component non-dirty doesn't trigger a copy.
            entity.Commit();
            cloneEntity.Verify(c => c.CopyTo(mockEntity.Object),
                Times.Never());

            // Modify the component to set as dirty
            entity.Modify<IWriteableSimpleComponent>();

            // Trigger an entity commit, which should cause the entity to replicate
            // changes from `Next` to `Current`.
            entity.Commit();
            cloneEntity.Verify(c => c.CopyTo(mockEntity.Object),
                Times.Once());
        }
Ejemplo n.º 7
0
 public void EntityThrowsOnNonExistantModifyAccess()
 {
     var entity = new Entity.EngineEntity(0, new IComponent[] { new SimpleComponent() }, Mock.Of<IEventDispatcher>());
     Should.Throw<ComponentAccessException>(() => entity.Modify<IWriteableOtherSimpleComponent>());
 }