예제 #1
0
        public void InterfaceImplementations()
        {
            NbtTag[] tagList =
            {
                new NbtByte("First",  1), new NbtShort("Second", 2), new NbtInt("Third", 3),
                new NbtLong("Fourth", 4L)
            };

            // test NbtCompound(IEnumerable<NbtTag>) constructor
            var comp = new NbtCompound(tagList);

            // test .Names and .Tags collections
            Assert.Equal(new[]
            {
                "First", "Second", "Third", "Fourth"
            }, comp.Names);
            Assert.Equal(tagList, comp.Tags);

            // test ICollection and ICollection<NbtTag> boilerplate properties
            ICollection <NbtTag> iGenCollection = comp;

            Assert.False(iGenCollection.IsReadOnly);
            ICollection iCollection = comp;

            Assert.NotNull(iCollection.SyncRoot);
            Assert.False(iCollection.IsSynchronized);

            // test CopyTo()
            var tags = new NbtTag[iCollection.Count];

            iCollection.CopyTo(tags, 0);
            Assert.Equal(comp, tags);

            // test non-generic GetEnumerator()
            var enumeratedTags = comp.ToList();

            Assert.Equal(tagList, enumeratedTags);

            // test generic GetEnumerator()
            List <NbtTag> enumeratedTags2 = new List <NbtTag>();
            var           enumerator      = comp.GetEnumerator();

            while (enumerator.MoveNext())
            {
                enumeratedTags2.Add(enumerator.Current);
            }
            Assert.Equal(tagList, enumeratedTags2);
        }
예제 #2
0
        public void InterfaceImplementations()
        {
            NbtTag[] tagList = {
                new NbtByte("First", 1), new NbtShort("Second", 2), new NbtInt("Third", 3),
                new NbtLong("Fourth", 4L)
            };

            // test NbtCompound(IEnumerable<NbtTag>) constructor
            var comp = new NbtCompound(tagList);

            // test .Names and .Tags collections
            CollectionAssert.AreEquivalent(new[] {
                "First", "Second", "Third", "Fourth"
            }, comp.Names);
            CollectionAssert.AreEquivalent(tagList, comp.Tags);

            // test ICollection and ICollection<NbtTag> boilerplate properties
            ICollection<NbtTag> iGenCollection = comp;
            Assert.IsFalse(iGenCollection.IsReadOnly);
            ICollection iCollection = comp;
            Assert.NotNull(iCollection.SyncRoot);
            Assert.IsFalse(iCollection.IsSynchronized);

            // test CopyTo()
            var tags = new NbtTag[iCollection.Count];
            iCollection.CopyTo(tags, 0);
            CollectionAssert.AreEquivalent(comp, tags);

            // test non-generic GetEnumerator()
            var enumeratedTags = comp.ToList();
            CollectionAssert.AreEquivalent(tagList, enumeratedTags);

            // test generic GetEnumerator()
            List<NbtTag> enumeratedTags2 = new List<NbtTag>();
            var enumerator = comp.GetEnumerator();
            while (enumerator.MoveNext()) {
                enumeratedTags2.Add(enumerator.Current);
            }
            CollectionAssert.AreEquivalent(tagList, enumeratedTags2);
        }