Ejemplo n.º 1
0
        public void MergeStackableItemsPartialStack()
        {
            var col         = new CollectionAccessibleMethods <IItemInstance>(10);
            var arrowsClone = (MockedEquippableItemInstance)_arrowsItem.Clone();

            _equipmentCollection.SetEquipmentTypes(0, new [] { _arrowsEquipmentType });

            var set    = col.Set(0, _arrowsItem, 5);
            var set1   = _character.EquipAt(0, _arrowsItem, 5);
            var set2   = _character.EquipAt(4, arrowsClone, 2);
            var merged = _character.SwapOrMerge(0, 4);

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

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

            // _arrowsItem never gets an OnEquipped because we're moving a partial stack, which duplicates the instance.
            Assert.AreEqual(1, _arrowsItem.onEquippedCallCount);
            Assert.AreEqual(0, _arrowsItem.onUnEquippedCallCount);

            Assert.AreEqual(1, arrowsClone.onEquippedCallCount);
            Assert.AreEqual(0, arrowsClone.onUnEquippedCallCount);
        }
Ejemplo n.º 2
0
        public void SwapIncompatibleTest()
        {
            var col = new CollectionAccessibleMethods <IItemInstance>(10);

            var set     = col.Set(0, _swordItem, 1);
            var swapped = col.SwapPublic(0, _equipmentCollection, 2);

            Assert.IsNull(set.error);
            Assert.AreEqual(Errors.CharacterCollectionEquipmentTypeInvalid, swapped.error);

            Assert.AreSame(_swordItem, col[0]);
            Assert.IsNull(_equipmentCollection[4]);
            Assert.AreEqual(0, _swordItem.onEquippedCallCount);
            Assert.AreEqual(0, _swordItem.onUnEquippedCallCount);
        }
Ejemplo n.º 3
0
        public void MoveAutoFullStackToEquipTest()
        {
            var col = new CollectionAccessibleMethods <IItemInstance>(10);

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

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

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

            Assert.AreEqual(0, col.GetAmount(0));
            Assert.AreEqual(100, _equipmentCollection.GetAmount(4));
        }
Ejemplo n.º 4
0
        public void UnstackToSlotIntoChar()
        {
            var col = new CollectionAccessibleMethods <IItemInstance>(10);

            var set    = col.Set(0, _arrowsItem, 100);
            var merged = col.MergePublic(0, _equipmentCollection, 4, 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));
        }
Ejemplo n.º 5
0
        public void SwapStackable()
        {
            var col         = new CollectionAccessibleMethods <IItemInstance>(10);
            var arrowsClone = (MockedEquippableItemInstance)_arrowsItem.Clone();

            var set     = col.Set(0, _arrowsItem, 5);
            var set2    = _character.EquipAt(4, arrowsClone, 2);
            var swapped = col.SwapPublic(0, _equipmentCollection, 4);

            Assert.IsNull(set.error);
            Assert.IsNull(set2.error);
            Assert.IsNull(swapped.error);

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

            // Events aren't fired because we don't use the IEquippableCharacter, and move to the collection directly.
            Assert.AreEqual(0, _arrowsItem.onEquippedCallCount);
            Assert.AreEqual(0, _arrowsItem.onUnEquippedCallCount);

            Assert.AreEqual(1, arrowsClone.onEquippedCallCount);
            Assert.AreEqual(0, arrowsClone.onUnEquippedCallCount);
        }
Ejemplo n.º 6
0
        public void CollectionSetAddRestrictionTest()
        {
            // Arrange
            var itemDef = new ItemDefinition(Guid.NewGuid());
            var item    = new ItemInstance(Guid.NewGuid(), itemDef);

            _collection.restrictions.Add(new FakeCollectionRestriction());

            // Act
            var result = _collection.Set(0, item);

            // Assert
            Assert.AreEqual(Errors.CollectionRestrictionPreventedAction, result.error);
            Assert.IsTrue(!_collection.slots[0].isOccupied);
        }