Register() public method

public Register ( IAutoupdateableGameActor actor, int timePeriod = 1 ) : void
actor IAutoupdateableGameActor
timePeriod int
return void
        public void TestRegisterForThisStepThrows()
        {
            AutoupdateRegister register = new AutoupdateRegister();
            Mock<IAutoupdateableGameActor> mock = new Mock<IAutoupdateableGameActor>();

            Assert.Throws<ArgumentOutOfRangeException>(() => register.Register(mock.Object, 0));
        }
示例#2
0
        private void InitAtlas(Map tmxDeserializedMap)
        {
            Action <GameActor> initializer = delegate(GameActor actor)
            {
                IAutoupdateable updateable = actor as IAutoupdateable;
                if (updateable != null && updateable.NextUpdateAfter > 0)
                {
                    AutoupdateRegister.Register(updateable, updateable.NextUpdateAfter);
                }
            };

            Atlas = MapLoader.LoadMap(tmxDeserializedMap, TilesetTable, initializer);

            Atlas.DayLength  = TWConfig.Instance.DayLengh;
            Atlas.YearLength = TWConfig.Instance.YearLength;

            IAtmosphere atmosphere = new SimpleAtmosphere(Atlas);

            Atlas.Atmosphere = atmosphere;
        }
        public void TestRegisterNullThrows()
        {
            AutoupdateRegister register = new AutoupdateRegister();

            Assert.Throws<ArgumentNullException>(() => register.Register(null));
        }
        public void TestUpdateItems()
        {
            Mock<IAtlas> mockAtlas = new Mock<IAtlas>();

            AutoupdateRegister register = new AutoupdateRegister();
            Mock<IAutoupdateableGameActor> mock1 = new Mock<IAutoupdateableGameActor>();
            mock1.Setup(x => x.Update(It.IsAny<IAtlas>(), It.IsAny<TilesetTable>()));
            Mock<IAutoupdateableGameActor> mock2 = new Mock<IAutoupdateableGameActor>();
            mock2.Setup(x => x.Update(It.IsAny<IAtlas>(), It.IsAny<TilesetTable>()));
            register.Register(mock1.Object, 1);
            register.Register(mock2.Object, 2);

            // Act
            register.Tick();
            register.UpdateItems(mockAtlas.Object, It.IsAny<TilesetTable>());

            // Assert
            mock1.Verify(x => x.Update(It.IsAny<IAtlas>(), It.IsAny<TilesetTable>()));
            mock2.Verify(x => x.Update(It.IsAny<IAtlas>(), It.IsAny<TilesetTable>()), Times.Never());

            // Act
            register.Tick();
            register.UpdateItems(mockAtlas.Object, It.IsAny<TilesetTable>());

            // Assert
            mock2.Verify(x => x.Update(It.IsAny<IAtlas>(), It.IsAny<TilesetTable>()));
        }