private async void NodeWriterTestInternal()
        {
            // One node description to file
            File.Delete(filePath);
            INodeWriter implementation = new NodeWriter(new NodeDescriber(new NodesHelper()));
            await implementation.WriteToFileAsync(new NoChildrenNode("root"), filePath);

            var result = File.ReadAllText(filePath, Encoding.Unicode);

            Assert.AreEqual("new NoChildrenNode(\"root\");", result);


            // Multiple nodes description to file
            File.Delete(filePath);
            implementation = new NodeWriter(new NodeDescriber(new NodesHelper()));
            await implementation.WriteToFileAsync(new SingleChildNode("root",
                                                                      new TwoChildrenNode("child1",
                                                                                          new NoChildrenNode("leaf1"),
                                                                                          new SingleChildNode("child2",
                                                                                                              new NoChildrenNode("leaf2")))), filePath);

            result = File.ReadAllText(filePath, Encoding.Unicode);

            StringBuilder sb = new StringBuilder();

            sb.Append("new SingleChildNode(\"root\","); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append("new TwoChildrenNode(\"child1\","); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append(tab); sb.Append("new NoChildrenNode(\"leaf1\"),"); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append(tab); sb.Append("new SingleChildNode(\"child2\","); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append(tab); sb.Append(tab); sb.Append("new NoChildrenNode(\"leaf2\"))));");
            string expectedResult = sb.ToString();

            Assert.AreEqual(sb.ToString(), result);
        }
Ejemplo n.º 2
0
        public async Task WriteEmpty()
        {
            var filePath = "test-tree-empty.txt";

            INodeWriter implementation = new NodeWriter();
            await implementation.WriteToFileAsync(null, filePath);

            var result = File.ReadAllText(filePath);

            Assert.AreEqual("", result);
        }
Ejemplo n.º 3
0
        public async Task WriteToFileAsyncTest()
        {
            var filePath = "test-tree.txt";
            var node     = new SingleChildNode("root",
                                               new TwoChildrenNode("child1",
                                                                   new NoChildrenNode("leaf1"),
                                                                   new SingleChildNode("child2",
                                                                                       new NoChildrenNode("leaf2"))));

            INodeWriter implementation = new NodeWriter();
            await implementation.WriteToFileAsync(node, filePath);

            var result = File.ReadAllText(filePath);

            Assert.AreEqual(
                "new SingleChildNode(\"root\",\n" +
                "    new TwoChildrenNode(\"child1\",\n" +
                "        new NoChildrenNode(\"leaf1\"),\n" +
                "        new SingleChildNode(\"child2\",\n" +
                "            new NoChildrenNode(\"leaf2\"))))",
                result
                );
        }