public void CallCollectionClearSetsParentReferenceToNull() { Post p = new Post("Flaming"); Comment c; p.Comments.Add(c = new Comment("Ashes")); p.Comments.Clear(); Assert.AreEqual(0, p.Comments.Count); Assert.IsNull(c.Post); }
public void AddCommentToPostSetsPostOnComment() { Post p = new Post("Flaming"); p.Comments.Add(new Comment("Ashes")); Assert.AreEqual(p, p.Comments[0].Post); Comment c = new Comment("backwards"); c.Post = p = new Post("yeah"); Assert.AreEqual(1, p.Comments.Count); Assert.AreEqual(p, p.Comments[0].Post); }
public void CallingRemoveAtWillCallDelegate() { Post p = new Post("Flaming"); Comment c = new Comment("Ashes"); p.Comments.Add(c); p.Comments.RemoveAt(0); Assert.IsNull(c.Post); }
public void ModifyCollectionsUsingInsertAtPositionAllowsDoubling() { Post p = new Post("q"); Comment c = new Comment("a"); p.Comments.Add(c); p.Comments.Insert(0,c); p.Comments.Add(c); Assert.AreEqual(2, p.Comments.Count); }
public void DoubleAddOfSameInstanceDoesNothing() { /* I have modified EntityList.DoAdd with this to prevent adding the same item twice * if (_list.Contains(item)) return false; else { _list.Add(item); return true; } */ Post p = new Post("1"); Comment c; p.Comments.Add(new Comment("c1")); Assert.AreEqual(1, p.Comments.Count); p.Comments.Add(c = new Comment("c2")); Assert.AreEqual(2, p.Comments.Count); p.Comments.Add(c); Assert.AreEqual(2, p.Comments.Count, "Double test add failed"); }