public void CreateTreeProperly() { var first = new ClassWithRecursion(); first.Name = "First"; var second = new ClassWithRecursion(); second.Name = "Second"; first.Subclass = second; var sourceTree = new ObjectTreeItem(first); sourceTree.CreateTree(); Trace.WriteLine(sourceTree.ToFormattedString()); Assert.IsNull(sourceTree.Parent); Assert.IsNotNull(sourceTree.Childs); Assert.IsTrue(IEnumerableExtensions.Any(sourceTree.Childs)); Assert.AreEqual(2, sourceTree.Childs.Count); Assert.AreEqual(first, sourceTree.Item); Assert.IsTrue(sourceTree.Childs.Any(item => item.Item == second)); foreach (var objectTreeItem in sourceTree.Childs) { Assert.AreEqual(sourceTree, objectTreeItem.Parent); } }
public void RecursiveItemsAreOnlyRecursiveItemsTest() { var first = new ExtendedClassWithRecursion(); first.Name = "first"; var second = new ExtendedClassWithRecursion(); second.Name = "second"; var third = new ClassWithRecursion(); third.Name = "third"; first.Subclass = second; second.Subclass = first; first.AnotherSubclass = third; third.Subclass = second; var sourceTree = new ObjectTreeItem(first); sourceTree.CreateTree(); foreach (var recursiveSourceTreeItem in sourceTree.RecursionObjectTreeItems) { //if (!ReferenceEquals(recursiveSourceTreeItem.Parent.Item, first)) if (recursiveSourceTreeItem.Item != first) { // Tree contains errors, if recursive tree items does not contain root as any of their child Trace.TraceInformation(sourceTree.ToFormattedString()); throw new Exception("<<<< BUG IN OBJECT TREE>>>>>\n" + "In: \"" + recursiveSourceTreeItem.Item + "\"\n" + "Expected Item: \"" + first + "\"\n" + "Actual Items: \"" + recursiveSourceTreeItem.ToFormattedString()); } } }
private void BuildListTree <T>(params T[] arrayElements) { var instance = new ClassWithMembers <List <T> >(arrayElements.ToList(), arrayElements.ToList()); var treeItem = new ObjectTreeItem(instance); treeItem.CreateTree(); Trace.WriteLine(treeItem.ToFormattedString()); }
public void TreeCanHandleGuid() { var instance = new ClassWithMembers <Guid>(new Guid(), new Guid()); var treeItem = new ObjectTreeItem(instance); treeItem.CreateTree(); Trace.WriteLine(treeItem.ToFormattedString()); }
public void TreeCanHandleIpAddress() { var instance = new ClassWithMembers <IPAddress>(new IPAddress(19216811), new IPAddress(19216811)); var treeItem = new ObjectTreeItem(instance); treeItem.CreateTree(); Trace.WriteLine(treeItem.ToFormattedString()); }
private void TestObjectTreeCreation <T>(T property, T field) { var instance = new ClassWithMembers <T>(field, property); var treeItem = new ObjectTreeItem(instance); treeItem.CreateTree(); Trace.WriteLine(treeItem.ToFormattedString()); }
public void TreeCanHandleEnumberable() { var action = new Func <IEnumerable <string> >(CreateString); var instance = new ClassWithMembers <IEnumerable <string> >(action.Invoke(), new List <string>()); var treeItem = new ObjectTreeItem(instance); treeItem.CreateTree(); Trace.WriteLine(treeItem.ToFormattedString()); }
public void TreeCanHandleDelegates() { Del del = delegate(string name) { Console.WriteLine("Notification received for: {0}", name); }; var instance = new ClassWithMembers <Delegate>(del); var treeItem = new ObjectTreeItem(instance); treeItem.CreateTree(); Trace.WriteLine(treeItem.ToFormattedString()); }
public void TreeCanHandleOwnGenericList() { var instance = new ClassWithMembers <OwnGenericListClass <string> >(new OwnGenericListClass <string>() { "test1", "test2" }, new OwnGenericListClass <string>()); var treeItem = new ObjectTreeItem(instance); treeItem.CreateTree(); Trace.WriteLine(treeItem.ToFormattedString()); }
// [ExpectedException(typeof(AssertFailedException))] public void SelfReferencingObjectIsProperlyCreated() { var first = new ClassWithRecursion(); first.Name = "first"; first.Subclass = first; var sourceTree = new ObjectTreeItem(first); sourceTree.CreateTree(); Trace.WriteLine(sourceTree.ToFormattedString()); Assert.AreEqual(1, sourceTree.RecursionObjectTreeItems.Count); Assert.IsTrue(sourceTree.RecursionObjectTreeItems.Any(item => item.Parent.Item == first)); Assert.AreSame(sourceTree.Item, sourceTree.Childs.First(item => item.Item == sourceTree.Item).Item); }
public void TreeCanHandleFunctions() { var instance1 = new ClassWithMembers <Func <string, int> >(s => 5); var instance2 = new ClassWithMembers <Func <string> >(() => "test", () => "test"); var instance3 = new ClassWithMembers <Func <string> >(() => "test", () => "test"); var treeItem1 = new ObjectTreeItem(instance1); var treeItem2 = new ObjectTreeItem(instance2); var treeItem3 = new ObjectTreeItem(instance3); treeItem1.CreateTree(); treeItem2.CreateTree(); treeItem3.CreateTree(); Trace.WriteLine(treeItem1.ToFormattedString()); Trace.WriteLine(treeItem2.ToFormattedString()); Trace.WriteLine(treeItem3.ToFormattedString()); }
// [ExpectedException(typeof(AssertFailedException))] public void ToFormattedStringTest() { var first = new ExtendedClassWithRecursion(); first.Name = "first"; var second = new ExtendedClassWithRecursion(); second.Name = "second"; var third = new ClassWithRecursion(); third.Name = "third"; first.Subclass = second; second.Subclass = first; first.AnotherSubclass = third; third.Subclass = second; var sourceTree = new ObjectTreeItem(first); sourceTree.CreateTree(); Trace.WriteLine(sourceTree.ToFormattedString()); }