public void WritesEmptyStrictGraph()
        {
            IStringWriter  writer = new StringWriterAdapter();
            GraphVizWriter g      = new GraphVizWriter(writer, Mock.Of <IDotHelper>());

            g.StartGraph(GraphMode.Graph, strict: true);
            g.EndGraph();

            string result   = writer.GetStringBuilder().ToString().Trim();
            string expected = "strict graph \"\" {" + Environment.NewLine + "}";

            Assert.Equal(expected, result);
        }
        private void btnVisualise_Click(object sender, EventArgs e)
        {
            if (this.txtFile.Text.Equals(String.Empty))
            {
                MessageBox.Show("You must enter a filename you wish to visualise the Graph to", "Filename Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                try
                {
                    switch (Path.GetExtension(this.txtFile.Text))
                    {
                    case ".dot":
                    case "dot":
                        GraphVizWriter dotwriter = new GraphVizWriter();
                        dotwriter.Save(this._g, this.txtFile.Text);
                        break;

                    case ".png":
                    case "png":
                        GraphVizGenerator pnggenerator = new GraphVizGenerator("png");
                        pnggenerator.Generate(this._g, this.txtFile.Text, true);
                        break;

                    case ".svg":
                    case "svg":
                    default:
                        GraphVizGenerator svggenerator = new GraphVizGenerator("svg");
                        svggenerator.Generate(this._g, this.txtFile.Text, true);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An Error occurred while trying to visualise the selected Graph:\n" + ex.Message, "Visualisation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
        public void GivenNodeWithTwoAttributes_ThenWritesThemCorrectly()
        {
            IAttrSet attributes = AttrSet.Empty.Width(1).Label("x");

            IStringWriter writer = new StringWriterAdapter();

            var dotHelperMock = new Mock <IDotHelper>();

            dotHelperMock.Setup(m => m.EscapeId(It.IsAny <string>())).Returns((string s) => s);
            dotHelperMock.Setup(m => m.GetRecordFromAttribute(It.IsAny <IAttribute>()))
            .Returns((IAttribute a) => $"{a.Key}={a.StringValue}");

            GraphVizWriter g = new GraphVizWriter(writer, dotHelperMock.Object);

            g.Node("z", attributes);

            string result   = writer.GetStringBuilder().ToString();
            string expected = $"z [width=1, label=x];{Environment.NewLine}";

            Assert.Equal(expected, result);
        }
Beispiel #4
0
 public GraphHandle(GraphVizWriter w)
 {
     _w = w;
 }
Beispiel #5
0
 internal void MarkAsUsed()
 {
     _w = null;
 }