public void Convert_root_to_dictionary_when_there_is_a_complex_object_graph() { var originalNode = new ConfigNode(); originalNode.Name = "N1"; originalNode.Children = new List<ConfigNode> { CreateValueNode(1), CreateValueNode(2), new ConfigNode { Name = "N2", Children = new List<ConfigNode> { CreateValueNode(5), } }, CreateValueNode(3), CreateValueNode(4), new ConfigNode { Name = "N3", Children = new List<ConfigNode> { CreateValueNode(6), new ConfigNode { Name = "N6", Children = new List<ConfigNode> { CreateValueNode(8), } } } } }; var expectedDictionary = new Dictionary<string, string>(); expectedDictionary["N1.N1"] = "V1"; expectedDictionary["N1.N2"] = "V2"; expectedDictionary["N1.N2.N5"] = "V5"; expectedDictionary["N1.N3"] = "V3"; expectedDictionary["N1.N4"] = "V4"; expectedDictionary["N1.N3.N6"] = "V6"; expectedDictionary["N1.N3.N6.N8"] = "V8"; Assert.IsTrue(_objectComparer.Compare(expectedDictionary, originalNode.ToDictionary()).AreEqual); }
public void Convert_root_to_dictionary_when_there_is_leading_or_trailing_whitespace_in_the_contents() { var node = new ConfigNode(); node.Children = new List<ConfigNode> { CreateValueNodeWithWhitespace(1), CreateValueNodeWithWhitespace(2), CreateValueNodeWithWhitespace(3), CreateValueNodeWithWhitespace(4) }; var expectedDictionary = new Dictionary<string, string>(); expectedDictionary[".N1"] = "V1"; expectedDictionary[".N2"] = "V2"; expectedDictionary[".N3"] = "V3"; expectedDictionary[".N4"] = "V4"; Assert.IsTrue(_objectComparer.Compare(expectedDictionary, node.ToDictionary()).AreEqual); }
public void Convert_root_to_dictionary_when_there_are_duplicate_names() { var node = new ConfigNode(); node.Name = "N1"; node.Children = new List<ConfigNode> { CreateValueNode(1), CreateValueNode(2), CreateValueNode(3), CreateValueNode(4) }; node.Children[1].Name = "foo"; node.Children[2].Name = "foo"; node.ToDictionary(); }
public void Convert_root_to_dictionary_when_there_are_nulls_in_some_of_the_names() { var node = new ConfigNode(); node.Children = new List<ConfigNode> { CreateValueNode(1), CreateValueNode(2), CreateValueNode(3), CreateValueNode(4) }; node.Children[1].Name = null; // Nulls alone should not cause this to break var expectedDictionary = new Dictionary<string, string>(); expectedDictionary[".N1"] = "V1"; expectedDictionary["."] = "V2"; expectedDictionary[".N3"] = "V3"; expectedDictionary[".N4"] = "V4"; Assert.IsTrue(_objectComparer.Compare(expectedDictionary, node.ToDictionary()).AreEqual); }
public void Convert_root_to_dictionary_when_there_are_no_duplicate_names() { var node = new ConfigNode(); node.Name = "N1"; node.Children = new List<ConfigNode> { CreateValueNode(1), CreateValueNode(2), CreateValueNode(3), CreateValueNode(4) }; var expectedDictionary = new Dictionary<string, string>(); expectedDictionary["N1.N1"] = "V1"; expectedDictionary["N1.N2"] = "V2"; expectedDictionary["N1.N3"] = "V3"; expectedDictionary["N1.N4"] = "V4"; Assert.IsTrue(_objectComparer.Compare(expectedDictionary, node.ToDictionary()).AreEqual); }