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(); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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(); }
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(); }