public void ChangingListTagType() { var list = new NbtList(); // changing list type to an out-of-range type Assert.Throws <ArgumentOutOfRangeException>(() => list.ListType = (NbtTagType)200); // failing to add or insert a tag should not change ListType Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(-1, new NbtInt())); Assert.Throws <ArgumentException>(() => list.Add(new NbtInt("namedTagWhereUnnamedIsExpected"))); Assert.AreEqual(NbtTagType.Unknown, list.ListType); // changing the type of an empty list to "End" is allowed, see https://github.com/fragmer/fNbt/issues/12 Assert.DoesNotThrow(() => list.ListType = NbtTagType.End); Assert.AreEqual(list.ListType, NbtTagType.End); // changing the type of an empty list back to "Unknown" is allowed too! Assert.DoesNotThrow(() => list.ListType = NbtTagType.Unknown); Assert.AreEqual(list.ListType, NbtTagType.Unknown); // adding the first element should set the tag type list.Add(new NbtInt()); Assert.AreEqual(list.ListType, NbtTagType.Int); // setting correct type for a non-empty list Assert.DoesNotThrow(() => list.ListType = NbtTagType.Int); // changing list type to an incorrect type Assert.Throws <ArgumentException>(() => list.ListType = NbtTagType.Short); // after the list is cleared, we should once again be allowed to change its TagType list.Clear(); Assert.DoesNotThrow(() => list.ListType = NbtTagType.Short); }
public void ChangingListTagType() { var list = new NbtList(); // changing list type to an out-of-range type Assert.Throws<ArgumentOutOfRangeException>(() => list.ListType = (NbtTagType)200); // failing to add or insert a tag should not change ListType Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(-1, new NbtInt())); Assert.Throws<ArgumentException>(() => list.Add(new NbtInt("namedTagWhereUnnamedIsExpected"))); Assert.AreEqual(NbtTagType.Unknown, list.ListType); // changing the type of an empty list to "End" is allowed, see https://github.com/fragmer/fNbt/issues/12 Assert.DoesNotThrow(() => list.ListType = NbtTagType.End); Assert.AreEqual(list.ListType, NbtTagType.End); // changing the type of an empty list back to "Unknown" is allowed too! Assert.DoesNotThrow(() => list.ListType = NbtTagType.Unknown); Assert.AreEqual(list.ListType, NbtTagType.Unknown); // adding the first element should set the tag type list.Add(new NbtInt()); Assert.AreEqual(list.ListType, NbtTagType.Int); // setting correct type for a non-empty list Assert.DoesNotThrow(() => list.ListType = NbtTagType.Int); // changing list type to an incorrect type Assert.Throws<ArgumentException>(() => list.ListType = NbtTagType.Short); // after the list is cleared, we should once again be allowed to change its TagType list.Clear(); Assert.DoesNotThrow(() => list.ListType = NbtTagType.Short); }