public void DeserializeFromXml()
        {
            XPathDocument document = new XPathDocument(GetGraphFilePath("repro12273.xml"));
            UndirectedGraph <string, TaggedEdge <string, double> > undirectedGraph = document.DeserializeFromXml(
                "graph",
                "node",
                "edge",
                nav => new UndirectedGraph <string, TaggedEdge <string, double> >(),
                nav => nav.GetAttribute("id", ""),
                nav => new TaggedEdge <string, double>(
                    nav.GetAttribute("source", ""),
                    nav.GetAttribute("target", ""),
                    int.Parse(nav.GetAttribute("weight", ""))));

            using (XmlReader reader = XmlReader.Create(GetGraphFilePath("repro12273.xml")))
            {
                UndirectedGraph <string, TaggedEdge <string, double> > undirectedGraph2 = reader.DeserializeFromXml(
                    "graph",
                    "node",
                    "edge",
                    "",
                    r => new UndirectedGraph <string, TaggedEdge <string, double> >(),
                    r => r.GetAttribute("id"),
                    r => new TaggedEdge <string, double>(
                        r.GetAttribute("source") ?? throw new AssertionException("Must have source attribute"),
                        r.GetAttribute("target") ?? throw new AssertionException("Must have target attribute"),
                        int.Parse(r.GetAttribute("weight") ?? throw new AssertionException("Must have weight attribute"))));

                Assert.AreEqual(undirectedGraph.VertexCount, undirectedGraph2.VertexCount);
                Assert.AreEqual(undirectedGraph.EdgeCount, undirectedGraph2.EdgeCount);
            }
        }
        public void DeserializeFromXml_Document_Empty()
        {
            XPathDocument document = new XPathDocument(GetGraphFilePath(EmptyGraphFileName));

            // Directed graph
            AdjacencyGraph <string, Edge <string> > adjacencyGraph = document.DeserializeFromXml(
                "graph",
                "node",
                "edge",
                nav => new AdjacencyGraph <string, Edge <string> >(),
                nav => nav.GetAttribute("id", ""),
                nav => new Edge <string>(
                    nav.GetAttribute("source", ""),
                    nav.GetAttribute("target", "")));

            AssertEmptyGraph(adjacencyGraph);

            // Directed bidirectional graph
            BidirectionalGraph <string, Edge <string> > bidirectionalGraph = document.DeserializeFromXml(
                "graph",
                "node",
                "edge",
                nav => new BidirectionalGraph <string, Edge <string> >(),
                nav => nav.GetAttribute("id", ""),
                nav => new Edge <string>(
                    nav.GetAttribute("source", ""),
                    nav.GetAttribute("target", "")));

            AssertEmptyGraph(bidirectionalGraph);

            // Undirected graph
            UndirectedGraph <string, TaggedEdge <string, double> > undirectedGraph = document.DeserializeFromXml(
                "graph",
                "node",
                "edge",
                nav => new UndirectedGraph <string, TaggedEdge <string, double> >(),
                nav => nav.GetAttribute("id", ""),
                nav => new TaggedEdge <string, double>(
                    nav.GetAttribute("source", ""),
                    nav.GetAttribute("target", ""),
                    int.Parse(nav.GetAttribute("weight", ""))));

            AssertEmptyGraph(undirectedGraph);
        }
        public void DeserializeFromXml_Document()
        {
            XPathDocument document = new XPathDocument(GetGraphFilePath(TestGraphFileName));

            // Directed graph
            AdjacencyGraph <string, EquatableEdge <string> > adjacencyGraph = document.DeserializeFromXml(
                "graph",
                "node",
                "edge",
                nav => new AdjacencyGraph <string, EquatableEdge <string> >(),
                nav => nav.GetAttribute("id", ""),
                nav => new EquatableEdge <string>(
                    nav.GetAttribute("source", ""),
                    nav.GetAttribute("target", "")));

            AssetTestGraphContent(
                adjacencyGraph,
                (v1, v2, weight) => new EquatableEdge <string>(v1, v2));

            // Directed bidirectional graph
            BidirectionalGraph <string, EquatableEdge <string> > bidirectionalGraph = document.DeserializeFromXml(
                "graph",
                "node",
                "edge",
                nav => new BidirectionalGraph <string, EquatableEdge <string> >(),
                nav => nav.GetAttribute("id", ""),
                nav => new EquatableEdge <string>(
                    nav.GetAttribute("source", ""),
                    nav.GetAttribute("target", "")));

            AssetTestGraphContent(
                bidirectionalGraph,
                (v1, v2, weight) => new EquatableEdge <string>(v1, v2));

            // Undirected graph
            UndirectedGraph <string, EquatableTaggedEdge <string, double> > undirectedGraph = document.DeserializeFromXml(
                "graph",
                "node",
                "edge",
                nav => new UndirectedGraph <string, EquatableTaggedEdge <string, double> >(),
                nav => nav.GetAttribute("id", ""),
                nav => new EquatableTaggedEdge <string, double>(
                    nav.GetAttribute("source", ""),
                    nav.GetAttribute("target", ""),
                    int.Parse(nav.GetAttribute("weight", ""))));

            AssetTestGraphContent(
                undirectedGraph,
                (v1, v2, weight) => new EquatableTaggedEdge <string, double>(v1, v2, weight));
        }
        public void DeserializeFromXml_Document_Throws()
        {
            // ReSharper disable ReturnValueOfPureMethodIsNotUsed
            // ReSharper disable AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(
                () => ((XPathDocument)null).DeserializeFromXml(
                    "graph",
                    "node",
                    "edge",
                    nav => new AdjacencyGraph <string, EquatableEdge <string> >(),
                    nav => nav.GetAttribute("id", ""),
                    nav => new EquatableEdge <string>(
                        nav.GetAttribute("source", ""),
                        nav.GetAttribute("target", ""))));

            XPathDocument document = new XPathDocument(GetGraphFilePath(TestGraphFileName));

            Assert.Throws <ArgumentException>(
                () => document.DeserializeFromXml(
                    null,
                    "node",
                    "edge",
                    nav => new AdjacencyGraph <string, Edge <string> >(),
                    nav => nav.GetAttribute("id", ""),
                    nav => new Edge <string>(
                        nav.GetAttribute("source", ""),
                        nav.GetAttribute("target", ""))));

            Assert.Throws <ArgumentException>(
                () => document.DeserializeFromXml(
                    "",
                    "node",
                    "edge",
                    nav => new AdjacencyGraph <string, Edge <string> >(),
                    nav => nav.GetAttribute("id", ""),
                    nav => new Edge <string>(
                        nav.GetAttribute("source", ""),
                        nav.GetAttribute("target", ""))));

            Assert.Throws <ArgumentException>(
                () => document.DeserializeFromXml(
                    "graph",
                    null,
                    "edge",
                    nav => new AdjacencyGraph <string, Edge <string> >(),
                    nav => nav.GetAttribute("id", ""),
                    nav => new Edge <string>(
                        nav.GetAttribute("source", ""),
                        nav.GetAttribute("target", ""))));

            Assert.Throws <ArgumentException>(
                () => document.DeserializeFromXml(
                    "graph",
                    "",
                    "edge",
                    nav => new AdjacencyGraph <string, Edge <string> >(),
                    nav => nav.GetAttribute("id", ""),
                    nav => new Edge <string>(
                        nav.GetAttribute("source", ""),
                        nav.GetAttribute("target", ""))));

            Assert.Throws <ArgumentException>(
                () => document.DeserializeFromXml(
                    "graph",
                    "node",
                    null,
                    nav => new AdjacencyGraph <string, Edge <string> >(),
                    nav => nav.GetAttribute("id", ""),
                    nav => new Edge <string>(
                        nav.GetAttribute("source", ""),
                        nav.GetAttribute("target", ""))));

            Assert.Throws <ArgumentException>(
                () => document.DeserializeFromXml(
                    "graph",
                    "node",
                    "",
                    nav => new AdjacencyGraph <string, Edge <string> >(),
                    nav => nav.GetAttribute("id", ""),
                    nav => new Edge <string>(
                        nav.GetAttribute("source", ""),
                        nav.GetAttribute("target", ""))));

            Assert.Throws <ArgumentNullException>(
                () => document.DeserializeFromXml <string, Edge <string>, AdjacencyGraph <string, Edge <string> > >(
                    "graph",
                    "node",
                    "edge",
                    null,
                    nav => nav.GetAttribute("id", ""),
                    nav => new Edge <string>(
                        nav.GetAttribute("source", ""),
                        nav.GetAttribute("target", ""))));

            Assert.Throws <ArgumentNullException>(
                () => document.DeserializeFromXml <string, Edge <string>, AdjacencyGraph <string, Edge <string> > >(
                    "graph",
                    "node",
                    "edge",
                    nav => new AdjacencyGraph <string, Edge <string> >(),
                    null,
                    nav => new Edge <string>(
                        nav.GetAttribute("source", ""),
                        nav.GetAttribute("target", ""))));

            Assert.Throws <ArgumentNullException>(
                () => document.DeserializeFromXml <string, Edge <string>, AdjacencyGraph <string, Edge <string> > >(
                    "graph",
                    "node",
                    "edge",
                    nav => new AdjacencyGraph <string, Edge <string> >(),
                    nav => nav.GetAttribute("id", ""),
                    null));

            // No graph node found
            Assert.Throws <InvalidOperationException>(
                () => document.DeserializeFromXml(
                    "g",    // No node named "g" for the graph
                    "node",
                    "edge",
                    nav => new AdjacencyGraph <string, EquatableEdge <string> >(),
                    nav => nav.GetAttribute("id", ""),
                    nav => new EquatableEdge <string>(
                        nav.GetAttribute("source", ""),
                        nav.GetAttribute("target", ""))));
            // ReSharper restore AssignNullToNotNullAttribute
            // ReSharper restore ReturnValueOfPureMethodIsNotUsed
        }