PkmnLibSharp/PkmnLibSharpTests/Library/ItemLibraryTests.cs

70 lines
2.5 KiB
C#
Raw Normal View History

2022-03-12 09:32:31 +00:00
using System;
2020-05-05 19:40:04 +00:00
using NUnit.Framework;
using PkmnLibSharp.Library;
using PkmnLibSharp.Library.Items;
2020-05-05 19:40:04 +00:00
using PkmnLibSharp.Utilities;
namespace PkmnLibSharpTests.Library
{
public class ItemLibraryTests
{
[Test]
public void ConstructDestruct()
{
var item = new ItemLibrary(100);
item.Dispose();
}
[Test]
public void Insert()
{
2022-03-12 09:32:31 +00:00
var item = new Item("testItem", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000, "",
Array.Empty<EffectParameter>(), "", Array.Empty<EffectParameter>(), new[] { "testFlag" }, 50);
2020-05-05 19:40:04 +00:00
var library = new ItemLibrary(100);
library.Insert("foobar", item);
Assert.AreEqual(1, library.Count);
library.Dispose();
}
2022-03-12 09:32:31 +00:00
2020-05-05 19:40:04 +00:00
[Test]
public void Delete()
{
2022-03-12 09:32:31 +00:00
var item = new Item("testItem", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000, "",
Array.Empty<EffectParameter>(), "", Array.Empty<EffectParameter>(), new[] { "testFlag" }, 50);
2020-05-05 19:40:04 +00:00
var library = new ItemLibrary(100);
library.Insert("foobar", item);
Assert.AreEqual(1, library.Count);
library.Delete("foobar");
Assert.AreEqual(0, library.Count);
library.Dispose();
}
2022-03-12 09:32:31 +00:00
2020-05-05 19:40:04 +00:00
[Test]
public void Get()
{
2022-03-12 09:32:31 +00:00
var item = new Item("testItem", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000, "",
Array.Empty<EffectParameter>(), "", Array.Empty<EffectParameter>(), new[] { "testFlag" }, 50);
2020-05-05 19:40:04 +00:00
var library = new ItemLibrary(100);
library.Insert("foobar", item);
Assert.AreEqual(1, library.Count);
var m = library.Get("foobar");
Assert.AreEqual(m.Name, "testItem");
2022-03-12 09:32:31 +00:00
Assert.Throws<NativeException>(() => { library.Get("barfoo"); });
2020-05-05 19:40:04 +00:00
library.Dispose();
}
2022-03-12 09:32:31 +00:00
2020-05-05 19:40:04 +00:00
[Test]
public void TryGet()
{
2022-03-12 09:32:31 +00:00
var item = new Item("testItem", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000, "",
Array.Empty<EffectParameter>(), "", Array.Empty<EffectParameter>(), new[] { "testFlag" }, 50);
2020-05-05 19:40:04 +00:00
var library = new ItemLibrary(100);
library.Insert("foobar", item);
Assert.AreEqual(1, library.Count);
Assert.True(library.TryGet("foobar", out item));
Assert.AreEqual(item.Name, "testItem");
Assert.False(library.TryGet("barfoo", out item));
library.Dispose();
}
}
}