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