Esempio n. 1
0
        public void SampleWalkerDisplaysTheSyntaxTreeStructure()
        {
            var unit = CSharpToApexHelpers.ParseText(
                @"using System;
                using System.Collections;
                using System.Linq.Think;
                using System.Text;
                using system.debug;

                namespace Demo
                {
                    struct Program
                    {
                        static void Main(string[] args)
                        {
                            Console.WriteLine(""Hello, World!"");
                        }
                    }
                }");

            var walker = new SampleWalker();

            unit.Accept(walker);

            var tree = walker.ToString();

            Assert.False(string.IsNullOrWhiteSpace(tree));
        }
Esempio n. 2
0
        public void CSharpHelperParsesTheCSharpCodeAndReturnsTheSyntaxTree()
        {
            var unit = CSharpToApexHelpers.ParseText(
                @"using System;
                using System.Collections;
                using System.Linq.Think;
                using System.Text;
                using system.debug;

                namespace HelloWorld
                {
                    class Program
                    {
                        static void Main(string[] args)
                        {
                            Console.WriteLine(""Hello, World!"");
                        }
                    }
                }");

            Assert.NotNull(unit);

            var txt = CSharpToApexHelpers.ConvertToCSharp(unit);

            Assert.NotNull(txt);
        }
        protected void Check(string csharpUnit, params string[] apexClasses)
        {
            var csharpNode = CSharpToApexHelpers.ParseText(csharpUnit);
            var apexNodes  = ApexSyntaxBuilder.GetApexSyntaxNodes(csharpNode);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(apexClasses.Length, apexNodes.Count);
                foreach (var apexItem in apexNodes.Zip(apexClasses, (node, text) => new { node, text }))
                {
                    Check(apexItem.node, apexItem.text);
                }
            });
        }
        public void EmptyClassIsGenerated()
        {
            var csharp = "class Test {}";
            var cs     = CSharpToApexHelpers.ParseText(csharp);
            var apex   = ApexSyntaxBuilder.GetApexSyntaxNodes(cs);

            Assert.NotNull(apex);
            Assert.AreEqual(1, apex.Count);

            var cd = apex.OfType <ClassDeclarationSyntax>().FirstOrDefault();

            Assert.NotNull(cd);
            Assert.AreEqual("Test", cd.Identifier);

            Check(csharp, "class Test {}");
        }