private void createItemEffect_Click(object sender, EventArgs e) { int amount, id; Item item; if (int.TryParse(itemAmount.Text, out amount)) { String selected = itemResource.SelectedValue.ToString(); String[] selElem = selected.Split(':'); if (int.TryParse(selElem[0], out id) && itemList.TryGetValue(id, out item)) { item.amount = amount; String itemEffect = String.Format("{0}#{1}#{2}", ItemEventEffect.ITEM_EFFECT_TAG, item.ParseToString(), resultTB.Text); if (ItemEventEffect.IsValidItemEventEffect(itemEffect)) { itemEffectsList.Add(itemEffect); } else { MessageBox.Show(this, itemEffect); } } } string toWrite = "ITEMEFFECTS"; foreach (String ie in itemEffectsList) { toWrite += "^" + ie; } WriteFile("itemEffects.txt", toWrite); }
public void ItemEventEffect_ParseFromString() { ItemEventEffect iee = new ItemEventEffect(validStrings[0].Item1); String expectedItem = "ID:2,Name:TestItem,Amount:1,Description:test item 2,ActiveEffect,PassiveEffect,Requirements,Icon:test.png"; Assert.AreEqual(expectedItem, iee.GetItem().ParseToString(), "The string should match the expected value"); }
public void ItemEventEffect_StandardConstructor() { ItemEventEffect iee = new ItemEventEffect(); Item item = new Item("ID:1,Name:TestItem,Amount:1,Description:test item 1,ActiveEffect,PassiveEffect,Requirements"); Assert.AreEqual(item, iee.GetItem(), "Items should be equal"); }
public void ItemEventEffect_ParseToString() { String expected = ItemEventEffect.ITEM_EFFECT_TAG + "#ID:2,Name:TestItem,Amount:1,Description:test item 2,ActiveEffect,PassiveEffect,Requirements,Icon:test.png#Test Result"; ItemEventEffect iee = new ItemEventEffect(expected); String expectedItem = "ID:2,Name:TestItem,Amount:1,Description:test item 2,ActiveEffect,PassiveEffect,Requirements,Icon:test.png"; Assert.AreEqual(expectedItem, iee.GetItem().ParseToString(), "The string should match the expected value"); Assert.AreEqual(expected, iee.ParseToString(), "String should be " + expected); }
public void ItemEventEffect_CheckStringValid() { foreach (Tuple <String, String> test in validStrings) { Assert.IsTrue(ItemEventEffect.IsValidItemEventEffect(test.Item1), test.Item2); } foreach (Tuple <String, String> test in invalidStrings) { Assert.IsFalse(ItemEventEffect.IsValidItemEventEffect(test.Item1), test.Item2); } }