コード例 #1
0
        public void ReceivePacket_EventCanceled()
        {
            // Clear out the password so we know it's empty.
            Terraria.Netplay.Clients[5] = new Terraria.RemoteClient {
                Id = 5
            };
            Terraria.Netplay.ServerPassword = string.Empty;

            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player {
                whoAmI = 5
            };
            var player = new OrionPlayer(5, terrariaPlayer, events, log);

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

            var packet = new ClientConnect {
                Version = "Terraria" + Terraria.Main.curRelease
            };

            player.ReceivePacket(packet);

            Assert.Equal(0, Terraria.Netplay.Clients[5].State);

            Mock.Get(events).VerifyAll();
        }
コード例 #2
0
        public void SendPacket_NotConnected()
        {
            Terraria.Netplay.Clients[5] = new Terraria.RemoteClient
            {
                Id     = 5,
                Socket = Mock.Of <Terraria.Net.Sockets.ISocket>(s => !s.IsConnected())
            };

            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player {
                whoAmI = 5
            };
            var player = new OrionPlayer(5, terrariaPlayer, events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(It.IsAny <PacketSendEvent <TestPacket> >(), log));

            player.SendPacket(new TestPacket {
                Value = 100
            });

            Mock.Get(events)
            .Verify(em => em.Raise(It.IsAny <PacketSendEvent <TestPacket> >(), log), Times.Never);
        }
コード例 #3
0
        public void Name_SetNullValue_ThrowsArgumentNullException()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            Assert.Throws <ArgumentNullException>(() => player.Name = null !);
        }
コード例 #4
0
        public void Inventory_Get_Count_Get()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            Assert.Equal(260, player.Inventory.Count);
        }
コード例 #5
0
        public void Character_Get()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            Assert.NotNull(player.Character);
        }
コード例 #6
0
        public void Inventory_Get_Item_GetIndexOutOfRange_ThrowsIndexOutOfRangeException(int index)
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            Assert.Throws <IndexOutOfRangeException>(() => player.Inventory[index]);
        }
コード例 #7
0
        public void SendPacket_NullPacket_ThrowsArgumentNullException()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            Assert.Throws <ArgumentNullException>(() => player.SendPacket <IPacket>(null !));
        }
コード例 #8
0
        public void Team_Set()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            player.Team = Team.Red;

            Assert.Equal(1, terrariaPlayer.team);
        }
コード例 #9
0
        public void Team_Get()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player {
                team = (int)Team.Red
            };
            var player = new OrionPlayer(terrariaPlayer, events, log);

            Assert.Equal(Team.Red, player.Team);
        }
コード例 #10
0
        public void Buffs_Get_Item_InvalidTime_Get(int buffTime)
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            terrariaPlayer.buffType[0] = (int)BuffId.ObsidianSkin;
            terrariaPlayer.buffTime[0] = buffTime;

            Assert.Equal(default, player.Buffs[0]);
コード例 #11
0
        public void MaxMana_Set()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            player.MaxMana = 200;

            Assert.Equal(200, terrariaPlayer.statManaMax);
        }
コード例 #12
0
        public void Mana_Get()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player {
                statMana = 100
            };
            var player = new OrionPlayer(terrariaPlayer, events, log);

            Assert.Equal(100, player.Mana);
        }
コード例 #13
0
        public void MaxHealth_Get()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player {
                statLifeMax = 500
            };
            var player = new OrionPlayer(terrariaPlayer, events, log);

            Assert.Equal(500, player.MaxHealth);
        }
コード例 #14
0
        public void IsInPvp_Set()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            player.IsInPvp = true;

            Assert.True(terrariaPlayer.hostile);
        }
コード例 #15
0
        public void Health_Set()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            player.Health = 100;

            Assert.Equal(100, terrariaPlayer.statLife);
        }
コード例 #16
0
        public void Name_Set()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            player.Name = "test";

            Assert.Equal("test", terrariaPlayer.name);
        }
コード例 #17
0
        public void Buffs_Get_Item_Get()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            terrariaPlayer.buffType[0] = (int)BuffId.ObsidianSkin;
            terrariaPlayer.buffTime[0] = 28800;

            Assert.Equal(new Buff(BuffId.ObsidianSkin, TimeSpan.FromMinutes(8)), player.Buffs[0]);
        }
コード例 #18
0
        public void Inventory_Get_Item_SetBank4()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            player.Inventory[223] = new ItemStack(ItemId.Sdmg, ItemPrefix.Unreal, 1);

            Assert.Equal(ItemId.Sdmg, (ItemId)terrariaPlayer.bank4.item[3].type);
            Assert.Equal(ItemPrefix.Unreal, (ItemPrefix)terrariaPlayer.bank4.item[3].prefix);
            Assert.Equal(1, terrariaPlayer.bank4.item[3].stack);
        }
コード例 #19
0
        public void Inventory_Get_Item_GetMiscEquips()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            terrariaPlayer.miscEquips[3] = new Terraria.Item
            {
                type   = (int)ItemId.Sdmg,
                prefix = (byte)ItemPrefix.Unreal,
                stack  = 1
            };

            Assert.Equal(new ItemStack(ItemId.Sdmg, ItemPrefix.Unreal, 1), player.Inventory[92]);
        }
コード例 #20
0
        public void Inventory_Get_GetEnumerator()
        {
            var events         = Mock.Of <IEventManager>();
            var log            = Mock.Of <ILogger>();
            var terrariaPlayer = new Terraria.Player();
            var player         = new OrionPlayer(terrariaPlayer, events, log);

            for (var i = 0; i < player.Inventory.Count; ++i)
            {
                player.Inventory[i] = new ItemStack((ItemId)i, ItemPrefix.None, (short)i);
            }

            var inventory = player.Inventory.ToList();

            for (var i = 0; i < inventory.Count; ++i)
            {
                Assert.Equal(new ItemStack((ItemId)i, ItemPrefix.None, (short)i), inventory[i]);
            }
        }