public void AddingAndRemoving() { NbtCompound test = new NbtCompound(); NbtInt foo = new NbtInt( "Foo" ); test.Add( foo ); // adding duplicate object Assert.Throws<ArgumentException>( () => test.Add( foo ) ); // adding duplicate name Assert.Throws<ArgumentException>( () => test.Add( new NbtByte( "Foo" ) ) ); // adding unnamed tag Assert.Throws<ArgumentException>( () => test.Add( new NbtInt() ) ); // adding null Assert.Throws<ArgumentNullException>( () => test.Add( null ) ); // contains existing name Assert.IsTrue( test.Contains( "Foo" ) ); // contains existing object Assert.IsTrue( test.Contains( foo ) ); // contains non-existent name Assert.IsFalse( test.Contains( "Bar" ) ); // contains existing name / different object Assert.IsFalse( test.Contains( new NbtInt( "Foo" ) ) ); // removing non-existent name Assert.IsFalse( test.Remove( "Bar" ) ); // removing existing name Assert.IsTrue( test.Remove( "Foo" ) ); // removing non-existent name Assert.IsFalse( test.Remove( "Foo" ) ); // re-adding object test.Add( foo ); // removing existing object Assert.IsTrue( test.Remove( foo ) ); // clearing an empty NbtCompound Assert.AreEqual( test.Count, 0 ); test.Clear(); // re-adding after clearing test.Add( foo ); Assert.AreEqual( test.Count, 1 ); // clearing a non-empty NbtCompound test.Clear(); Assert.AreEqual( test.Count, 0 ); }
public void AddingAndRemoving() { var test = new NbtCompound(); var foo = new NbtInt("Foo"); test.Add(foo); // adding duplicate object Assert.Throws <ArgumentException>(() => test.Add(foo)); // adding duplicate name Assert.Throws <ArgumentException>(() => test.Add(new NbtByte("Foo"))); // adding unnamed tag Assert.Throws <ArgumentException>(() => test.Add(new NbtInt())); // adding null Assert.Throws <ArgumentNullException>(() => test.Add(null)); // contains existing name Assert.IsTrue(test.Contains("Foo")); // contains existing object Assert.IsTrue(test.Contains(foo)); // contains non-existent name Assert.IsFalse(test.Contains("Bar")); // contains existing name / different object Assert.IsFalse(test.Contains(new NbtInt("Foo"))); // removing non-existent name Assert.IsFalse(test.Remove("Bar")); // removing existing name Assert.IsTrue(test.Remove("Foo")); // removing non-existent name Assert.IsFalse(test.Remove("Foo")); // re-adding object test.Add(foo); // removing existing object Assert.IsTrue(test.Remove(foo)); // clearing an empty NbtCompound Assert.AreEqual(test.Count, 0); test.Clear(); // re-adding after clearing test.Add(foo); Assert.AreEqual(test.Count, 1); // clearing a non-empty NbtCompound test.Clear(); Assert.AreEqual(test.Count, 0); }
public void CheckSynchronized() { var root = new NbtCompound("test"); var view = new NbtTreeView(); var model = new NbtTreeModel((object)root); view.Model = model; Assert.AreEqual(model.Root.Children.Count(), 1); Assert.AreEqual(view.Root.Children.Count, 1); AssertSynchronized(view, model); root.Add(new NbtByte("test1")); AssertSynchronized(view, model); root.Add(new NbtByte("test2")); AssertSynchronized(view, model); root.Add(new NbtCompound("test3")); AssertSynchronized(view, model); root.Get <NbtCompound>("test3").Add(new NbtShort("test4")); Assert.AreEqual(view.Root.DescendantsCount, 5); Assert.AreEqual(model.Root.DescendantsCount, 5); AssertSynchronized(view, model); root.Remove("test2"); AssertSynchronized(view, model); root.Get <NbtCompound>("test3").Clear(); Assert.AreEqual(view.Root.DescendantsCount, 3); Assert.AreEqual(model.Root.DescendantsCount, 3); AssertSynchronized(view, model); root.Clear(); AssertSynchronized(view, model); }
public void AddingAndRemoving() { var foo = new NbtInt("Foo"); var test = new NbtCompound { foo }; // adding duplicate object Assert.Throws<ArgumentException>(() => test.Add(foo)); // adding duplicate name Assert.Throws<ArgumentException>(() => test.Add(new NbtByte("Foo"))); // adding unnamed tag Assert.Throws<ArgumentException>(() => test.Add(new NbtInt())); // adding null Assert.Throws<ArgumentNullException>(() => test.Add(null)); // adding tag to self Assert.Throws<ArgumentException>(() => test.Add(test)); // contains existing name/object Assert.True(test.Contains("Foo")); Assert.True(test.Contains(foo)); Assert.Throws<ArgumentNullException>(() => test.Contains((string) null)); Assert.Throws<ArgumentNullException>(() => test.Contains((NbtTag) null)); // contains non-existent name Assert.False(test.Contains("Bar")); // contains existing name / different object Assert.False(test.Contains(new NbtInt("Foo"))); // removing non-existent name Assert.Throws<ArgumentNullException>(() => test.Remove((string) null)); Assert.False(test.Remove("Bar")); // removing existing name Assert.True(test.Remove("Foo")); // removing non-existent name Assert.False(test.Remove("Foo")); // re-adding object test.Add(foo); // removing existing object Assert.Throws<ArgumentNullException>(() => test.Remove((NbtTag) null)); Assert.True(test.Remove(foo)); Assert.False(test.Remove(foo)); // clearing an empty NbtCompound Assert.Equal(0, test.Count); test.Clear(); // re-adding after clearing test.Add(foo); Assert.Equal(1, test.Count); // clearing a non-empty NbtCompound test.Clear(); Assert.Equal(0, test.Count); }
public void AddingAndRemoving() { var foo = new NbtInt("Foo"); var test = new NbtCompound { foo }; // adding duplicate object Assert.Throws <ArgumentException>(() => test.Add(foo)); // adding duplicate name Assert.Throws <ArgumentException>(() => test.Add(new NbtByte("Foo"))); // adding unnamed tag Assert.Throws <ArgumentException>(() => test.Add(new NbtInt())); // adding null Assert.Throws <ArgumentNullException>(() => test.Add(null)); // adding tag to self Assert.Throws <ArgumentException>(() => test.Add(test)); // contains existing name/object Assert.True(test.Contains("Foo")); Assert.Contains(foo, test); Assert.Throws <ArgumentNullException>(() => test.Contains((string)null)); Assert.Throws <ArgumentNullException>(() => test.Contains((NbtTag)null)); // contains non-existent name Assert.False(test.Contains("Bar")); // contains existing name / different object Assert.DoesNotContain(new NbtInt("Foo"), test); // removing non-existent name Assert.Throws <ArgumentNullException>(() => test.Remove((string)null)); Assert.False(test.Remove("Bar")); // removing existing name Assert.True(test.Remove("Foo")); // removing non-existent name Assert.False(test.Remove("Foo")); // re-adding object test.Add(foo); // removing existing object Assert.Throws <ArgumentNullException>(() => test.Remove((NbtTag)null)); Assert.True(test.Remove(foo)); Assert.False(test.Remove(foo)); // clearing an empty NbtCompound Assert.Empty(test); test.Clear(); // re-adding after clearing test.Add(foo); Assert.Single(test); // clearing a non-empty NbtCompound test.Clear(); Assert.Empty(test); }