[Test] public void SaveAndOpen() { Network network = Network.GetSampleNetwork(); DateTime date = DateTime.Now; FileInfo file = new FileInfo("Network.xml"); XmlFile.Write (network, file); Assert.IsTrue (File.Exists(file.FullName), "File created"); Assert.IsTrue (XmlFile.GetRegisteredFile(network).FullName == file.FullName, "Registration correct"); Network network1 = (Network) XmlFile.GetRead (file); Assert.AreSame (network, network1, "Same instance"); Network network2 = new Network(); XmlFile.Read (network2, file); Assert.AreEqual (false, network == network2, "New instance is created"); Assert.AreEqual (network.Nodes.Count, network2.Nodes.Count, "Read file"); Assert.AreEqual (((Node) network.Nodes[0]).Name, ((Node) network2.Nodes[0]).Name, "Node name"); Assert.AreSame (((Branch) network2.Branches[0]).BeginNode, (Node) network2.Nodes[0], "Branch refers to node in node list"); Assert.AreSame (((Branch) network2.Branches[0]).EndNode, ((Branch) network2.Branches[1]).BeginNode, "Branches share same node object"); Assert.AreEqual (network.LastModificationTime.ToString(), network2.LastModificationTime.ToString(), "Date Time"); }
/// <summary> /// /// </summary> [SetUp] public void Init() { node1 = new Node("Node1", new Location (35, 53), 30.4, 18000); node2 = new Node("Node2", new Location (23, 18), 26.4, 14000); network = new Network(); network.Nodes.Add (node1); network.Nodes.Add (node2); commonLocation = new Location (12, 37); }
[Test] public void ReferencedFiles() { Network network1 = Network.GetSampleNetwork(); Network network2 = Network.GetSampleNetwork(); Network network3 = new Network(); network3.Nodes.Add (network1); network3.Nodes.Add (network2); FileInfo file = new FileInfo("Network3.xml"); XmlFile.Write (network3, file); Assert.IsTrue (File.Exists(file.FullName), "File written"); Assert.IsTrue (File.Exists(new FileInfo("Network1.xml").FullName), "Referenced file written"); Assert.AreEqual (new FileInfo("Network1.xml").FullName, XmlFile.GetRegisteredFile(network1).FullName, "File registered"); }
[Test] public void SameID() { Network network1 = Network.GetSampleNetwork(); Network network2 = Network.GetSampleNetwork(); ((Node) network1.Nodes[0]).Location.X = 44; ((Node) network2.Nodes[0]).Location.X = 55; Network network3 = new Network(); network3.Nodes.Add (network1.Nodes[0]); network3.Nodes.Add (network2.Nodes[0]); XmlFile.Write (network1, new FileInfo("Network1.xml")); XmlFile.Write (network2, new FileInfo("Network2.xml")); XmlFile.Write (network3, new FileInfo("Network3.xml")); Assert.IsTrue (File.Exists(new FileInfo("Network3.xml").FullName), "File written"); Assert.IsTrue (File.Exists(new FileInfo("Network1.xml").FullName), "Referenced file written"); Network network = new Network(); XmlFile.Read (network, new FileInfo("Network3.xml")); Assert.AreEqual (2, network.Nodes.Count, "Number of nodes read"); Assert.AreEqual (((Node)network1.Nodes[0]).ID, ((Node)network.Nodes[0]).ID, "Node is the same"); }
public static Network GetSampleNetwork() { Network network = new Network(); network.Name = "Rhine"; network.LastModificationTime = DateTime.Now; Node node1 = new Node("Node1", new Location (35, 53), 30.4, 18000); Node node2 = new Node("Node2", new Location (23, 18), 26.4, 14000); Node node3 = new Node("Node3", new Location (67, 63), 12.6, 12000); Node node4 = new Node("Node4", new Location (12, 23), 0.3, 1500); Node node5 = new Node("Node5", new Location (14, 34), 9.6, 2000); Branch branch1 = new Branch ("Nederrijn", node1, node2, 10, 80); Branch branch2 = new Branch ("IJssel", node2, node3, 60, 30); Branch branch3 = new Branch ("Rijn", node2, node4, 100, 40); Branch branch4 = new Branch ("Nederrijn", node1, node5, 110, 50); network.Nodes.Add (node1); network.Nodes.Add (node2); network.Nodes.Add (node3); network.Nodes.Add (node4); network.Nodes.Add (node5); network.Branches.Add (branch1); network.Branches.Add (branch2); network.Branches.Add (branch3); network.Branches.Add (branch4); return network; }