Example #1
0
        public void MoveAutoPartialToEquipTest()
        {
            var col = new CollectionAccessibleMethods <IItemInstance>(10);

            var set    = col.Set(0, _arrowsItem, 100);
            var merged = col.MoveAuto(0, _equipmentCollection, 40);

            Assert.IsNull(set.error);
            Assert.IsNull(merged.error);

            Assert.AreEqual(col[0], _equipmentCollection[4]);
            Assert.AreNotSame(col[0], _equipmentCollection[4]);

            Assert.AreEqual(60, col.GetAmount(0));
            Assert.AreEqual(40, _equipmentCollection.GetAmount(4));
        }
Example #2
0
        public void MoveAutoFromEquipFullStackTest()
        {
            var col = new CollectionAccessibleMethods <IItemInstance>(10);

            var set    = _character.EquipAt(4, _arrowsItem, 100);
            var merged = _equipmentCollection.MoveAuto(4, col, 100);

            Assert.IsNull(set.error);
            Assert.IsNull(merged.error);

            Assert.IsNull(_equipmentCollection[4]);
            Assert.AreSame(_arrowsItem, col[0]);

            Assert.AreEqual(100, col.GetAmount(0));
            Assert.AreEqual(0, _equipmentCollection.GetAmount(4));
        }
Example #3
0
        public void UnstackToSlotFromChar()
        {
            var col = new CollectionAccessibleMethods <IItemInstance>(10);

            var set    = _character.EquipAt(4, _arrowsItem, 100);
            var merged = _equipmentCollection.MergePublic(4, col, 0, 40);

            Assert.IsNull(set.error);
            Assert.IsNull(merged.error);

            Assert.AreEqual(col[0], _equipmentCollection[4]);
            Assert.AreNotSame(col[0], _equipmentCollection[4]);

            Assert.AreEqual(40, col.GetAmount(0));
            Assert.AreEqual(60, _equipmentCollection.GetAmount(4));
        }
Example #4
0
        public void ReadOnlyCollectionTest()
        {
            // Arrange
            var itemDef = new ItemDefinition(Guid.NewGuid())
            {
                maxStackSize = 999
            };
            var item              = new ItemInstance(Guid.NewGuid(), itemDef);
            int addedItemCount    = 0;
            int removedItemCount  = 0;
            int slotsChangedCount = 0;

            var set1 = _collection.Set(0, item, 3);

            _collection.isReadOnly = true;

            _collection.OnAddedItem    += (sender, result) => addedItemCount++;
            _collection.OnRemovedItem  += (sender, result) => removedItemCount++;
            _collection.OnSlotsChanged += (sender, result) => slotsChangedCount++;

            // Act
            var canSetResult    = _collection.CanSet(0, item);
            var setResult       = _collection.Set(0, item, 2);
            var canAddAmount    = _collection.GetCanAddAmount(item);
            var canAdd          = _collection.CanAdd(item);
            var addResult       = _collection.Add(item);
            var swap            = _collection.SwapPublic(0, _collection, 1);
            var merge           = _collection.MergePublic(0, _collection, 1, _collection.GetAmount(0));
            var canRemoveResult = _collection.CanRemove(item);
            var removeResult    = _collection.Remove(item);

            _collection.Clear();
            _collection.Expand <FakeCollectionSlot>(2);
            _collection.Shrink(5);
            _collection.Sort(null);

            _collection.GenerateSlots <FakeCollectionSlot>();
            _collection.GenerateSlotsRange <FakeCollectionSlot>(0, 5);

            // Assert
            Assert.IsNull(set1.error);

            Assert.AreEqual(item, _collection[0]);
            Assert.AreEqual(3, _collection.slots[0].amount);

            Assert.AreEqual(0, addedItemCount);
            Assert.AreEqual(0, removedItemCount);
            Assert.AreEqual(0, slotsChangedCount);

            Assert.AreEqual(Errors.CollectionIsReadOnly, canSetResult.error);
            Assert.AreEqual(Errors.CollectionIsReadOnly, setResult.error);
            Assert.AreEqual(Errors.CollectionIsReadOnly, canAdd.error);
            Assert.AreEqual(Errors.CollectionIsReadOnly, addResult.error);
            Assert.AreEqual(Errors.CollectionIsReadOnly, canRemoveResult.error);
            Assert.AreEqual(Errors.CollectionIsReadOnly, removeResult.error);
            Assert.AreEqual(Errors.CollectionIsReadOnly, merge.error);
            Assert.AreEqual(Errors.CollectionIsReadOnly, swap.error);
            Assert.AreEqual(Errors.CollectionIsReadOnly, canAddAmount.error);

            Assert.AreEqual(10, _collection.slotCount);
            Assert.IsTrue(_collection.slots.All(o => o.GetType() == typeof(CollectionSlot <IItemInstance>)));
        }