public void CanBeInsertedInto() { ContainerBlock container = new MockContainerBlock(); var one = new ParagraphBlock(); container.Insert(0, one); Assert.AreEqual(1, container.Count); Assert.AreSame(container[0], one); var two = new ParagraphBlock(); container.Insert(1, two); Assert.AreEqual(2, container.Count); Assert.AreSame(container[0], one); Assert.AreSame(container[1], two); var three = new ParagraphBlock(); container.Insert(0, three); Assert.AreEqual(3, container.Count); Assert.AreSame(container[0], three); Assert.AreSame(container[1], one); Assert.AreSame(container[2], two); Assert.Throws <ArgumentNullException>(() => container.Insert(0, null)); Assert.Throws <ArgumentOutOfRangeException>(() => container.Insert(4, new ParagraphBlock())); Assert.Throws <ArgumentOutOfRangeException>(() => container.Insert(-1, new ParagraphBlock())); Assert.Throws <ArgumentException>(() => container.Insert(0, one)); // one already has a parent }
public void Contains() { var container = new MockContainerBlock(); var block = new ParagraphBlock(); Assert.False(container.Contains(block)); container.Add(block); Assert.True(container.Contains(block)); container.Add(new ParagraphBlock()); Assert.True(container.Contains(block)); container.Insert(0, new ParagraphBlock()); Assert.True(container.Contains(block)); }
public void CanBeSet() { ContainerBlock container = new MockContainerBlock(); var one = new ParagraphBlock(); container.Insert(0, one); Assert.AreEqual(1, container.Count); Assert.AreSame(container[0], one); Assert.AreSame(container, one.Parent); var two = new ParagraphBlock(); container[0] = two; Assert.AreSame(container, two.Parent); Assert.Null(one.Parent); Assert.Throws <ArgumentException>(() => container[0] = two); // two already has a parent }