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 GetDescendants_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]); List <TaskNote> Descendants = manager.GetDescendants(tasks[0].Id); Assert.Equal(2, Descendants.Count); Assert.Single(Descendants.Where(d => d.Id == tasks[1].Id)); Assert.Single(Descendants.Where(d => d.Id == tasks[2].Id)); Assert.Empty(manager.GetDescendants(tasks[1].Id)); }
public void Remove_RemoveTerminalTaskTest() { TestHelper.ClearDatabase(options); TaskNote[] tasks = { new TaskNote { Name = "1" }, new TaskNote { Name = "2" } }; TaskTreeManager manager = new TaskTreeManager(options); manager.Add(tasks[0]); manager.Add(tasks[1], tasks[0]); manager.Remove(tasks[1].Id); Assert.Null(manager.Find(tasks[1].Id)); Assert.Empty(manager.GetDescendants(tasks[0].Id)); }