public void CollectionRemoveEventTest() { // Arrange var itemDef = new ItemDefinition(Guid.NewGuid()); var item = new ItemInstance(Guid.NewGuid(), itemDef); CollectionRemoveResult <IItemInstance> eventResult = null; int eventCallCount = 0; // Act _collection.OnRemovedItem += (sender, removeResult) => { eventResult = removeResult; eventCallCount++; }; var result = _collection.Add(item); var result2 = _collection.Remove(item); // Assert Assert.IsNotNull(eventResult); Assert.AreEqual(1, eventResult.affectedSlots.Length); Assert.AreEqual(1, eventResult.affectedSlots[0].amount); Assert.IsNull(result.error); Assert.IsNull(result2.error); Assert.AreEqual(1, eventCallCount); }
public void ItemUseNotEnoughInCollectionTest() { var itemDef = new ItemDefinition(Guid.NewGuid()) { maxStackSize = 10 }; var item = new CollectionItemInstance(Guid.NewGuid(), itemDef); _collection.Set(0, item, 2); CollectionRemoveResult <IItemInstance> removeResult = null; int removeCallCount = 0; _collection.OnRemovedItem += (sender, result) => { removeResult = result; removeCallCount++; }; var context1 = new ItemContext { useAmount = 3 }; var usedResult = item.Use(null, context1); Assert.AreEqual(Errors.CollectionDoesNotContainItem, usedResult.error); Assert.AreEqual(0, removeCallCount); Assert.AreEqual(2, _collection.GetAmount(0)); }
public void ItemUseCollectionUpdateTest() { var itemDef = new ItemDefinition(Guid.NewGuid()) { maxStackSize = 10 }; var item = new CollectionItemInstance(Guid.NewGuid(), itemDef); var item2 = (CollectionItemInstance)item.Clone(); _collection.Set(0, item); _collection.Set(1, item2); CollectionRemoveResult <IItemInstance> removeResult = null; int removeCallCount = 0; _collection.OnRemovedItem += (sender, result) => { removeResult = result; removeCallCount++; }; var used = item.Use(null, new ItemContext()); Assert.IsNull(used.error); Assert.AreEqual(1, removeResult.affectedSlots[0].amount); Assert.AreEqual(1, removeCallCount); Assert.AreEqual(0, _collection.GetAmount(0)); Assert.IsNull(_collection[0]); }
public void SetRemoveEventTest() { // Arrange var itemDef = new ItemDefinition(Guid.NewGuid()) { maxStackSize = 10 }; var item = new ItemInstance(Guid.NewGuid(), itemDef); CollectionRemoveResult <IItemInstance> eventResult = null; int eventCallCount = 0; var addResult = _collection.Set(0, item, 3); // Act _collection.OnRemovedItem += (sender, removeResult) => { eventResult = removeResult; eventCallCount++; }; var setRemoveResult = _collection.Set(0, item, 1); // Assert Assert.IsNotNull(eventResult); Assert.AreEqual(1, eventResult.affectedSlots.Length); Assert.AreEqual(2, eventResult.affectedSlots[0].amount); Assert.IsNull(addResult.error); Assert.IsNull(setRemoveResult.error); Assert.AreEqual(1, eventCallCount); }
public void SetNewItemEventTest() { // Arrange var itemDef = new ItemDefinition(Guid.NewGuid()) { maxStackSize = 10 }; var item = new ItemInstance(Guid.NewGuid(), itemDef); var itemDef2 = new ItemDefinition(Guid.NewGuid()) { maxStackSize = 10 }; var item2 = new ItemInstance(Guid.NewGuid(), itemDef2); CollectionRemoveResult <IItemInstance> removeEventResult = null; CollectionAddResult addEventResult = null; int removeEventCallCount = 0; int addEventCallCount = 0; var addResult = _collection.Set(0, item, 3); // Act _collection.OnAddedItem += (sender, addResult1) => { addEventResult = addResult1; addEventCallCount++; }; _collection.OnRemovedItem += (sender, removeResult) => { removeEventResult = removeResult; removeEventCallCount++; }; var setRemoveResult = _collection.Set(0, item2, 2); // Assert Assert.IsNull(addResult.error); Assert.IsNull(setRemoveResult.error); Assert.AreEqual(1, removeEventResult.affectedSlots.Length); Assert.AreEqual(3, removeEventResult.affectedSlots[0].amount); Assert.AreEqual(1, addEventResult.affectedSlots.Length); Assert.AreEqual(2, addEventResult.affectedSlots[0].amount); Assert.AreEqual(1, removeEventCallCount); Assert.AreEqual(1, addEventCallCount); }
public void EquipmentCollectionOnEquipEventTest() { CollectionAddResult equipmentAddResult = null; CollectionRemoveResult <IEquippableItemInstance> equipmentRemoveResult = null; CollectionSlotsChangedResult equipmentChangeResult = null; int equipmentAddEventCount = 0; int equipmentRemoveEventCount = 0; int equipmentChangeEventCount = 0; CollectionAddResult restoreAddResult = null; CollectionRemoveResult <IItemInstance> restoreRemoveResult = null; CollectionSlotsChangedResult restoreChangeResult = null; int restoreAddEventCount = 0; int restoreRemoveEventCount = 0; int restoreChangeEventCount = 0; _equipmentCollection.OnAddedItem += (sender, result) => { equipmentAddResult = result; equipmentAddEventCount++; }; _equipmentCollection.OnRemovedItem += (sender, result) => { equipmentRemoveResult = result; equipmentRemoveEventCount++; }; _equipmentCollection.OnSlotsChanged += (sender, result) => { equipmentChangeResult = result; equipmentChangeEventCount++; }; _restoreToCollection.OnAddedItem += (sender, result) => { restoreAddResult = result; restoreAddEventCount++; }; _restoreToCollection.OnRemovedItem += (sender, result) => { restoreRemoveResult = result; restoreRemoveEventCount++; }; _restoreToCollection.OnSlotsChanged += (sender, result) => { restoreChangeResult = result; restoreChangeEventCount++; }; var set1 = _equippableCharacter.EquipAt(4, _arrowsItem); // Add event var set2 = _equippableCharacter.EquipAt(4, _shieldItem); // Unequips arrows + add event for shield Assert.IsNull(set1.error); Assert.IsNull(set2.error); Assert.AreEqual(2, equipmentAddEventCount); // Add arrows + shield Assert.AreEqual(1, equipmentRemoveEventCount); // Remove arrows Assert.AreEqual(3, equipmentChangeEventCount); // Arrow equip, unequip, shield equip Assert.AreEqual(1, restoreAddEventCount); // Add arrows Assert.AreEqual(0, restoreRemoveEventCount); Assert.AreEqual(1, restoreChangeEventCount); // Changed for arrows Assert.AreEqual(1, _restoreToCollection.GetAmount(_arrowsItem)); Assert.AreEqual(1, _equipmentCollection.GetAmount(_shieldItem)); }