ChildrenCollectionTests.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using NUnit.Framework;
  5. namespace SharpGLTF.Collections
  6. {
  7. [TestFixture]
  8. [Category("Core")]
  9. public class ChildrenCollectionTests
  10. {
  11. class TestChild : IChildOf<ChildrenCollectionTests>
  12. {
  13. public ChildrenCollectionTests LogicalParent { get; private set; }
  14. public void _SetLogicalParent(ChildrenCollectionTests parent)
  15. {
  16. LogicalParent = parent;
  17. }
  18. }
  19. [Test]
  20. public void TestChildCollectionList1()
  21. {
  22. var list = new ChildrenCollection<TestChild, ChildrenCollectionTests>(this);
  23. Assert.Throws<ArgumentNullException>(() => list.Add(null));
  24. var item1 = new TestChild();
  25. Assert.IsNull(item1.LogicalParent);
  26. list.Add(item1);
  27. Assert.AreSame(item1.LogicalParent, this);
  28. Assert.Throws<ArgumentException>(() => list.Add(item1));
  29. list.Remove(item1);
  30. Assert.IsNull(item1.LogicalParent);
  31. }
  32. }
  33. }