Пример #1
0
        private void PacketReceive_EventCanceled <TPacket, TEvent>(TPacket packet, IPlayer sender)
            where TPacket : IPacket
            where TEvent : Event
        {
            Action <PacketReceiveEvent <TPacket> >?registeredHandler = null;

            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            Mock.Get(events)
            .Setup(em => em.RegisterHandler(It.IsAny <Action <PacketReceiveEvent <TPacket> > >(), log))
            .Callback <Action <PacketReceiveEvent <TPacket> >, ILogger>(
                (handler, log) => registeredHandler = handler);

            using var world = new OrionWorld(events, log);

            var evt = new PacketReceiveEvent <TPacket>(packet, sender);

            Mock.Get(events)
            .Setup(em => em.Raise(It.IsAny <TEvent>(), log))
            .Callback <TEvent, ILogger>((evt, log) => evt.Cancel());

            Assert.NotNull(registeredHandler);
            registeredHandler !(evt);

            Assert.True(evt.IsCanceled);

            Mock.Get(events).VerifyAll();
        }
Пример #2
0
        public void Name_Get()
        {
            Terraria.Main.worldName = "test";

            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            Assert.Equal("test", world.Name);
        }
Пример #3
0
        public void Width_Get()
        {
            Terraria.Main.maxTilesX = 8400;

            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            Assert.Equal(8400, world.Width);
        }
Пример #4
0
        public void Height_Get()
        {
            Terraria.Main.maxTilesY = 2400;

            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            Assert.Equal(2400, world.Height);
        }
Пример #5
0
        public void BaseNpcSpawnLimit_Set()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            world.BaseNpcSpawnLimit = 456;

            Assert.Equal(456, Terraria.NPC.defaultMaxSpawns);
        }
Пример #6
0
        public void Item_Get()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            world[0, 0].BlockId = BlockId.Stone;

            Assert.Equal(BlockId.Stone, world[0, 0].BlockId);
        }
Пример #7
0
        public void BaseNpcSpawnRate_Set()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            world.BaseNpcSpawnRate = 123;

            Assert.Equal(123, Terraria.NPC.defaultSpawnRate);
        }
Пример #8
0
        public void AnglerQuest_Set()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            world.AnglerQuest = AnglerQuest.Bunnyfish;

            Assert.Equal(AnglerQuest.Bunnyfish, (AnglerQuest)Terraria.Main.anglerQuest);
        }
Пример #9
0
        public void Evil_SetCrimson()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            world.Evil = WorldEvil.Crimson;

            Assert.True(Terraria.WorldGen.crimson);
        }
Пример #10
0
        public void Evil_Get_ReturnsCrimson()
        {
            Terraria.WorldGen.crimson = true;

            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            Assert.Equal(WorldEvil.Crimson, world.Evil);
        }
Пример #11
0
        public void Difficulty_Set()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            world.Difficulty = WorldDifficulty.Master;

            Assert.Equal(WorldDifficulty.Master, (WorldDifficulty)Terraria.Main.GameMode);
        }
Пример #12
0
        public void WorldSave_EventTriggered()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(It.Is <WorldSaveEvent>(evt => evt.World == world), log));

            Terraria.IO.WorldFile.SaveWorld(false, true);

            Assert.Equal(13500.0, Terraria.IO.WorldFile._tempTime);

            Mock.Get(events).VerifyAll();
        }
Пример #13
0
        public void WorldSave_EventCanceled()
        {
            // Clear the time so we know it's 0.
            Terraria.IO.WorldFile._tempTime = 0.0;

            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var world = new OrionWorld(events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(It.IsAny <WorldSaveEvent>(), log))
            .Callback <WorldSaveEvent, ILogger>((evt, log) => evt.Cancel());

            Terraria.IO.WorldFile.SaveWorld(false, true);

            Assert.Equal(0.0, Terraria.IO.WorldFile._tempTime);

            Mock.Get(events).VerifyAll();
        }