public void Count_Get()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var itemService = new OrionItemService(events, log);

            Assert.Equal(Terraria.Main.maxItems, itemService.Count);
        }
        public void Item_GetIndexOutOfRange_ThrowsIndexOutOfRangeException(int index)
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var itemService = new OrionItemService(events, log);

            Assert.Throws <IndexOutOfRangeException>(() => itemService[index]);
        }
        public void Item_GetMultipleTimes_ReturnsSameInstance()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var itemService = new OrionItemService(events, log);

            var item  = itemService[0];
            var item2 = itemService[0];

            Assert.Same(item, item2);
        }
        public void Item_Get()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var itemService = new OrionItemService(events, log);

            var item = itemService[1];

            Assert.Equal(1, item.Index);
            Assert.Same(Terraria.Main.item[1], ((OrionItem)item).Wrapped);
        }
        public void GetEnumerator()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var itemService = new OrionItemService(events, log);

            var items = itemService.ToList();

            for (var i = 0; i < items.Count; ++i)
            {
                Assert.Same(Terraria.Main.item[i], ((OrionItem)items[i]).Wrapped);
            }
        }
        public void ItemTick_EventCanceled()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var itemService = new OrionItemService(events, log);

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

            Terraria.Main.item[0].UpdateItem(0);

            Mock.Get(events).VerifyAll();
        }
        public void ItemTick_EventTriggered()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var itemService = new OrionItemService(events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(
                       It.Is <ItemTickEvent>(evt => ((OrionItem)evt.Item).Wrapped == Terraria.Main.item[0]), log));

            Terraria.Main.item[0].UpdateItem(0);

            Mock.Get(events).VerifyAll();
        }
        public void ItemDefaults_EventModified()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var itemService = new OrionItemService(events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(It.IsAny <ItemDefaultsEvent>(), log))
            .Callback <ItemDefaultsEvent, ILogger>((evt, log) => evt.Id = ItemId.DirtBlock);

            Terraria.Main.item[0].SetDefaults((int)ItemId.Sdmg);

            Assert.Equal(ItemId.DirtBlock, (ItemId)Terraria.Main.item[0].type);

            Mock.Get(events).VerifyAll();
        }
        public void Spawn(ItemId id, short stackSize, ItemPrefix prefix)
        {
            // Set up an empty slot for the item to appear at.
            Terraria.Main.item[0] = new Terraria.Item {
                whoAmI = 0
            };

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

            using var itemService = new OrionItemService(events, log);

            var item = itemService.Spawn(new ItemStack(id, prefix, stackSize), Vector2f.Zero);

            Assert.Equal(Terraria.Main.item[0], ((OrionItem)item).Wrapped);
            Assert.Equal(id, item.Id);
            Assert.Equal(stackSize, item.StackSize);
            Assert.Equal(prefix, item.Prefix);
        }
        public void ItemDefaults_EventTriggered()
        {
            var events = Mock.Of <IEventManager>();
            var log    = Mock.Of <ILogger>();

            using var itemService = new OrionItemService(events, log);

            Mock.Get(events)
            .Setup(em => em.Raise(
                       It.Is <ItemDefaultsEvent>(
                           evt => ((OrionItem)evt.Item).Wrapped == Terraria.Main.item[0] && evt.Id == ItemId.Sdmg),
                       log));

            Terraria.Main.item[0].SetDefaults((int)ItemId.Sdmg);

            Assert.Equal(ItemId.Sdmg, (ItemId)Terraria.Main.item[0].type);

            Mock.Get(events).VerifyAll();
        }
        public void ItemDefaults_EventCanceled()
        {
            // Clear the item so that we know it's empty.
            Terraria.Main.item[0] = new Terraria.Item {
                whoAmI = 0
            };

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

            using var itemService = new OrionItemService(events, log);

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

            Terraria.Main.item[0].SetDefaults((int)ItemId.Sdmg);

            Assert.Equal(ItemId.None, (ItemId)Terraria.Main.item[0].type);

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