public void Add_HierarchyTest() { TestHelper.ClearDatabase(options); TaskNote[] tasks = { new TaskNote { Name = "1" }, new TaskNote{ Name = "2" }, new TaskNote{ Name = "3" } }; var manager = new TaskTreeManager(options); manager.Add(tasks[0]); manager.Add(tasks[1], tasks[0]); manager.Add(tasks[2], tasks[0]); var Descendants = manager.GetDescendants(tasks[0].Id); Action act = () => manager.Add(null); Assert.Equal(tasks[0].Id, manager.GetAncestor(tasks[1].Id).Id); Assert.Equal(tasks[0].Id, manager.GetAncestor(tasks[2].Id).Id); Assert.Single(Descendants.Where(t => t.Id == tasks[1].Id)); Assert.Single(Descendants.Where(t => t.Id == tasks[2].Id)); Assert.Throws <NullReferenceException>(act); }
public void GetAncestor_Test() { TestHelper.ClearDatabase(options); TaskNote[] tasks = { new TaskNote { Name = "1" }, new TaskNote { Name = "2" }, new TaskNote { Name = "3" } }; TaskTreeManager manager = new TaskTreeManager(options); manager.Add(tasks[0]); manager.Add(tasks[1], tasks[0]); manager.Add(tasks[2], tasks[0]); Assert.Null(manager.GetAncestor(tasks[0].Id)); Assert.Equal(tasks[0].Id, manager.GetAncestor(tasks[1].Id).Id); Assert.Equal(tasks[0].Id, manager.GetAncestor(tasks[2].Id).Id); }