Exemple #1
0
        public void Open_ValidText_Graph()
        {
            var text = @"1 2
1 3
2 4
2 3
3 1";

            var storage   = new EdgesListFormatStorage();
            var graphMock = new Mock <IGraph>();

            graphMock.Setup(g => g.AddVertex(It.IsAny <int>())).Returns <int>(index => Mock.Of <IVertex>(v => v.Index == index));

            using (var sr = new System.IO.StringReader(text))
            {
                storage.Open(sr, graphMock.Object);
            }

            graphMock.Verify(g => g.AddVertex(1), Times.Exactly(3));
            graphMock.Verify(g => g.AddVertex(2), Times.Exactly(3));
            graphMock.Verify(g => g.AddVertex(3), Times.Exactly(3));
            graphMock.Verify(g => g.AddVertex(4), Times.Exactly(1));

            graphMock.Verify(g => g.AddEdge(It.Is <IVertex>(v => v.Index == 1), It.Is <IVertex>(v => v.Index == 2), true, true), Times.Once);
            graphMock.Verify(g => g.AddEdge(It.Is <IVertex>(v => v.Index == 1), It.Is <IVertex>(v => v.Index == 3), true, true), Times.Once);
            graphMock.Verify(g => g.AddEdge(It.Is <IVertex>(v => v.Index == 2), It.Is <IVertex>(v => v.Index == 4), true, true), Times.Once);
            graphMock.Verify(g => g.AddEdge(It.Is <IVertex>(v => v.Index == 2), It.Is <IVertex>(v => v.Index == 3), true, true), Times.Once);
            graphMock.Verify(g => g.AddEdge(It.Is <IVertex>(v => v.Index == 3), It.Is <IVertex>(v => v.Index == 1), true, true), Times.Once);
        }