Beispiel #1
0
        public void SetUp()
        {
            _fileReaders = new List <IFileReader>();
            string[] data1 =
            {
                "using System.Text;",
                "using Efrpg.aaa;",
                "using System.Text;",
                "using System.Text;",
                "using System.Text;",
                "using System.Text;",
                "using Efrpg.bbb.ccc;",
                "using System.Fred;",
                "namespace Efrpg.FileManagement",
                "{",
                "    void abc()",
                "    {",
                "        var Efrpg.a = new Efrpg.blah();",
                "        var b = new Something(Efrpg.Hello);",
                "    }",
                "}"
            };
            string[] data2 =
            {
                "using System.XYZ;",
                "using Efrpg.ddd;",
                "using System.Crypt;",
                "using Efrpg.eee;",
                "using System.Text;",
                "using System.Text;",
                "using System.Text;",
                "namespace Efrpg.Generator",
                "{",
                "    void def()",
                "    {",
                "        var a = new Efrpg.something();",
                "        var Efrpg.b = new AnotherThing(Efrpg.World);",
                "    }",
                "}"
            };
            string[] data3 =
            {
                "using System.XYZ;",
                "",
                "namespace Efrpg",
                "{",
                "    public static class AssemblyHelper",
                "    {",
                "        // todo",
                "    }",
                "}"
            };
            var reader1 = new StringReaderStrategy(data1);
            var reader2 = new StringReaderStrategy(data2);
            var reader3 = new StringReaderStrategy(data3);

            _fileReaders.Add(new FileReader(reader1));
            _fileReaders.Add(new FileReader(reader2));
            _fileReaders.Add(new FileReader(reader3));
        }
        public void WithComments()
        {
            // Arrange
            string[] data =
            {
                "file comment",
                "another file comment",
                "namespace Efrpg.Simon",
                "{",
                "    // Code comment",
                "    blah",
                "}"
            };
            string[] expected =
            {
                "file comment",
                "another file comment",
                "    // Code comment",
                "    blah"
            };
            var reader     = new StringReaderStrategy(data);
            var fileReader = new FileReader(reader);

            // Act
            var result = fileReader.ReadFile(null);

            // Assert
            Assert.IsTrue(result);
            Assert.AreEqual("Simon", fileReader.Namespace());
            Assert.IsEmpty(fileReader.Usings());
            Assert.AreEqual(expected, fileReader.Code());
        }
        public void WithUsings(bool includeBlanks)
        {
            // Arrange
            var data = new List <string>
            {
                "using Hello;",
                "using World;",
                "using Efrpg.Gear;"
            };

            if (includeBlanks)
            {
                data.AddRange(new List <string> {
                    "", "", "", ""
                });
            }

            var expectedCode = new List <string>
            {
                "    public interface IFileManager",
                "    {",
                "        void StartHeader();",
                "        void Process(bool split = true);",
                "        void StartNewFile(string name);",
                "    }"
            };

            data.Add("namespace Efrpg.FileManagement");
            data.Add("{");
            data.AddRange(expectedCode);
            data.Add("}");

            if (includeBlanks)
            {
                expectedCode.InsertRange(0, new List <string> {
                    "", "", "", ""
                });
            }

            var expectedUsings = new List <string>
            {
                "Hello",
                "World"
            };
            var reader     = new StringReaderStrategy(data.ToArray());
            var fileReader = new FileReader(reader);

            // Act
            var result = fileReader.ReadFile(null);

            // Assert
            Assert.IsTrue(result);
            Assert.AreEqual("FileManagement", fileReader.Namespace());
            Assert.AreEqual(expectedUsings, fileReader.Usings());
            Assert.AreEqual(expectedCode, fileReader.Code());
        }
        public void NoUsings()
        {
            // Arrange
            string[] data =
            {
                "namespace Efrpg.FileManagement",
                "{",
                "    public interface IFileManager",
                "    {",
                "        void StartHeader();",
                "        void Process(bool split = true);",
                "        void StartNewFile(string name);",
                "    }",
                "}"
            };
            string[] expected =
            {
                "    public interface IFileManager",
                "    {",
                "        void StartHeader();",
                "        void Process(bool split = true);",
                "        void StartNewFile(string name);",
                "    }"
            };
            var reader     = new StringReaderStrategy(data);
            var fileReader = new FileReader(reader);

            // Act
            var result = fileReader.ReadFile(null);

            // Assert
            Assert.IsTrue(result);
            Assert.AreEqual("FileManagement", fileReader.Namespace());
            Assert.IsEmpty(fileReader.Usings());
            Assert.AreEqual(expected, fileReader.Code());
        }